python - Why doesn't tensorflow allow me to write file? -


i newbie tensorflow. have trained model classify images tensorflow, , prediction works well. however, when try write classification result of test dataset result file, said tensorflow.python.framework.errors_impl.permissiondeniederror: file isn't open writing.
and here python code:

import tensorflow tf, sys import os  image_path = sys.argv[1] images = os.listdir(image_path) f = file("/tf_files/result.csv","w+") f.write("image,alb,bet,dol,lag,nof,other,shark,yft\n") image in images:     # read in image_data     image_data = tf.gfile.fastgfile(image_path + image, 'rb').read()      # loads label file, strips off carriage return     label_lines = [line.rstrip() line                    in tf.gfile.gfile("/tf_files/retrained_labels.txt")]      # unpersists graph file     tf.gfile.fastgfile("/tf_files/retrained_graph.pb", 'rb') f:         graph_def = tf.graphdef()         graph_def.parsefromstring(f.read())         _ = tf.import_graph_def(graph_def, name='')      pred = []     tf.session() sess:         # feed image_data input graph , first prediction         softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')          predictions = sess.run(softmax_tensor, \                                {'decodejpeg/contents:0': image_data})          pred = predictions         # sort show labels of first prediction in order of confidence         top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]          node_id in top_k:             human_string = label_lines[node_id]             score = predictions[0][node_id]             print('%s (score = %.5f)' % (human_string, score))      f.write(image + ",")     f.write(pred[0][4] + ",")     f.write(pred[0][7] + ",")     f.write(pred[0][1] + ",")     f.write(pred[0][3] + ",")     f.write(pred[0][2] + ",")     f.write(pred[0][6] + ",")     f.write(pred[0][0] + ",")     f.write(pred[0][5] + "\n")  f.close() 


when tried write first line indicates f.write("image,alb,bet,dol,lag,nof,other,shark,yft\n"), works well. after calling tensorflow in program, statement f.write(image + ",") dennied.
furthermore, use tensorflow on docker. there environment? don't understand why tensorflow doesn't allow me write files when using it. , there way me write files when using tensorflow?

notice line

with tf.gfile.fastgfile("/tf_files/retrained_graph.pb", 'rb') f: 

is overriding f in namespace f.write('blah') trying write closed file /tf_files/retrained_graph.pb

either change () some_other_f or change variable name of initial file open (or put them in 2 different namespaces)


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -