Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
386 Views

Can't Compile a Simple Network

I am trying to compile a _very_ simple neural network written in TensorFlow and saved as a .meta graph. The network was taken directly from this tutorial:

 

http://stackabuse.com/tensorflow-save-and-restore-models/

 

which I followed in order to learn how to save and restore graphs. I have made minor changes to name inputs and outputs (I'm including all my Python notebooks and the saved .meta). When trying to compile using mcNCCompile I am stuck on the TensorFlow error:

 

tensorflow.python.framework.errors_impl.InvalidArgumentError: Input 1 (tensor_name) must be a string scalar; got a tensor of 2elements [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]

 

It is not obvious to me where it expects a tensor with a type "string scalar" and so I'm not clear where it is being fed a tensor of "2elements".

 

This was intended to be a simple test of mvNCCompile. This command is giving me errors on a larger, more complicated network and I wanted to run a simple experiment with a simple network to help me better understand the process. I am disappointed that I am still running into hiccups here. Any help would be much appreciated.

 

I am including my code below. I tried uploading the files but they aren't allowed (!?). I cannot upload the .meta file either (why can't I attach any files???). The .meta can easily be produced by running SaveTest.py as long as there is a folder named "saved" in the same directory.

 

After producing the .meta graph I can produce the error by running:

 

mvNCCompile model_final.meta -in=X -on=y

 

or even just

 

mvNCCompile model_final.meta

 

""" SaveTest.py This file builds, trains and saves the network. """ import tensorflow as tf import numpy as np import matplotlib.pyplot as plt tf.reset_default_graph() X = tf.placeholder(tf.float32, name="X") Y = tf.placeholder(tf.float32, name="y") h_est = tf.Variable(0.0, name='h_estimate') v_est = tf.Variable(0.0, name='v_estimate') y_est = tf.square(X - h_est) + v_est cost = (tf.pow(Y - y_est, 2)) trainop = tf.train.GradientDescentOptimizer(0.001).minimize(cost) h = 1 v = -2 x_train = np.linspace(-2, 4, 201) noise = np.random.randn(*x_train.shape) * 0.4 y_train = (x_train - h) ** 2 + v + noise plt.rcParams['figure.figsize'] = (10, 6) plt.scatter(x_train, y_train) plt.xlabel('x_train') plt.ylabel('y_train') saver = tf.train.Saver() init = tf.global_variables_initializer() def train_graph(): with tf.Session() as sess: sess.run(init) for i in range(100): for (x, y) in zip(x_train, y_train): sess.run(trainop, feed_dict={X: x, Y: y}) saver.save(sess, 'saved/model_iter', global_step=i) saver.save(sess, 'saved/model_final') print("Training complete!") h_ = sess.run(h_est) v_ = sess.run(v_est) return h_, v_ result = train_graph() print("h_est = %.2f, v_est = %.2f" % result) """ RestoreTest.py This file reloads the network via the saved .meta and prints the learned parameters """ import tensorflow as tf import numpy as np import matplotlib.pyplot as plt tf.reset_default_graph() imported_meta = tf.train.import_meta_graph("saved/model_final.meta") with tf.Session() as sess: imported_meta.restore(sess, tf.train.latest_checkpoint('saved')) h_est2 = sess.run('h_estimate:0') v_est2 = sess.run('v_estimate:0') print("h_est: %.2f, v_est: %.2f" % (h_est2, v_est2))
Tags (1)
0 Kudos
0 Replies
Reply