Our input images have varied resolution while a model often requires fixed-size inputs so that we need to preprocess them to have a uniform size for our data. To do that, we take two bellow steps:
In [ ]:
%matplotlib inline
%load_ext autoreload
%autoreload 2
import tensorflow as tf
from scipy.misc import imread, imresize
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import gridspec
from Dataset.data import preprocess_image
image = tf.placeholder("uint8", [None, None, 3])
result_image = preprocess_image(image, 34, 34)
raw_image = imread('/home/taivu/workspace/NudityDetection/Dataset/train/normal/34.jpg')
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
result_img = sess.run(result_image, feed_dict={image:raw_image})
################ Plot the raw image and the processed image ##########################
gs = gridspec.GridSpec(1, 2, width_ratios=[3, 2])
fig = plt.figure()
a1 = fig.add_subplot(gs[0])
a1.set_title("Raw image")
plt.imshow(raw_image)
a2 = fig.add_subplot(gs[1])
a2.set_title("Processed image")
plt.imshow(result_img, shape =(34, 34))
plt.show()
In [ ]:
import tensorflow as tf
from vng_train import train
# Do train the model
train()
In [ ]:
%matplotlib inline
%load_ext autoreload
%autoreload 2
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from execute_model import evaluate
# Evaluate the model
img, pre_lb, real_lb = evaluate()
fig = plt.figure(figsize=(20,20))
for i in range(50):
a = fig.add_subplot(10,5, i)
a.set_title('PL:%d'%(pre_lb[i]))
a.set_yticklabels([])
a.set_xticklabels([])
plt.imshow(img[i])
plt.pause(1)
plt.show()
#print pre_lb
#print real_lb
num_err = np.absolute(pre_lb - real_lb)
print('The number of error samples: %d'%np.sum(num_err))
In [ ]:
%matplotlib inline
%load_ext autoreload
%autoreload 2
import tensorflow as tf
import matplotlib.pyplot as plt
from execute_model import evaluate
import numpy as np
# Evaluate the model
img, pre_lb, real_lb = evaluate('/home/taivu/workspace/NudityDetection/Dataset/normal_test_set.tfrecords')
#print('Predicted labels: ',pre_lb)
#print('Real labels: ',real_lb)
fig = plt.figure(figsize=(20,20))
for i in range(50):
a = fig.add_subplot(10,5, i)
a.set_title('PL:%d'%(pre_lb[i]))
a.set_yticklabels([])
a.set_xticklabels([])
plt.imshow(img[i])
plt.show()
num_err = np.absolute(pre_lb - real_lb)
print('The number of error samples: %d'%np.sum(num_err))
In [ ]:
%matplotlib inline
%load_ext autoreload
%autoreload 2
import tensorflow as tf
import matplotlib.pyplot as plt
from execute_model import evaluate
# Evaluate the model
img, pre_lb, real_lb = evaluate('/home/taivu/workspace/NudityDetection/Dataset/nudity_test_set.tfrecords', False)
fig = plt.figure(figsize=(20,20))
for i in range(50):
a = fig.add_subplot(10,5, i)
a.set_title('PL:%d'%(pre_lb[i]))
a.set_yticklabels([])
a.set_xticklabels([])
plt.imshow(img[i])
plt.show()
num_err = np.absolute(pre_lb - real_lb)
print('The number of error samples: %d'%np.sum(num_err))
In [3]:
############################PIPELINE INPUT DATA########################################
%matplotlib inline
%load_ext autoreload
%autoreload 2
import tensorflow as tf
import matplotlib.pyplot as plt
from execute_model import evaluate
import numpy as np
eval_img, pre_label, _ = evaluate('/home/taivu/workspace/AddPic', True)
#fig = plt.figure(figsize=(40,80))
#for i in range(80):
# a = fig.add_subplot(16,5, i)
# a.set_title('PL:%d'%(pre_label[i]))
# a.set_yticklabels([])
# a.set_xticklabels([])
# plt.imshow(eval_img[i])
#plt.show()
In [3]:
# Test program
%matplotlib inline
%load_ext autoreload
%autoreload 2
from test_program import test_program
test_program()