Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ValueError: Fetch argument 'infer' cannot be interpreted as a Tensor. ("The name 'infer' refers to an Operation not in the graph.")
- class Controller_tf:
- set_speed = None
- def __init__(self, model, ckpt_path, set_speed_in):
- self.set_speed = set_speed_in
- self.x = tf.placeholder(tf.float32, shape = (None, 104, 160, 3))
- self.y = model(self.x, None, tf.estimator.ModeKeys.PREDICT)
- # make TF use memory growth method
- config = tf.ConfigProto()
- config.gpu_options.allow_growth = True
- self.sess = tf.Session(config=config)
- saver = tf.train.Saver()
- saver.restore(self.sess, ckpt_path)
- def update(self, message):
- # The current speed of the car
- image = frame2numpy(message['frame'], (160,104))
- image_array = np.asarray(image)
- turn_logits = self.sess.run(self.y, {self.x: image_array[None, :, :, :]})
- return turn_logits
- model = cnn_model_fn3
- ckpt = 'ckpts/stc_model3/model.ckpt-27621'
- controller = Controller_tf(model, ckpt, 18)
- image_file = 'G:/Datasets/ds072.001/ds072.001-fm-0008465.jpg'
- #image_file = 'G:/Datasets/ds072.001/ds072.001-fm-0009156.jpg'
- satnavimg = load_image(image_file)
- satnavimg = np.asarray([satnavimg])
- satnavimg = (satnavimg/127.5) - 1.0
- print(np.shape(satnavimg))
- msg = {'frame': satnavimg}
- turn = controller.update(msg)
- print(turn)
- def cnn_model_fn3(features, labels, mode):
- if mode == tf.estimator.ModeKeys.PREDICT:
- input_layer = features
- else:
- input_layer = tf.reshape(features["image_data"], [-1, 104, 160, 3])
- conv1 = tf.layers.conv2d(
- inputs=input_layer,
- filters=32,
- kernel_size=[10, 10],
- padding="same",
- activation=tf.nn.relu,
- name='Conv1')
- ... removed layer code for brevity ...
- logits = tf.layers.dense(
- inputs=dropout1,
- units=3,
- name='Dense3')
- predictions = {
- "classes": tf.argmax(input=logits, axis=1),
- "probabilities": tf.nn.softmax(logits, name="softmax_tensor")
- }
- if mode == tf.estimator.ModeKeys.PREDICT:
- return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions)
- # Calculate Loss (for both TRAIN and EVAL modes)
- loss = tf.losses.sparse_softmax_cross_entropy(labels=labels, logits=logits)
- # Configure the Training Op (for TRAIN mode)
- if mode == tf.estimator.ModeKeys.TRAIN:
- optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001)
- train_op = optimizer.minimize(
- loss=loss,
- global_step=tf.train.get_global_step())
- return tf.estimator.EstimatorSpec(mode=mode, loss=loss, train_op=train_op)
- # Add evaluation metrics (for EVAL mode)
- if mode == tf.estimator.ModeKeys.EVAL:
- eval_metric_ops = {
- "accuracy": tf.metrics.accuracy(
- labels=labels, predictions=predictions["classes"])}
- if mode == tf.estimator.ModeKeys.PREDICT:
- return logits
- return tf.estimator.EstimatorSpec(
- mode=mode, loss=loss, eval_metric_ops=eval_metric_ops)
Add Comment
Please, Sign In to add comment