I got this error when I ran the notebook on jupyter.
log_dir = "inception_log"
if not os.path.exists(log_dir):
os.makedirs(log_dir)
#classify_image_graph_def.pd是google訓練好的模型
inception_graph_def_file = os.path.join("inception_model","classify_image_graph_def.pd")
with tf.Session() as sess:
#建一張圖存放google訓練好的模型
with tf.gfile.FastGFile(inception_graph_def_file,'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def,name = "")
#保存圖的結構
print("start")
writer = tf.summary.FileWriter("inception_log",sess.graph)
writer.close()
print("end")
I'm not sure is this error cause I couldn't write a file in my folder.
I tried to google this error but didn't find the way to solve this error.
Thanks.
Related
I am using an example program from github in which it has imported pickle module at the beginning. But when it is trying to open file via pickle. Its giving an error
I can't understand the reason of it.
file = open('df_train_train', 'rb')
df_train_train = pickle.load(file)
file.close()
file = open('df_train_test', 'rb')
df_train_test = pickle.load(file)
file.close()
screen shot of my result.
You need to dump it first, then load it. Try the following:
# dump df_train_train
file = open('df_train_train', 'wb')
pickle.dump(df_train_train, file)
file.close()
Then
file = open('df_train_train', 'rb')
df_train_train = pickle.load(file)
file.close()
I am trying to create a small game for fun, and I want to save and load previous run scores. I started a test file to mess around and try to figure out how pickling works. I have a pickle file with a small set of number. How do I add numbers to the pickle file and save it for the next run.
Currently I have it like this:
new_score = 9
filename = "scoreTest.pk"
outfile = open(filename,'wb')
infile = open(filename,'rb')
with infile as f:
scores = pickle.load(f)
scores.add(new_score)
pickle.dump(scores, outfile)
When I run it like this I get this error:
EOFError: Ran out of input
If someone could please tell me what is wrong and how to do it correctly that would be great. Apologies for any un-optimal code, I'm new to code.
You are trying to juggle a reader and writer on the same file at the same time. The open(filename, 'wb') of the write deletes whatever happened to be in the file so there is no data for the reader. You should only open the file when you really need to use it. And its better to write to a temporary file and rename it. If something goes wrong you haven't lost your data.
import pickle
import os
new_score = 9
filename = "scoreTest.pk"
tmp_filename = "scoreTest.tmp"
try:
with open(filename, 'rb') as infile:
scores = pickle.load(f)
except (IOError, EOFError) as e:
scores = default # whatever that is
scores.add(new_score)
with open(tmp_filename, 'wb') as outfile:
pickle.dump(scores, outfile)
os.rename(tmp_filename, filename)
I tried to solve the problem by writing the following code but no luck.
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(path, 'r') as fid:
serialized_graph = fid.read()
Then I saw an error like this
NameError: name 'path' is not defined
How can I fix it?
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
I just guess because the infomation you give is not enough. Just try it if your tensorflow has version issue.
Try:
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.compat.v1.GraphDef()
Go to environment variables and add it to PATH.
I'm trying to use Tensorflow's Object Detection API with a pre-trained model. I'm loading the model with this:
model_name='fish_inception_v2_graph2'
PATH_TO_CKPT='models/research/object_detection/'+model_name+'/frozen_inference_graph.pb'
### Load a (frozen) Tensorflow model into memory.
detection_model = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.compat.v1.GraphDef()
with tf.compat.v2.io.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
That seems to work fine but then the API has a section to "Check the model's input signature, it expects a batch of 3-color images of type uint8":
print(detection_model.signatures['serving_default'].inputs)
When I run that is when I get the error "AttributeError: 'Graph' object has no attribute 'signatures'".
Anyone know how to fix this? Thank you!
In the path to the checkpoint just mention the model.ckpt-10000 or something of that sort. You are providing a .pb file and hence the error.
I'm trying to read a text file via win python 3, the strange thing is that I am not getting any error nor any output.
f = open ('C:\\Users\\test\\Desktop\\test.txt','r')
data = f.read()
print data
f.close()
print is a function in py3
f = open ('C:\\Users\\test\\Desktop\\test.txt','r')
data = f.read()
print(data)
f.close()
Though, it should have give you invalid syntax error.