Skip to content

Commit ba556d9

Browse files
committed
Completing Tensorflow statistics
1 parent dd839b8 commit ba556d9

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

DenseNet/preprocessing/densenet_pre.py

-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ def _crop(image, offset_height, offset_width, crop_height, crop_width):
6262
tf.summary.image("rnd_cropped_image", tf.expand_dims(image,0))
6363
return tf.reshape(image, cropped_shape)
6464

65-
66-
67-
68-
6965
def _random_crop(image_list, crop_height, crop_width):
7066

7167
"""Crops the given list of images.

utils/images/visu_tensorflow.py

+23-10
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,19 @@ def extract_image(filename, num_channels):
3838
image = tf.image.convert_image_dtype(image, tf.float32)
3939
return image
4040

41-
def per_pixel_mean_stddev(dataset):
41+
def per_pixel_mean_stddev(dataset, image_size):
4242
"""
4343
Compute the mean of each pixel over the entire dataset.
4444
4545
"""
46-
return
46+
maximum = image_size*image_size*3
47+
initial_state = tf.constant([0.]*maximum)
48+
count = dataset.reduce(0, lambda x, _: x+1)
49+
dataset_resized = dataset.map(lambda x: resize([x], image_size))
50+
dataset_per_pixel = dataset_resized.map(lambda x: tf.reshape(x, [-1]))
51+
pixel_sum = dataset_per_pixel.reduce(initial_state, lambda x, y: x + y)
52+
pixel_mean = tf.divide(pixel_sum, tf.to_float(count))
53+
return pixel_mean
4754

4855
def per_channel_mean_stddev(dataset):
4956
"""
@@ -53,7 +60,8 @@ def channel_mean_stddev(decoded_image):
5360
means = tf.reduce_mean(decoded_image, axis=[0,1])
5461
stddev = tf.sqrt(tf.reduce_mean(tf.square(decoded_image-means), axis=[0,1]))
5562
return tf.stack([means, stddev])
56-
return dataset.map(lambda x: channel_mean_stddev(x))
63+
per_channel_mean_stddev_dataset = dataset.map(lambda x: channel_mean_stddev(x))
64+
return per_channel_mean_stddev_dataset
5765

5866
def per_mean_stddev(dataset):
5967
"""
@@ -72,12 +80,17 @@ def encode_stats(alpha):
7280
"""
7381
pass
7482

83+
def resize(image, image_size):
84+
rank_assertion = tf.Assert(
85+
tf.equal(tf.rank(image), 4),
86+
['Rank of image must be equal to 4.'])
87+
with tf.control_dependencies([rank_assertion]):
88+
image = tf.image.resize_bilinear(image, [image_size, image_size])[0]
89+
return image
90+
91+
7592
a, b = load_images("D:/MURA-v1.1/train/*/*/*/*.png", 3 ,image_extension='png')
76-
a= per_channel_mean_stddev(a)
77-
a_iter = a.make_one_shot_iterator()
78-
image = a_iter.get_next()
79-
b_iter = b.make_one_shot_iterator()
80-
label = b_iter.get_next()
93+
a = per_pixel_mean_stddev(a, 300)
8194
with tf.Session() as sess:
82-
for i in range(10):
83-
print(sess.run([image, label]))
95+
sess.run(a)
96+
print(a)

0 commit comments

Comments
 (0)