Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to user this model2 with detection api because here .pb file is not available #10

Open
DeveloperRachit opened this issue Oct 23, 2019 · 6 comments

Comments

@DeveloperRachit
Copy link

2019-10-23 10:55:06.715141: W tensorflow/core/framework/allocator.cc:107] Allocation of 25690112 exceeds 10% of system memory.

@kalaspuffar
Copy link
Owner

Hi @DeveloperRachit

Seems you've got it to run but your graphic card seems to have too little memory to handle the model.

Best regards
Daniel

@DeveloperRachit
Copy link
Author

Hi @daniel

that problem has been solved issue is that which .pb file is created how to use it for detection.
i did it as like below code
label.txt

Best regards
Rachit
import sys
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
import numpy as np
import os,time
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import cv2
sys.path.append("..")
cap = cv2.VideoCapture("./test.avi")
fps = 30
capSize = (640, 480)
NUM_CLASSES = 1
detection_graph = tf.Graph()

with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile("./frozen.pb", 'rb') as fid:
serialized_graph = fid.read()
#print(serialized_graph)
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')

label_map = label_map_util.load_labelmap("./label.txt")
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
category_index = label_map_util.create_category_index(categories)
print (categories)
def load_image_into_numpy_array(image):
(im_width, im_height) = image.size
return np.array(image.getdata()).reshape(
(im_height, im_width, 3)).astype(np.uint8)

with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:

while cap.isOpened():
  ret, image_np = cap.read()
  if ret == True:

print (image_np)

      image_np_expanded = np.expand_dims(image_np, axis=0)
      print(image_np)
      #start_time = time.time()
      #print("Elapsed Time:", end_time-start_time)
      #image_np = detect_and_align.create_mtcnn(sess, None)
      image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')

      boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
      scores = detection_graph.get_tensor_by_name('detection_scores:0')
      classes = detection_graph.get_tensor_by_name('detection_classes:0')
      num_detections = detection_graph.get_tensor_by_name('num_detections:0')

      (boxes, scores, classes, num_detections) = sess.run(
          [boxes, scores, classes, num_detections],
          feed_dict={image_tensor: image_np_expanded})
      print "{bounding}{Boxes}"
      print boxes
      vis_util.visualize_boxes_and_labels_on_image_array(
          image_np,
          np.squeeze(boxes),
          np.squeeze(classes).astype(np.int32),
          np.squeeze(scores),
          category_index,
          use_normalized_coordinates=True,
          line_thickness=8)

out.write(image_np)

      im=cv2.resize(image_np,(960,540))
      #im=cv2.resize(image_np,(640,480))
      out_video.write(im)
      cv2.imshow('Output',im)

print(classes)

print(scores)

      if cv2.waitKey(1) & 0xFF == ord('q'):
          cv2.destroyAllWindows()
          break
  else:
      break

cap.release()
#out.release()
cv2.destroyAllWindows()

@DeveloperRachit
Copy link
Author

this error is after running that script


KeyError: "The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph."

@kalaspuffar
Copy link
Owner

Hi @DeveloperRachit

These kinds of issues are hard to solve as you need to read your graph and find what the actual inputs should be called. Maybe Tensorboard can help you there.

Best regards
Daniel

@DeveloperRachit
Copy link
Author

could you tell me the steps to train a datasets that is really big open_images_v4.
have you heard about it actually i want to train it i have this data csv annotation file and image data also hoe could i do that?

@kalaspuffar
Copy link
Owner

Hi @DeveloperRachit

I've not tried it myself and maybe I will look into it in the future and create a video to describe the workflow. But in the meantime, I found that some people had made a tutorial of how they built one of the datasets.

https://algorithmia.com/blog/deep-dive-into-object-detection-with-open-images-using-tensorflow

Maybe that could be an inspiration for you.

Best regards
Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants