I made an object classifier that classifies objects and gives predictions. It is working fine with images but when i am giving it a video input and running that on every 5 frames in the video, after a certain time it stops giving the error as given below:
My Error:
File “/home/shorav/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py”, line 2324, in _as_graph_def
raise ValueError(“GraphDef cannot be larger than 2GB.”)
ValueError: GraphDef cannot be larger than 2GB.
My Code:
import tensorflow as tf
import cv2
fn_list=
Capture video from file
cap = cv2.VideoCapture(‘combined.mp4’)
Frame_number=0
while True:
ret, frame = cap.read()
if ret == True:
Frame_number+=1
fn_list.append(Frame_number)
print “frame number is :”, Frame_number
gray = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)
cv2.imshow(‘frame’,gray)
if (Frame_number%5==0):
cv2.imwrite(‘new_capture.jpg’,frame)
image_path = ‘/home/shorav/tfClassifier/new_capture.jpg’
image_data = tf.gfile.FastGFile(image_path, ‘rb’).read()
label_lines = [line.rstrip() for line
in tf.gfile.GFile(“final_labels.txt”)]
with tf.gfile.FastGFile("./final_graph.pb", ‘rb’) as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name=’’)
with tf.Session() as sess:
softmax_tensor = sess.graph.get_tensor_by_name(‘final_result:0’)
predictions = sess.run(softmax_tensor, \
{‘DecodeJpeg/contents:0’: image_data})
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
score_results=
final_label=
for node_id in top_k:
human_string = label_lines[node_id]
score = predictions[0][node_id]
print(’%s (score = %.5f)’ % (human_string, score))
score_results.append(score)
final_label.append(human_string)
if cv2.waitKey(50) & 0xFF == ord(‘q’):
break
else:
break
cap.release()
cv2.destroyAllWindows()