In [ ]:
# import
import os
import sys
import time
import copy
import h5py
import numpy as np
from tf_cnnvis import *
import tensorflow as tf
from scipy.misc import imread, imresize
In [ ]:
# download InceptionV5 model if not
if not os.path.exists("./inception5h.zip"):
os.system("python -m wget -o ./inception5h.zip https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip && unzip inception5h.zip")
In [ ]:
# importing InceptionV5 model
with tf.gfile.FastGFile('tensorflow_inception_graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
t_input = tf.placeholder(np.float32, name='input') # define the input tensor
imagenet_mean = 117.0
t_preprocessed = t_input-imagenet_mean
tf.import_graph_def(graph_def, {'input':t_preprocessed})
In [ ]:
# reading sample image
im = np.expand_dims(imresize(imread(os.path.join("./sample_images", "images.jpg")), (224, 224)), axis = 0)
In [ ]:
# deepdream visualization
layer = "import/softmax2_pre_activation"
start = time.time()
# api call
In [ ]:
is_success = deepdream_visualization(sess_graph_path = tf.get_default_graph(), value_feed_dict = {t_input : im},
layer=layer, classes = [1, 2, 3, 4, 5],
path_logdir=os.path.join("Log","Inception5"),
path_outdir=os.path.join("Output","Inception5"))
start = time.time() - start
print("Total Time = %f" % (start))
In [ ]: