I tried testing a single image on the tensorflow CIFAR 10 tutorial using the code given by bigdata2 for training in the link. 1 The following changes were made to CIFAR10_train.py
def train():
"""Train CIFAR-10 for a number of steps."""
with tf.Graph().as_default():
global_step = tf.contrib.framework.get_or_create_global_step()
with tf.device('/cpu:0'):
images, labels = cifar10.distorted_inputs()
is_training = tf.placeholder(dtype=bool,shape=(),name='is_training')
imgs = tf.placeholder(tf.float32, (1, 32, 32, 3), name='imgs')
images = tf.cond(is_training, lambda:images, lambda:imgs)
logits = cifar10.inference(images)
The other change which has been made is
import numpy as np
tmp_img = np.ndarray(shape=(1,32,32,3), dtype=float)
with tf.train.MonitoredTrainingSession(
checkpoint_dir=FLAGS.train_dir,
hooks=[tf.train.StopAtStepHook(last_step=FLAGS.max_steps),
tf.train.NanTensorHook(loss),
_LoggerHook()],
config=tf.ConfigProto(
log_device_placement=FLAGS.log_device_placement)) as mon_sess:
while not mon_sess.should_stop():
mon_sess.run(train_op, feed_dict={is_training: True, imgs: tmp_img})
I'm getting the error:
runfile('C:/Users/User/new_train.py', wdir='C:/Users/User') Filling queue with 20000 CIFAR images before starting to train. This will take a few minutes.
Traceback (most recent call last):
File "", line 1, in runfile('C:/Users/User/new_train.py', wdir='C:/Users/User')
File "C:\Users\User\AppData\Local\conda\conda\envs\tensorflow_windows\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile execfile(filename, namespace)
File "C:\Users\User\AppData\Local\conda\conda\envs\tensorflow_windows\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/User/new_train.py", line 135, in tf.app.run()
File "C:\Users\User\AppData\Local\conda\conda\envs\tensorflow_windows\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "C:/Users/User/new_train.py", line 131, in main train()
File "C:/Users/User/new_train.py", line 77, in train logits = cifar10.inference(images)
File "C:\Users\User\cifar10.py", line 246, in inference stddev=0.04, wd=0.004)
File "C:\Users\User\cifar10.py", line 135, in _variable_with_weight_decay tf.truncated_normal_initializer(stddev=stddev, dtype=dtype))
File "C:\Users\User\cifar10.py", line 111, in _variable_on_cpu var = tf.get_variable(name, shape, initializer=initializer, dtype=dtype)
File "C:\Users\User\AppData\Local\conda\conda\envs\tensorflow_windows\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1203, in get_variable constraint=constraint)
File "C:\Users\User\AppData\Local\conda\conda\envs\tensorflow_windows\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1092, in get_variable constraint=constraint)
File "C:\Users\User\AppData\Local\conda\conda\envs\tensorflow_windows\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 425, in get_variable constraint=constraint)
File "C:\Users\User\AppData\Local\conda\conda\envs\tensorflow_windows\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 394, in _true_getter use_resource=use_resource, constraint=constraint)
File "C:\Users\User\AppData\Local\conda\conda\envs\tensorflow_windows\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 763, in _get_single_variable "but instead was %s." % (name, shape))
ValueError: Shape of a new variable (local3/weights) must be fully defined, but instead was (?, 384).
Can someone give suggestions for rectifying this error?