File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change
1
+ import errno
1
2
import tensorflow as tf
2
3
from shutil import copyfile
3
- from os import listdir
4
- from os .path import isfile , join
4
+ from os import listdir , makedirs
5
+ from os .path import isfile , join , isdir
6
+
7
+ def mkdir_p (path ):
8
+ try :
9
+ makedirs (path )
10
+ except OSError as exc : # Python >2.5
11
+ if exc .errno == errno .EEXIST and isdir (path ):
12
+ pass
13
+ else :
14
+ raise
15
+
5
16
6
17
src_dir = '/toScan'
7
18
dest_dir = '/scanned'
25
36
src_image_path = join (src_dir , image_file )
26
37
image_data = tf .gfile .FastGFile (src_image_path , 'rb' ).read ()
27
38
28
- print src_image_path
39
+ print ( src_image_path )
29
40
predictions = sess .run (softmax_tensor , \
30
41
{'DecodeJpeg/contents:0' : image_data })
31
42
32
43
# Sort to show labels of first prediction in order of confidence
33
44
top_k = predictions [0 ].argsort ()[- len (predictions [0 ]):][::- 1 ]
34
45
firstElt = top_k [0 ];
35
46
36
- new_file_name = label_lines [firstElt ] + '--' + str (predictions [0 ][firstElt ])[2 :7 ]+ '.jpg'
37
- print (new_file_name )
38
- copyfile (src_image_path , join (dest_dir , new_file_name ))
47
+ label_dest_folder = join (dest_dir , label_lines [firstElt ])
48
+ mkdir_p (label_dest_folder )
49
+
50
+ final_file_path = join (label_dest_folder , image_file )
51
+
52
+ print (final_file_path )
53
+
54
+ move (src_image_path , final_file_path )
39
55
40
56
for node_id in top_k :
41
57
human_string = label_lines [node_id ]
You can’t perform that action at this time.
0 commit comments