Skip to content

Commit 5cc22df

Browse files
committed
Move image into a dir for the label rather than copy and change name
1 parent f55dc91 commit 5cc22df

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/py/label_dir.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
import errno
12
import tensorflow as tf
23
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+
516

617
src_dir = '/toScan'
718
dest_dir = '/scanned'
@@ -25,17 +36,22 @@
2536
src_image_path = join(src_dir, image_file)
2637
image_data = tf.gfile.FastGFile(src_image_path, 'rb').read()
2738

28-
print src_image_path
39+
print(src_image_path)
2940
predictions = sess.run(softmax_tensor, \
3041
{'DecodeJpeg/contents:0': image_data})
3142

3243
# Sort to show labels of first prediction in order of confidence
3344
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
3445
firstElt = top_k[0];
3546

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)
3955

4056
for node_id in top_k:
4157
human_string = label_lines[node_id]

0 commit comments

Comments
 (0)