I am getting an error while running a tensorflow program in spyder using python 2.7 ?

1 view
Skip to first unread message

shorav suriyal

unread,
Oct 20, 2017, 8:56:16 PM10/20/17
to Anaconda - Public
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 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()
error 1

Pete Jemian

unread,
Oct 20, 2017, 10:11:56 PM10/20/17
to anac...@continuum.io
This appe to be a question about tensorflow, not specific to anaconda
python. You might be better served by posting your question to
tensorflow's suggested support location on Stack Overflow:

https://stackoverflow.com/questions/tagged/tensorflow
> --
> Anaconda Community Support Group Brought to you by Continuum Analytics
> ---
> You received this message because you are subscribed to the Google
> Groups "Anaconda - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to anaconda+u...@continuum.io
> <mailto:anaconda+u...@continuum.io>.
> To post to this group, send email to anac...@continuum.io
> <mailto:anac...@continuum.io>.
> Visit this group at
> https://groups.google.com/a/continuum.io/group/anaconda/.
Reply all
Reply to author
Forward
0 new messages