Repository navigation
Closed
Description
Hi everyone,
We are trying to load a very simple graph inside IOS that we generate and freeze with python.
Right now, we have this following error:
E Running model failed: Invalid argument:
No OpKernel was registered to support Op 'Conv2DBackpropInput' with these attrs
[[Node: convt = Conv2DBackpropInput[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true](Shape, W/read, x)]]
Here is the python script generating the model:
from tools import freeze_graph
import tensorflow as tf
print('Init session')
sess = tf.InteractiveSession()
print('Define vars and ops')
x = tf.placeholder(tf.float32, shape=[None, 600, 600, 3], name="x")
W = tf.Variable(tf.truncated_normal([3, 3, 3, 3], stddev=0.1), name="W")
convt = tf.nn.conv2d_transpose(x, W, tf.shape(x), strides=[1, 1, 1, 1], padding='SAME', name="convt")
print('Init vars')
init = tf.initialize_all_variables()
sess.run(init)
input_graph_name = "input_graph.pb"
saver = tf.train.Saver(var_list=None)
saver.save(sess, 'data/conv', global_step=None)
graph_def = sess.graph.as_graph_def()
tf.train.write_graph(graph_def, "data", input_graph_name)
input_graph_path = 'data/' + input_graph_name
input_saver_def_path = ""
input_binary = False
input_checkpoint_path = 'data/conv'
output_node_names = "convt"
restore_op_name = "save/restore_all"
filename_tensor_name = "save/Const:0"
output_graph_path = "data/frozen_convt.pb"
clear_devices = True
freeze_graph.freeze_graph(input_graph_path, input_saver_def_path,
input_binary, input_checkpoint_path,
output_node_names, restore_op_name,
filename_tensor_name, output_graph_path,
clear_devices, "")Here is the Objective-C++ interesting part:
// 2. Load the network
NSString* network_path = FilePathForResourceName(@"frozen_conv", @"pb");
PortableReadFileToProto([network_path UTF8String], &tensorflow_graph);
LOG(INFO) << "Creating session.";
tensorflow::Status s = session->Create(tensorflow_graph);
if (!s.ok()) {
LOG(ERROR) << "Could not create Tensorflow Graph: " << s;
}
// 3. Run the network
std::string input_layer = "x:0";
std::string output_layer = "convt:0";
std::vector<tensorflow::Tensor> outputs;
tensorflow::Status run_status = session->Run({{input_layer, image_tensor}},
{output_layer}, {}, &outputs);
if (!run_status.ok()) {
LOG(ERROR) << "Running model failed: " << run_status;
}We are using:
- Python 3.5.1 for the script
- The python tensorflow build is downloaded from
https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0rc0-py3-none-any.whl - The compiled tensorflow for IOS is from the master branch 2 hour ago using the script
build_all_ios.sh - We have no problem running the IOS example
- We have no problem running a one standard convolutional graph frozen with custom python script
- We checked that the file
tensorflow/core/ops/nn_ops.ccis in the generated txt files (and this is the file containing the registering of the op 'Conv2DBackpropInput')
I would be gratefull if anyone has an idea on why IOS seems to not be able to find the Conv2DBackpropInput Op ?
Reacted by Thomas
Metadata
Metadata
Assignees
Labels
No labels
Activity
petewarden commentedon Jun 17, 2016
Sorry you're hitting problems, and thanks for the very clear report!
Because most mobile use cases are focused on inference, we don't support gradient ops like Conv2DBackpropInput. In this case though, the op is actually used under the hood by conv2d_transpose(), and so isn't removed when freeze_graph strips out training operations.
As a temporary solution, you should be able to add tensorflow/core/kernels/conv_grad_ops.cc to this file and re-run build_all_ios.sh:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/makefile/tf_cc_files.txt#L77
I'll work on getting a proper fix in.
petewarden commentedon Jun 17, 2016
Never mind, the op is already listed in that file. I'll keep digging to see what's actually wrong here.
petewarden commentedon Jun 18, 2016
I wasn't able to reproduce this locally, and on a deeper look I discovered that I'd fixed this in #2936 when I regenerated the file lists from the latest Bazel build. If you get top-of-tree, conv_grad_ops.cc is included and you should no longer see this problem.
Can you confirm updating fixes this for you too?
morgangiraud commentedon Jun 20, 2016
Hi Petewarden,
Thanks a lot, it is fixed! that was fast ;)
morgangiraud commentedon Jun 20, 2016
It's me again, i've tried something else and found a new error, here is the piece of code:
here is the error:
Running model failed: Invalid argument: No OpKernel was registered to support Op 'Abs' with these attrs [[Node: Abs = Abs[T=DT_FLOAT](conv_1)]]It seems that the little part
tf.abs(conv_1))can be frozen but not imported in the mobilepetewarden commentedon Jun 22, 2016
I did a bit of digging into this, and the problem is that cwise_op_abs.cc is not included in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/makefile/tf_cc_files.txt
This is generated from the Bazel build files, so I have a proper fix in review, but in the short term you should just be able to add tensorflow/core/kernels/cwise_op_abs.cc to that file locally, and re-run compile_ios_tensorflow.sh.
morgangiraud commentedon Jun 22, 2016
Yes, thanks! (it's working)
Do you know why some files could be missing from the bazel generated list ?
petewarden commentedon Jun 22, 2016
It's an error on our end, we manually pick the ops that we want to include and it appears that abs was excluded, probably by accident. I've added it back in internally, and once that goes through I'll regenerate the tf_cc_files.txt.
StephenOman commentedon Jun 22, 2016
Given that the graph must be built in Python first, it might be useful to have a utility to parse a given graph definition and generate a list of the ops used in that graph. Then it would be possible to have a core lib to do the basics and a custom lib containing only the ops needed to run the graph on a mobile.
petewarden commentedon Jun 22, 2016
We do actually have something like that running internally, to help us shrink the binary footprint. It relies on some features of our internal build system though, so we'll need to do a little work to get it into the public repo. It's something we're hoping to get done though.
I'll close this bug for now, since it sounds like the original issue is resolved?
morgangiraud commentedon Jun 22, 2016
Yes, it's resolved on my side.
The graph parser would be awesome for anybody who wants to avoid cherry picking deps. Looking forward to see it appear here!
Thanks again for your speed.
mdsujan91 commentedon Aug 24, 2017
I have followed the steps from Tensorflow For Poets (link : https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/#0 ) to train my own dataset using tensorflow, and getting very good prediction result.This provides me retrained.py, label_images.py, retrained_graph.pb, retrained_labels.txt files.So i have my own model graph and label file.
After that i have downloaded Tensorflow Example Project for iOS from github. The project runs successfully in iOS platform. but when i am using my own retrained_graph.pb, retrained_labels.txt file on behalf of examples model and label file , i am getting error as following -
Errors :
Could not create TensorFlow Graph: Invalid argument: No OpKernel was registered to support Op 'DecodeJpeg' with these attrs. Registered devices: [CPU], Registered kernels:
[[Node: DecodeJpeg = DecodeJpegacceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false]]
and ,
Couldn't load model: Invalid argument: No OpKernel was registered to support Op 'DecodeJpeg' with these attrs. Registered devices: [CPU], Registered kernels:
[[Node: DecodeJpeg = DecodeJpegacceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false]]
Can you help me please ? I have been searching a long time for it . @petewarden .
thanks