<p dir="auto">hi, everyone,</p>
<p dir="auto">We are trying to load a pb file inside Android. The pb file is generated with python 2.7.0 and Tensorflow 1.0.1.   We have this following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="exception triggered java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'FloorMod' with these attrs.  Registered devices: [CPU], Registered kernels:
                                                                    &lt;no registered kernels&gt;                                                                  
                                                                  	 [[Node: WCon/atrous_conv2d/mod = FloorMod[T=DT_INT32, _device=&quot;/device:CPU:0&quot;](WCon/atrous_conv2d/add_1, WCon/atrous_conv2d/mod/y)]]"><pre class="notranslate"><code class="notranslate">exception triggered java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'FloorMod' with these attrs.  Registered devices: [CPU], Registered kernels:
                                                                    &lt;no registered kernels&gt;                                                                  
                                                                  	 [[Node: WCon/atrous_conv2d/mod = FloorMod[T=DT_INT32, _device="/device:CPU:0"](WCon/atrous_conv2d/add_1, WCon/atrous_conv2d/mod/y)]]
</code></pre></div>
<p dir="auto">The network definition is using tf.nn.atrous_conv2d(i, k, dilation_rate, padding=padding)</p>
<p dir="auto">And our freezing graph code is also pretty standard.</p>
<p dir="auto">We have no problem running this pb files for inference with python under Tensorflow 1.0.1</p>
<p dir="auto">But when running on Android phone, we will see the above error, I tried several nightly build TF Android Inference library including the latest from <a href="https://ci.tensorflow.org/view/Nightly/job/nightly-android/" rel="nofollow">https://ci.tensorflow.org/view/Nightly/job/nightly-android/</a>    The result is the same</p>
<p dir="auto">My feeling is that the inference on Tensorflow python and Tensorflow Android has a huge gap?</p>
<p dir="auto">Thanks for any ideas!</p>
<p dir="auto">hi , all! I have tried to load the model inside iOS that I generated from python.<br>
and right now, I have the following problem:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Error adding graph to session:
No OpKernel was registered to support Op 'Less' with these attrs.  
Registered devices: [CPU],     Registered kernels: device='CPU';
 T in [DT_FLOAT]  [[Node: rnn/while/Less = Less[T=DT_INT32](rnn/while/Merge, rnn/while/Less/Enter)]]"><pre class="notranslate"><code class="notranslate">Error adding graph to session:
No OpKernel was registered to support Op 'Less' with these attrs.  
Registered devices: [CPU],     Registered kernels: device='CPU';
 T in [DT_FLOAT]  [[Node: rnn/while/Less = Less[T=DT_INT32](rnn/while/Merge, rnn/while/Less/Enter)]]
</code></pre></div>
<p dir="auto">Here is the python script generating the model:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="def add_dynamic_rnn_layer(inputs, out_size, batch_size, Xt_size, time_step, num_layer=1, keep_prob=0.5):
    # Reshaping to (batch_size, time_step, Xt_size)
    inputs = tf.reshape(inputs, [-1, time_step, Xt_size])
    cell = tf.contrib.rnn.MultiRNNCell([tf.contrib.rnn.DropoutWrapper(tf.contrib.rnn.LSTMCell(out_size, state_is_tuple=True,forget_bias=1.0),
                                                input_keep_prob=keep_prob)
                             for _ in range(num_layer)])
    cell =  tf.contrib.rnn.DropoutWrapper(cell,  input_keep_prob=keep_prob)
    sequence_length = np.zeros([batch_size], dtype=int)
    sequence_length += time_step
    init_state = cell.zero_state(batch_size, tf.float32)
    rnn_outputs, final_state = tf.nn.dynamic_rnn(cell, inputs, initial_state=init_state, dtype=tf.float32, time_major=False,sequence_length=sequence_length)
    return tf.transpose(rnn_outputs, [1, 0, 2])[-1]


with tf.Session() as sess:
  # ...... other model code....
   add_dynamic_rnn_layer()
   output_graph_def = convert_variables_to_constants(sess, sess.graph_def,
                                                          output_node_names=['predictions', 'prediction_labels'])
   with tf.gfile.FastGFile('inference'+str(time.time())+'.pb', mode='wb') as f:
            f.write(output_graph_def.SerializeToString())"><pre class="notranslate"><code class="notranslate">def add_dynamic_rnn_layer(inputs, out_size, batch_size, Xt_size, time_step, num_layer=1, keep_prob=0.5):
    # Reshaping to (batch_size, time_step, Xt_size)
    inputs = tf.reshape(inputs, [-1, time_step, Xt_size])
    cell = tf.contrib.rnn.MultiRNNCell([tf.contrib.rnn.DropoutWrapper(tf.contrib.rnn.LSTMCell(out_size, state_is_tuple=True,forget_bias=1.0),
                                                input_keep_prob=keep_prob)
                             for _ in range(num_layer)])
    cell =  tf.contrib.rnn.DropoutWrapper(cell,  input_keep_prob=keep_prob)
    sequence_length = np.zeros([batch_size], dtype=int)
    sequence_length += time_step
    init_state = cell.zero_state(batch_size, tf.float32)
    rnn_outputs, final_state = tf.nn.dynamic_rnn(cell, inputs, initial_state=init_state, dtype=tf.float32, time_major=False,sequence_length=sequence_length)
    return tf.transpose(rnn_outputs, [1, 0, 2])[-1]


