|
12 | 12 | from os import mkdir
|
13 | 13 | from shutil import copyfile
|
14 | 14 | from os.path import isfile, join
|
15 |
| -varPath = '/toScan' |
16 |
| -destDir = "/scanned" |
17 |
| -imgFiles = [f for f in listdir(varPath) if isfile(join(varPath, f))] |
| 15 | +var_path = '/toScan' |
| 16 | +dest_dir = "/scanned" |
| 17 | +img_files = [f for f in listdir(var_path) if isfile(join(var_path, f))] |
18 | 18 |
|
19 | 19 |
|
20 | 20 | # Loads label file, strips off carriage return
|
|
31 | 31 | # Feed the image_data as input to the graph and get first prediction
|
32 | 32 | softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
|
33 | 33 | #try:
|
34 |
| - # shutil.rmtree(destDir) |
| 34 | + # shutil.rmtree(dest_dir) |
35 | 35 | #except:
|
36 | 36 | # None
|
37 | 37 | #mkdir ('scanned')
|
38 | 38 |
|
39 |
| - for imageFile in imgFiles: |
40 |
| - image_data = tf.gfile.FastGFile(varPath+"/"+imageFile, 'rb').read() |
| 39 | + for image_file in img_files: |
| 40 | + image_data = tf.gfile.FastGFile(var_path+"/"+image_file, 'rb').read() |
41 | 41 |
|
42 |
| - print (varPath+"/"+imageFile) |
| 42 | + print (var_path+"/"+image_file) |
43 | 43 | predictions = sess.run(softmax_tensor, \
|
44 | 44 | {'DecodeJpeg/contents:0': image_data})
|
45 | 45 |
|
46 | 46 | # Sort to show labels of first prediction in order of confidence
|
47 | 47 | top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
|
48 | 48 | firstElt = top_k[0];
|
49 | 49 |
|
50 |
| - newFileName = label_lines[firstElt] +"--"+ str(predictions[0][firstElt])[2:7]+".jpg" |
51 |
| - print(newFileName) |
52 |
| - copyfile(varPath+"/"+imageFile, destDir+"/"+newFileName) |
| 50 | + new_file_name = label_lines[firstElt] +"--"+ str(predictions[0][firstElt])[2:7]+".jpg" |
| 51 | + print(new_file_name) |
| 52 | + copyfile(var_path+"/"+image_file, dest_dir+"/"+new_file_name) |
53 | 53 |
|
54 | 54 | for node_id in top_k:
|
55 | 55 | human_string = label_lines[node_id]
|
|
0 commit comments