-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_classes.py
More file actions
32 lines (29 loc) · 1011 Bytes
/
count_classes.py
File metadata and controls
32 lines (29 loc) · 1011 Bytes
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
import tensorflow as tf
import nerveseg_input
import skimage
import skimage.io
import numpy as np
FLAGS = tf.app.flags.FLAGS
def main(argv=None):
train_dict = nerveseg_input.read_labeled_image_dir(FLAGS.image_dir)
zero_count = 0
one_count = 0
n = 0
for name, (_, label_filename) in train_dict.iteritems():
img = skimage.io.imread(label_filename)
arr = np.array(img)
unique, counts = np.unique(arr, return_counts=True)
for i, value in enumerate(unique):
if value == 0:
zero_count += counts[i]
elif value == 255:
one_count += counts[i]
else:
print("element with value: {} found".format(value))
exit()
if n % 20 == 0:
print("There are {} backround and {} foreground".format(zero_count, one_count))
n += 1
print("There are {} backround and {} foreground".format(zero_count, one_count))
if __name__ == '__main__':
tf.app.run()