In [1]:
import numpy as np
import tensorflow as tf
In [2]:
%matplotlib notebook
import matplotlib
import matplotlib.pyplot as plt
from IPython.display import Image
In [3]:
size = 10
tf.reset_default_graph()
all_faces = tf.Variable(0,validate_shape=False, dtype=tf.float32, name='all_faces')
saver = tf.train.Saver()
sess = tf.Session()
In [4]:
with sess.as_default():
tf.initialize_all_variables().run()
for var in tf.all_variables():
print (var.name, var.eval().shape)
print all_faces.eval()
In [5]:
with sess.as_default():
ckpt = tf.train.get_checkpoint_state("./tmp/")
if ckpt and ckpt.model_checkpoint_path:
print ckpt.model_checkpoint_path
saver.restore(sess, ckpt.model_checkpoint_path)
print("Model restored.")
else:
print ("Model not restored.")
In [6]:
with sess.as_default():
for var in tf.all_variables():
print (var.name, var.eval().shape)
print all_faces.eval()
In [7]:
#need to be called within a session
def write_png(tensor, name):
casted_to_uint8 = tf.cast(tensor, tf.uint8)
converted_to_png = tf.image.encode_png(casted_to_uint8)
f = open(name, "wb+")
f.write(converted_to_png.eval())
f.close()
In [8]:
# Init size
with sess.as_default():
a_face = tf.gather(all_faces,[0])
print a_face.eval().shape
# remove channel dimension and add index dimension
pict_face = tf.expand_dims(tf.squeeze(a_face, squeeze_dims=[0]),2)
print pict_face.eval().shape
write_png(pict_face, 'a_face.png')
In [9]:
Image("a_face.png")
Out[9]:
Feedback wellcome @dh7net