Skip to content

IOS - No OpKernel was registered to support Op 'Conv2DBackpropInput' with these attrs #2929

Closed

Description

@morgangiraud

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.cc is 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 ?

Activity

  1. petewarden commented on Jun 17, 2016

    @petewarden
    Contributor

    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.

  2. petewarden commented on Jun 17, 2016

    @petewarden
    Contributor

    Never mind, the op is already listed in that file. I'll keep digging to see what's actually wrong here.

  3. petewarden commented on Jun 18, 2016

    @petewarden
    Contributor

    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?

  4. morgangiraud commented on Jun 20, 2016

    @morgangiraud
    Author

    Hi Petewarden,

    Thanks a lot, it is fixed! that was fast ;)

  5. morgangiraud commented on Jun 20, 2016

    @morgangiraud
    Author

    It's me again, i've tried something else and found a new error, here is the piece of code:

    W_1 = tf.Variable(tf.truncated_normal([3, 3, 3, 16], stddev=0.1), name="W_1")
    b_1 = tf.constant(0.1, shape=[16], name="b_1")
    conv_1 = tf.nn.conv2d(x, W_1, strides=[1, 2, 2, 1], padding='SAME', name="conv_1")
    # PRelu
    pos = tf.nn.relu(conv_1)
    neg = -0.1 * (conv_1 - tf.abs(conv_1)) * 0.5
    h_conv1 = pos + neg

    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 mobile

  6. petewarden commented on Jun 22, 2016

    @petewarden
    Contributor

    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.

  7. morgangiraud commented on Jun 22, 2016

    @morgangiraud
    Author

    Yes, thanks! (it's working)

    Do you know why some files could be missing from the bazel generated list ?

  8. petewarden commented on Jun 22, 2016

    @petewarden
    Contributor

    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.

  9. StephenOman commented on Jun 22, 2016

    @StephenOman

    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.

  10. petewarden commented on Jun 22, 2016

    @petewarden
    Contributor

    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?

  11. morgangiraud commented on Jun 22, 2016

    @morgangiraud
    Author

    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.

  12. mdsujan91 commented on Aug 24, 2017

    @mdsujan91

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions