-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathload_batches.py
88 lines (75 loc) · 3.33 KB
/
load_batches.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
import tensorflow as tf
BATCH_SIZE = 16
import os
def process_datax(dir_req):
HEIGHT, WIDTH, CHANNEL = 192, 256, 3
current_dir = os.getcwd()
# parent = os.path.dirname(current_dir)
images_dir = os.path.join(current_dir, dir_req)
images = []
for each in os.listdir(images_dir):
images.append(os.path.join(images_dir,each))
# print images
all_images = tf.convert_to_tensor(images, dtype = tf.string)
images_queue = tf.train.slice_input_producer(
[all_images])
content = tf.read_file(images_queue[0])
image = tf.image.decode_jpeg(content, channels = CHANNEL)
# sess1 = tf.Session()
# print sess1.run(image)
image = tf.image.random_flip_left_right(image)
image = tf.image.random_brightness(image, max_delta = 0.1)
image = tf.image.random_contrast(image, lower = 0.9, upper = 1.1)
# noise = tf.Variable(tf.truncated_normal(shape = [HEIGHT,WIDTH,CHANNEL], dtype = tf.float32, stddev = 1e-3, name = 'noise'))
# print image.get_shape()
size = [HEIGHT, WIDTH]
image = tf.image.resize_images(image, size)
image.set_shape([HEIGHT,WIDTH,CHANNEL])
# image = image + noise
# image = tf.transpose(image, perm=[2, 0, 1])
# print image.get_shape()
image = tf.cast(image, tf.float32)
image = image / 255.0
iamges_batch = tf.train.shuffle_batch(
[image], batch_size = BATCH_SIZE,
num_threads = 4, capacity = 200 + 3* BATCH_SIZE,
min_after_dequeue = 200)
num_images = len(images)
return iamges_batch
BATCH_SIZE = 16
import os
def process_datay(dir_req):
HEIGHT, WIDTH, CHANNEL = 192, 256, 1
current_dir = os.getcwd()
# parent = os.path.dirname(current_dir)
images_dir = os.path.join(current_dir, dir_req)
images = []
for each in os.listdir(images_dir):
images.append(os.path.join(images_dir,each))
# print images
all_images = tf.convert_to_tensor(images, dtype = tf.string)
images_queue = tf.train.slice_input_producer(
[all_images])
content = tf.read_file(images_queue[0])
image = tf.image.decode_jpeg(content, channels = CHANNEL)
# sess1 = tf.Session()
# print sess1.run(image)
image = tf.image.random_flip_left_right(image)
image = tf.image.random_brightness(image, max_delta = 0.1)
image = tf.image.random_contrast(image, lower = 0.9, upper = 1.1)
# noise = tf.Variable(tf.truncated_normal(shape = [HEIGHT,WIDTH,CHANNEL], dtype = tf.float32, stddev = 1e-3, name = 'noise'))
# print image.get_shape()
size = [HEIGHT, WIDTH]
image = tf.image.resize_images(image, size)
image.set_shape([HEIGHT,WIDTH,CHANNEL])
# image = image + noise
# image = tf.transpose(image, perm=[2, 0, 1])
# print image.get_shape()
image = tf.cast(image, tf.float32)
image = image / 255.0
iamges_batch = tf.train.shuffle_batch(
[image], batch_size = BATCH_SIZE,
num_threads = 4, capacity = 200 + 3* BATCH_SIZE,
min_after_dequeue = 200)
num_images = len(images)
return iamges_batch