使用Tensorflow更快的RCNN推理错误

时间:2019-06-16 15:47:18

标签: python tensorflow faster-rcnn

我试图在Tensorflow上运行推理FRCNN模型。

错误是

TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("image_tensor:0", shape=(?, ?, ?, 3), dtype=uint8) is not an element of this graph.

错误发生在

b, s, c = self.regsess.run([self.box, self.score, self.cls], {self.image_tensor: image_data})

我的代码是

class DigitRecognition:
   def __init__(self):
      self.regsess=tf.Session()
      self.reg_graph = tf.Graph()
      self.image_tensor=tf.placeholder(tf.float32, shape=(1, 300, 512, 3))
      self.box=[]
      self.score=[]
      self.cls=[]
      with self.reg_graph.as_default():
         with tf.gfile.FastGFile("recognition_tf_model/frozen_model.pb",'rb') as f:
            self.graph_def = tf.GraphDef()
            self.graph_def.ParseFromString(f.read())
            self.image_tensor, self.box, self.score, self.cls = tf.import_graph_def(self.graph_def, name='',return_elements=['image_tensor:0','detection_boxes:0', 'detection_scores:0', 'detection_classes:0'])

   def infer(self, crop, frame, w, h):
      image = cv2.resize(crop,(512,300))
      image_data = np.expand_dims(image, axis=0).astype(np.uint8)
      b, s, c = self.regsess.run([self.box, self.score, self.cls], {self.image_tensor: image_data})
      if(len(b)==0 or len(s)==0 or len(c)==0):
         return
      boxes = b[0]
      conf = s[0]
      clses = c[0]
      for i in (range(len(boxes))):
         bx = boxes[i]
         if conf[i] < 0.5:
            continue
         p1 = (int(w * bx[1]), int(h * bx[0]))
         p2 = (int(w * bx[3]) ,int(h * bx[2]))

         cv2.rectangle(frame, p1, p2, (0,255,0))
      cv2.imshow("Numplate recognition", frame)
      cv2.waitKey(1)

def main():
   dr=DigitRecognition()
   ...........................
   dr.infer(frame[p1[1]:p2[1], p1[0]:p2[0]], frame, width, height)

可以穿什么?

0 个答案:

没有答案