with tf.Session() as sess:
  # ...... other model code....
   add_dynamic_rnn_layer()
   output_graph_def = convert_variables_to_constants(sess, sess.graph_def,
                                                          output_node_names=['predictions', 'prediction_labels'])
   with tf.gfile.FastGFile('inference'+str(time.time())+'.pb', mode='wb') as f:
            f.write(output_graph_def.SerializeToString())
</code></pre></div>
<p dir="auto">Here is the objective-C++ code loading the model and creating the session:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
    NSString *path = [[NSBundle mainBundle] pathForResource:pbname ofType:@&quot;pb&quot;];
    if (!path) return false;
    auto status = ReadBinaryProto(tensorflow::Env::Default(), path.fileSystemRepresentation, &amp;graph);
    if (!status.ok()) {
        NSLog(@&quot;Error reading graph: %s&quot;, status.error_message().c_str());
        return NO;
    }
    
    // This prints out the names of the nodes in the graph.
    auto nodeCount = graph.node_size();
    NSLog(@&quot;Node count: %d&quot;, nodeCount);
    for (auto i = 0; i &lt; nodeCount; ++i) {
        auto node = graph.node(i);
        NSLog(@&quot;Node %d: %s '%s'&quot;, i, node.op().c_str(), node.name().c_str());
    }
    
    tensorflow::SessionOptions options;
    auto status = tensorflow::NewSession(options, &amp;session);
    if (!status.ok()) {
        NSLog(@&quot;Error creating session: %s&quot;, status.error_message().c_str());
        return NO;
    }
    
    status = session-&gt;Create(graph);
    if (!status.ok()) {
        NSLog(@&quot;Error adding graph to session: %s&quot;, status.error_message().c_str());
    }  
}"><pre class="notranslate"><code class="notranslate">{
    NSString *path = [[NSBundle mainBundle] pathForResource:pbname ofType:@"pb"];
    if (!path) return false;
    auto status = ReadBinaryProto(tensorflow::Env::Default(), path.fileSystemRepresentation, &amp;graph);
    if (!status.ok()) {
        NSLog(@"Error reading graph: %s", status.error_message().c_str());
        return NO;
    }
    
    // This prints out the names of the nodes in the graph.
    auto nodeCount = graph.node_size();
    NSLog(@"Node count: %d", nodeCount);
    for (auto i = 0; i &lt; nodeCount; ++i) {
        auto node = graph.node(i);
        NSLog(@"Node %d: %s '%s'", i, node.op().c_str(), node.name().c_str());
    }
    
    tensorflow::SessionOptions options;
    auto status = tensorflow::NewSession(options, &amp;session);
    if (!status.ok()) {
        NSLog(@"Error creating session: %s", status.error_message().c_str());
        return NO;
    }
    
    status = session-&gt;Create(graph);
    if (!status.ok()) {
        NSLog(@"Error adding graph to session: %s", status.error_message().c_str());
    }  
}
</code></pre></div>
<p dir="auto">the environment as follows:</p>
<ul dir="auto">
<li>python 3.5 / xcode 8.3.2</li>
<li>the iOS based on mac os x 10.12  / the tensorflow version: r1.1</li>
<li>the model generated based on Ubuntu / tensorflow is r1.1 gpu version</li>
</ul>
<p dir="auto">I have done things as follow:</p>
<ul dir="auto">
<li>build_all_ios.sh
<ul dir="auto">
<li>success,don't have any warning and error.</li>
</ul>
</li>
<li>set the xcode build settings
<ul dir="auto">
<li>header search path</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/Users/jw/Desktop/tensorflow  non-recursive
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/downloads non-recursive
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/downloads/protobuf/src non-recursive
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/downloads/eigen non-recursive
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/gen/proto non-recursive"><pre class="notranslate"><code class="notranslate">/Users/jw/Desktop/tensorflow  non-recursive
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/downloads non-recursive
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/downloads/protobuf/src non-recursive
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/downloads/eigen non-recursive
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/gen/proto non-recursive
</code></pre></div>
<ul dir="auto">
<li>other linker flags:</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib/libprotobuf.a
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib/libprotobuf-lite.a
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a
-force_load"><pre class="notranslate"><code class="notranslate">/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib/libprotobuf.a
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib/libprotobuf-lite.a
/Users/jw/Desktop/tensorflow/tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a
-force_load
</code></pre></div>
</li>
<li>check the tf_op_files.txt
<ul dir="auto">
<li>have the line <code class="notranslate"> tensorflow/core/kernels/cwise_op_less.cc</code></li>
</ul>
</li>
<li>using the tensorflow version v1.0
<ul dir="auto">
<li>have the same error</li>
</ul>
</li>
</ul>
<p dir="auto">I would be gratefull if anyone has an idea on why iOS seems to not be able to find the less Op ?<br>
Or the solution to the question : No OpKernel was registered to support Op 'Less' with these attrs.</p>