Comments (16)
When running freeze_graph.py you need to provide several arguments:
--input_graph=graph.pbtxt -> path to the saved graph
--input_checkpoint=model.ckpt -> path to the saved checkpoints
--output_graph=frozen_graph.pb -> name of the file that will contain the frozen graph
--output_node_names=out -> name of the layer that represents the output of the network (in this case the name is "out" because the last layer defined in network_structure/fruit_network.py in the conv_net method is named "out".
You can add a name to the softmax layer, in network_structure/fruit_network.py, in the build_model method and use that for the output_node_names argument. Otherwise, when you will load the frozen graph, you will need to apply softmax on the out layer in order to obtain correct predictions.
from fruit-images-dataset.
I modified to:
def freeze_graph_with_def_protos(input_graph_def='D:\Carine\Fruit-Images-Dataset\src\image_classification\fruit_models',
input_saver_def='D:\Carine\Fruit-Images-Dataset\src\image_classification\fruit_models',
input_checkpoint=checkpoint,
output_node_names=out,
restore_op_name,
filename_tensor_name,
output_graph=frozen_graph.pb,
clear_devices,
initializer_nodes,
variable_names_whitelist="",
variable_names_blacklist="",
input_meta_graph_def=model.ckpt.meta,
input_saved_model_dir='D:\Carine\Fruit-Images-Dataset\src\image_classification\fruit_models',
saved_model_tags=None,
checkpoint_version=saver_pb2.SaverDef.V2):
this is correct?
from fruit-images-dataset.
All the parameters here should be strings, so you should wrap them using single or double quotes, like this:
input_checkpoint='checkpoint'
output_node_names='out'
output_graph='frozen_graph.pb'
input_meta_graph_def='model.ckpt.meta'
Otherwise, I think it is ok.
from fruit-images-dataset.
I do like you said and I received the following error:
File "freeze_graph.py", line 55
def freeze_graph_with_def_protos(input_graph_def="D:\Carine\Fruit-Images-Dataset\src\image_classification\fruit_models",
^
SyntaxError: non-default argument follows default argument
from fruit-images-dataset.
And when I run the detect_fruit.py I receveid this error:
(machine-learning) D:\Carine\Fruit-Images-Dataset\src\image_classification\fruit_detection>python detect_fruits.py
WARNING:tensorflow:From detect_fruits.py:53: WholeFileReader.init (from tensorflow.python.ops.io_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by tf.data
. Use tf.data.Dataset.map(tf.read_file)
.
WARNING:tensorflow:From detect_fruits.py:15: string_input_producer (from tensorflow.python.training.input) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by tf.data
. Use tf.data.Dataset.from_tensor_slices(string_tensor).shuffle(tf.shape(input_tensor, out_type=tf.int64)[0]).repeat(num_epochs)
. If shuffle=False
, omit the .shuffle(...)
.
WARNING:tensorflow:From C:\Users\Carine\Anaconda3\envs\machine-learning\lib\site-packages\tensorflow\python\training\input.py:276: input_producer (from tensorflow.python.training.input) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by tf.data
. Use tf.data.Dataset.from_tensor_slices(input_tensor).shuffle(tf.shape(input_tensor, out_type=tf.int64)[0]).repeat(num_epochs)
. If shuffle=False
, omit the .shuffle(...)
.
WARNING:tensorflow:From C:\Users\Carine\Anaconda3\envs\machine-learning\lib\site-packages\tensorflow\python\training\input.py:188: limit_epochs (from tensorflow.python.training.input) is deprecated and will be removed in a future version.
Instructions for updating:
Queue-based input pipelines have been replaced by tf.data
. Use tf.data.Dataset.from_tensors(tensor).repeat(num_epochs)
.
WARNING:tensorflow:From C:\Users\Carine\Anaconda3\envs\machine-learning\lib\site-packages\tensorflow\python\training\input.py:197: QueueRunner.init (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.
Instructions for updating:
To construct input pipelines, use the tf.data
module.
WARNING:tensorflow:From C:\Users\Carine\Anaconda3\envs\machine-learning\lib\site-packages\tensorflow\python\training\input.py:197: add_queue_runner (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.
Instructions for updating:
To construct input pipelines, use the tf.data
module.
WARNING:tensorflow:From detect_fruits.py:72: start_queue_runners (from tensorflow.python.training.queue_runner_impl) is deprecated and will be removed in a future version.
Instructions for updating:
To construct input pipelines, use the tf.data
module.
from fruit-images-dataset.
For the first issue, in python, whenever you declare a method, the parameters with default values must be after all the parameters without default values. Instead of putting default values in that method, maybe you can hardcode those values when you call the method.
For the second issue, I believe you are using a version of tensorflow that is newer and does not support the methods used in that script.
from fruit-images-dataset.
Now I defined like you said:
in your code line 232 until 249
if input_saver:
input_saver_def = _parse_input_saver_proto(input_saver, input_binary)
freeze_graph_with_def_protos(
input_graph_def="D:\Carine\Fruit-Images-Dataset\src\image_classification\fruit_models",
input_saver_def="D:\Carine\Fruit-Images-Dataset\src\image_classification\fruit_models",
input_checkpoint="checkpoint",
output_node_names="out",
restore_op_name,
filename_tensor_name,
output_graph="frozen_graph.pb",
clear_devices,
initializer_nodes,
variable_names_whitelist,
variable_names_blacklist,
input_meta_graph_def="model.ckpt.meta",
input_saved_model_dir='D:\Carine\Fruit-Images-Dataset\src\image_classification\fruit_models',
saved_model_tags.replace(" ", "").split(","),
checkpoint_version=checkpoint_version)
and it keeps returning error:
File "freeze_graph.py", line 239
restore_op_name,
^
SyntaxError: positional argument follows keyword argument
Can you give me a example of how to the define this, like you did to generate your graphic?
from fruit-images-dataset.
Typically, I run the command like this
python freeze_graph.py --input_graph=graph.pbtxt --input_checkpoint=model.ckpt --output_graph=frozen_graph.pb --output_node_names=out
Alternatively, you can find in the freeze_graph.py, in run_main() method where these flags are defined.
You can set there the default value for each of the above to what you need.
from fruit-images-dataset.
I tried like you typically run:
python freeze_graph.py --input_graph=graph.pbtxt --input_checkpoint=model.ckpt --output_graph=frozen_graph.pb --output_node_names=out
python freeze_graph.py --input_graph=graph.pbtxt --input_checkpoint=model.ckpt --output_graph=frozen_graph.pb --output_node_names=out
WARNING:tensorflow:From freeze_graph.py:165: FastGFile.init (from tensorflow.python.platform.gfile) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.gfile.GFile.
Traceback (most recent call last):
File "freeze_graph.py", line 392, in
run_main()
File "freeze_graph.py", line 389, in run_main
app.run(main=my_main, argv=[sys.argv[0]] + unparsed)
File "C:\Users\Carine\Anaconda3\envs\machine-learning\lib\site-packages\tensorflow\python\platform\app.py", line 125, in run
_sys.exit(main(argv))
File "freeze_graph.py", line 388, in
my_main = lambda unused_args: main(unused_args, flags)
File "freeze_graph.py", line 282, in main
flags.saved_model_tags, checkpoint_version)
File "freeze_graph.py", line 264, in freeze_graph
checkpoint_version=checkpoint_version)
File "freeze_graph.py", line 148, in freeze_graph_with_def_protos
variable_names_blacklist=variable_names_blacklist)
File "C:\Users\Carine\Anaconda3\envs\machine-learning\lib\site-packages\tensorflow\python\framework\graph_util_impl.py", line 232, in convert_variables_to_constants
inference_graph = extract_sub_graph(input_graph_def, output_node_names)
File "C:\Users\Carine\Anaconda3\envs\machine-learning\lib\site-packages\tensorflow\python\framework\graph_util_impl.py", line 174, in extract_sub_graph
_assert_nodes_are_present(name_to_node, dest_nodes)
File "C:\Users\Carine\Anaconda3\envs\machine-learning\lib\site-packages\tensorflow\python\framework\graph_util_impl.py", line 133, in _assert_nodes_are_present
assert d in name_to_node, "%s is not in graph" % d
AssertionError: out is not in graph
it seems that out isn't recognizable.
from fruit-images-dataset.
Maybe try replacing out with out/out
It may be that the layer is defined under a namespace.
from fruit-images-dataset.
It seems that my libraries isn't compatible with the algoritm. I tried it and fixed the error, but I couldn't generate any graphics. When I run, the following message is returned:
python freeze_graph.py --input_graph=graph.pbtxt --input_checkpoint=model.ckpt --output_graph=frozen_graph.pb --output_node_names=out/out
WARNING:tensorflow:From freeze_graph.py:165: FastGFile.init (from tensorflow.python.platform.gfile) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.gfile.GFile.
Here are the environment libraries that I use:
# packages in environment at C:\Users\Carine\Anaconda3\envs\machine-learning:
absl-py 0.2.0
astor 0.6.2
blas 1.0 mkl
bleach 1.5.0
certifi 2018.4.16 py36_0
cython 0.28.3 py36hfa6e2cd_0
future 0.16.0
gast 0.2.0
grpcio 1.11.0
h5py 2.9.0
html5lib 0.9999999
icc_rt 2017.0.4 h97af966_0
intel-openmp 2018.0.3 0
iso8601 0.1.12
jpeg 9b hb83a4c4_2
Keras-Applications 1.0.7
Keras-Preprocessing 1.0.8
libpng 1.6.34 h79bbb47_0
libprotobuf 3.5.2 he0781b1_0
libtiff 4.0.9 hb8ad9f9_1
Markdown 2.6.11
mkl 2018.0.3 1
numpy 1.16.1
numpy-base 1.14.5 py36h5c71026_3
pip 10.0.1
pip 9.0.3 py36_0
protobuf 3.6.1
protobuf 3.5.2 py36h6538335_0
pyserial 3.4 py36hcb15667_0
python 3.6.5 h0c2934d_0
PyYAML 3.12
scipy 1.2.1
setuptools 39.0.1
setuptools 39.0.1 py36_0
six 1.11.0
six 1.11.0 py36_1
tensorboard 1.12.2
tensorflow 1.12.0
termcolor 1.1.0
vc 14.1 h0510ff6_3
vs2015_runtime 15.5.2 3
werkzeug 0.14.1 py36_0
Werkzeug 0.14.1
wheel 0.31.0 py36_0
wheel 0.31.0
wincertstore 0.2 py36h7fe50ca_0
zlib 1.2.11 h8395fce_2
As you see, my tensorflow library version is 1.12.0. I couldn't find the previous versions.
from fruit-images-dataset.
The file freeze_graph.py is provided with every version on tensorflow.
You can try a different version here:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py
Perhaps the documentation there will provide more clarity
from fruit-images-dataset.
Now, it's seems that works. One more question, what software do you used to open the frozen_graph.pb file?
from fruit-images-dataset.
The frozen_graph.pb is a binary file, so I never tried to open it.
It can be used in other programs with any language that supports tensorflow.
from fruit-images-dataset.
How can I access the graphic?
from fruit-images-dataset.
You can use this to load the graph:
with tf.gfile.GFile([path_to_froze_graph], 'rb') as f:
graph = tf.GraphDef()
graph.ParseFromString(f.read())
The you need to get the input and the output tensors from the graph, which can be done like this:
X = graph.get_tensor_by_name('X:0')
softmax = tf.nn.softmax(graph.get_tensor_by_name('out/out:0'))
from fruit-images-dataset.
Related Issues (20)
- Bouding box on predicted fruit HOT 1
- training file
- same problem in run HOT 10
- problem in test HOT 2
- (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape HOT 1
- Checkpoint error when freezing HOT 1
- Infrared images HOT 1
- Bad image HOT 1
- MacOS clone and run, this error occurs: OSError: Unable to open file (unable to open file: name = 'output_files/fruit-360 model/model.h5', HOT 2
- how to feed network with custom image? HOT 2
- [QUESTION] How to use the trained model in tensorflow? HOT 7
- how we can test or predict any image? HOT 3
- how to get the label HOT 1
- Training issue HOT 6
- extract_images documentation HOT 7
- Is it bug ???? HOT 9
- How to use folder test-multiple_fruits for code ? HOT 11
- Partial accuracy 0.000??? HOT 13
- Filename typo HOT 1
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 fruit-images-dataset.