Guest User

Untitled

a guest
May 23rd, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. ValueError: Fetch argument 'infer' cannot be interpreted as a Tensor. ("The name 'infer' refers to an Operation not in the graph.")
  2.  
  3. class Controller_tf:
  4.  
  5. set_speed = None
  6.  
  7. def __init__(self, model, ckpt_path, set_speed_in):
  8.  
  9. self.set_speed = set_speed_in
  10.  
  11. self.x = tf.placeholder(tf.float32, shape = (None, 104, 160, 3))
  12. self.y = model(self.x, None, tf.estimator.ModeKeys.PREDICT)
  13.  
  14. # make TF use memory growth method
  15. config = tf.ConfigProto()
  16. config.gpu_options.allow_growth = True
  17. self.sess = tf.Session(config=config)
  18.  
  19. saver = tf.train.Saver()
  20. saver.restore(self.sess, ckpt_path)
  21.  
  22.  
  23. def update(self, message):
  24. # The current speed of the car
  25.  
  26. image = frame2numpy(message['frame'], (160,104))
  27. image_array = np.asarray(image)
  28.  
  29. turn_logits = self.sess.run(self.y, {self.x: image_array[None, :, :, :]})
  30. return turn_logits
  31.  
  32. model = cnn_model_fn3
  33. ckpt = 'ckpts/stc_model3/model.ckpt-27621'
  34. controller = Controller_tf(model, ckpt, 18)
  35.  
  36. image_file = 'G:/Datasets/ds072.001/ds072.001-fm-0008465.jpg'
  37. #image_file = 'G:/Datasets/ds072.001/ds072.001-fm-0009156.jpg'
  38.  
  39. satnavimg = load_image(image_file)
  40. satnavimg = np.asarray([satnavimg])
  41. satnavimg = (satnavimg/127.5) - 1.0
  42. print(np.shape(satnavimg))
  43. msg = {'frame': satnavimg}
  44. turn = controller.update(msg)
  45.  
  46. print(turn)
  47.  
  48. def cnn_model_fn3(features, labels, mode):
  49.  
  50. if mode == tf.estimator.ModeKeys.PREDICT:
  51. input_layer = features
  52. else:
  53. input_layer = tf.reshape(features["image_data"], [-1, 104, 160, 3])
  54.  
  55. conv1 = tf.layers.conv2d(
  56. inputs=input_layer,
  57. filters=32,
  58. kernel_size=[10, 10],
  59. padding="same",
  60. activation=tf.nn.relu,
  61. name='Conv1')
  62.  
  63. ... removed layer code for brevity ...
  64.  
  65. logits = tf.layers.dense(
  66. inputs=dropout1,
  67. units=3,
  68. name='Dense3')
  69.  
  70. predictions = {
  71. "classes": tf.argmax(input=logits, axis=1),
  72. "probabilities": tf.nn.softmax(logits, name="softmax_tensor")
  73. }
  74. if mode == tf.estimator.ModeKeys.PREDICT:
  75. return tf.estimator.EstimatorSpec(mode=mode, predictions=predictions)
  76.  
  77. # Calculate Loss (for both TRAIN and EVAL modes)
  78. loss = tf.losses.sparse_softmax_cross_entropy(labels=labels, logits=logits)
  79.  
  80. # Configure the Training Op (for TRAIN mode)
  81. if mode == tf.estimator.ModeKeys.TRAIN:
  82. optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001)
  83. train_op = optimizer.minimize(
  84. loss=loss,
  85. global_step=tf.train.get_global_step())
  86. return tf.estimator.EstimatorSpec(mode=mode, loss=loss, train_op=train_op)
  87.  
  88. # Add evaluation metrics (for EVAL mode)
  89. if mode == tf.estimator.ModeKeys.EVAL:
  90. eval_metric_ops = {
  91. "accuracy": tf.metrics.accuracy(
  92. labels=labels, predictions=predictions["classes"])}
  93. if mode == tf.estimator.ModeKeys.PREDICT:
  94. return logits
  95. return tf.estimator.EstimatorSpec(
  96. mode=mode, loss=loss, eval_metric_ops=eval_metric_ops)
Add Comment
Please, Sign In to add comment