Comments (4)
Short answer: You can but it is difficult, it is easier to add this line when a training is finished:
tf.train.write_graph(sess.graph_def, "/tmp/load", "test.pb", False) #proto
Example from: tensorflow/tensorflow#616
import tensorflow as tf
import os
import numpy as np
from tensorflow.python.platform import gfile
data = np.arange(10,dtype=np.int32)
with tf.Session() as sess:
print("# build graph and run")
input1= tf.placeholder(tf.int32, [10], name="input")
output1= tf.add(input1, tf.constant(100,dtype=tf.int32), name="output") # data depends on the input data
saved_result= tf.Variable(data, name="saved_result")
do_save=tf.assign(saved_result,output1)
tf.initialize_all_variables()
os.system("rm -rf /tmp/load")
tf.train.write_graph(sess.graph_def, "/tmp/load", "test.pb", False) #proto
# now set the data:
result,_=sess.run([output1,do_save], {input1: data}) # calculate output1 and assign to 'saved_result'
saver = tf.train.Saver(tf.all_variables())
saver.save(sess,"checkpoint.data")
with tf.Session() as persisted_sess:
print("load graph")
with gfile.FastGFile("/tmp/load/test.pb",'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
persisted_sess.graph.as_default()
tf.import_graph_def(graph_def, name='')
print("map variables")
persisted_result = persisted_sess.graph.get_tensor_by_name("saved_result:0")
tf.add_to_collection(tf.GraphKeys.VARIABLES,persisted_result)
try:
saver = tf.train.Saver(tf.all_variables()) # 'Saver' misnomer! Better: Persister!
except:pass
print("load data")
saver.restore(persisted_sess, "checkpoint.data") # now OK
print(persisted_result.eval())
print("DONE")
It might be possible to go straight from meta and checkpoint to graphdef using some of the code from this stackoverflow topic: https://stackoverflow.com/questions/33759623/tensorflow-how-to-save-restore-a-model
But this is something you will need to figure out yourself.
from squeezedet.
"False" must be setted? If I use tf.train.write_graph(sess.graph_def, "/tmp/load", "test.pb"), is it right?
from squeezedet.
That boolean determines whether or not to write the file as binary or as text https://www.tensorflow.org/api_docs/python/tf/train/write_graph
It has a default value (True) so you don't need to set it.
from squeezedet.
Found this blog post.
It might be pretty straight forward after all, worth looking into. I still recommend outputting the .pb file directly from training but this should work as-well.
from squeezedet.
Related Issues (20)
- Gpu occupancy rate
- where is base_model_config.py?
- Will random initialization parameters have no precision? HOT 1
- Fine-tune SqueezeDet from sparse labels
- How to do hard negative mining HOT 1
- Publish frozen model? HOT 3
- Problem converting to TFLite HOT 3
- low GPU usage
- 8-bit weights
- Deploying squeezeDet on mobile HOT 3
- How to convert checkpoint of squeezedet to frozen graph for tflite conversion?! HOT 1
- Image resolution problem
- How to run demo.py using train.py checkpoint model HOT 1
- Train with different size and Inference with different size.
- Fine tuning with the model
- Train error and Eval error
- Using negative samples for training.
- print weights per layer during training
- Performance issue in src/eval.py (by P3) HOT 1
- The loss plateaus after 100 Epoch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from squeezedet.