forked from mariolew/TF-FaceDetection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_inputs.py
executable file
·111 lines (75 loc) · 3.67 KB
/
image_inputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import tensorflow as tf
def read_my_file_format(filename):
record_defaults = [[""]] + [[0]]
components = tf.decode_csv(filename, record_defaults=record_defaults, field_delim=" ")
imgName = components[0]
label = components[1:]
img_contents = tf.read_file(imgName)
img = tf.image.decode_jpeg(img_contents, channels=3)
return img, label
def inputs(lists, image_shape, batch_size):
filename_queue = tf.train.string_input_producer(lists, shuffle=True)
reader = tf.TextLineReader()
_, value = reader.read(filename_queue)
image, label = read_my_file_format(value)
image = tf.image.resize_images(image, [image_shape[0]+3, image_shape[1]+3])
image = tf.random_crop(image, image_shape)
label = tf.cast(label, tf.float32)
image.set_shape(image_shape)
# image = tf.image.random_flip_left_right(image)
float_image = tf.image.per_image_whitening(image)
min_after_dequeue = 1000
capacity = min_after_dequeue+(2+1)*batch_size
image_batch, label_batch = tf.train.shuffle_batch([float_image, label],
batch_size=batch_size,
capacity=capacity,
min_after_dequeue=min_after_dequeue)
return image_batch, label_batch
def inputs_without_crop(lists, image_shape, batch_size):
filename_queue = tf.train.string_input_producer(lists, shuffle=True)
reader = tf.TextLineReader()
_, value = reader.read(filename_queue)
image, label = read_my_file_format(value)
image = tf.image.resize_images(image, [image_shape[0], image_shape[1]])
# image = tf.random_crop(image, image_shape)
label = tf.cast(label, tf.float32)
image.set_shape(image_shape)
# image = tf.image.random_flip_left_right(image)
float_image = tf.image.per_image_whitening(image)
min_after_dequeue = 1000
capacity = min_after_dequeue+(2+1)*batch_size
# image_batch, label_batch = tf.train.shuffle_batch([float_image, label],
# batch_size=batch_size,
# capacity=capacity,
# min_after_dequeue=min_after_dequeue)
image_batch, label_batch = tf.train.batch([float_image, label],
batch_size=batch_size,
capacity=128)
return image_batch, label_batch
def inputs_for_test(lists, image_shape, batch_size):
filename_queue = tf.train.string_input_producer(lists, shuffle=True)
reader = tf.TextLineReader()
_, value = reader.read(filename_queue)
image, label = read_my_file_format(value)
image = tf.image.resize_images(image, [image_shape[0], image_shape[1]])
# image = tf.random_crop(image, image_shape)
label = tf.cast(label, tf.float32)
image.set_shape(image_shape)
# image = tf.image.random_flip_left_right(image)
float_image = tf.image.per_image_whitening(image)
min_after_dequeue = 1000
capacity = min_after_dequeue+(2+1)*batch_size
image_batch, label_batch = tf.train.batch([float_image, label],
batch_size=batch_size)
return image_batch, label_batch
if __name__ == '__main__':
image_batch, label_batch = inputs(['net_12_list.txt'], [12, 12, 3], 10)
sess = tf.Session()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
for i in range(100):
ibatch, lbatch = sess.run([image_batch, label_batch])
print(lbatch)
coord.request_stop()
coord.join(threads)
sess.close()