Issue 1:
System information (version)

OpenCV => 4.0.0

Operating System / Platform => Ubuntu 18.4

Compiler => gcc 7.2

Detailed description

I'm having problems trying to load a model in pb or pb&pbtxt using readNetFromTensorflow.

The model is a pretrained resnext network trained and exported using tflearn with code:

net = tflearn.input_data(shape=[None, 49, 49, 3], img_prep, img_aug)
net = tflearn.conv_2d(net, 16, 3, regularizer='L2', weight_decay=0.0001)
...
net = tflearn.fully_connected(net, 11, activation='softmax')

model = tflearn.DNN(net)
model.load("checkpoints/meta-data/model_resnext-96000")

init_op = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init_op)

tf.train.write_graph(sess.graph_def, "/tmp/my-model", 'graph.pbtxt', as_text=True)
tf.train.write_graph(sess.graph, "/tmp/my-model", 'graph.pb', as_text=False)

The model works perfectly fine using tflearn api (model.predict()).

After that I attempted to freeze the graph and optimize it for inference:

1.Freezing the graph

python -m tensorflow.python.tools.freeze_graph --input_binary --input_graph graph.pb --output_graph frozen_graph.pb --input_checkpoint ~/datasets/TrainedNetworksTfLearn/Expression/model-resnext-no-train-ops --output_node_names FullyConnected/Softmax

2 Optimizing the graph for inference with two different ways

a).using tensorflow.python.tools.optimize_for_inference:

python -m tensorflow.python.tools.optimize_for_inference --input frozen_graph_with_freeze_graph_tool.pb --output frozen_interference_graph_opt.pb --frozen_graph True --input_names InputData/X --output_names FullyConnected/Softmax

b). using snippet provided by @dkurt

import tensorflow as tf
from tensorflow.tools.graph_transforms import TransformGraph
from tensorflow.python.tools import optimize_for_inference_lib

graph = 'graph.pb'
with tf.gfile.FastGFile(graph, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.summary.FileWriter('logs', graph_def)

inp_node = 'InputData/X'
out_node = 'FullyConnected/Softmax'
graph_def = optimize_for_inference_lib.optimize_for_inference(graph_def, [inp_node], [out_node],
tf.float32.as_datatype_enum)
graph_def = TransformGraph(graph_def, [inp_node], [out_node], ["sort_by_execution_order"])

tf.train.write_graph(graph_def, "/tmp/my-model", 'graph_opt.pbtxt', as_text=True)
tf.train.write_graph(graph_def, "/tmp/my-model", 'graph_opt.pb', as_text=False)

This completes successfully:

WARNING:tensorflow:From optimize_graph.py:6: FastGFile.init (from tensorflow.python.platform.gfile) is deprecated and will be removed in a future version.

Instructions for updating:

Use tf.gfile.GFile.

WARNING:tensorflow:Passing a GraphDef to the SummaryWriter is deprecated. Pass a Graph object instead, such as sess.graph.

WARNING:tensorflow:From //.local/lib/python3.6/site-packages/tensorflow/python/tools/strip_unused_lib.py:86: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.

Instructions for updating:

Use tf.compat.v1.graph_util.extract_sub_graph

WARNING:tensorflow:From //.local/lib/python3.6/site-packages/tensorflow/python/tools/optimize_for_inference_lib.py:113: remove_training_nodes (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.

Instructions for updating:

Use tf.compat.v1.graph_util.remove_training_nodes

2019-03-15 17:32:23.963903: I tensorflow/tools/graph_transforms/transform_graph.cc:317] Applying sort_by_execution_order

After these steps i get the following errors:

this->net = cv::dnn::readNetFromTensorflow("graph_opt.pb", "graph_opt.pbtxt");

tf_importer.cpp:616: error: (-215:Assertion failed) const_layers.insert(std::make_pair(name, li)).second in function 'addConstNodes'

this->net = cv::dnn::readNetFromTensorflow("graph_opt.pb");

tf_graph_simplifier.cpp:773: error: (-2:Unspecified error) Tensor's data type is not supported in function 'getTensorContent'

Steps to reproduce

Issue 2:
System information (version)

OpenCV => 3.4

Operating System / Platform => Mac OS X ( Related to JS version of Open CV)

JS has been built using branch 3.4

Detailed description

Was trying to use orb.detect() function in JS but it throws errors:

Cannot call Feature2D.detect due to unbound types: NSt3__26vectorIN2cv8KeyPointENS_9allocatorIS2_EEEE↵ at UnboundTypeError

Steps to reproduce

Use the steps as mentioned in the tutorial to include JS file in your code

and then when opencv has been loaded into Browser memory run this code

console.log(cv);
let imgMat = cv.imread(imgElement);
let orb = new cv.ORB();
let kp = orb.detect(imgMat,"");
console.log("kp",kp);
// let result = orb.compute(imgMat,kp);
// console.log("result",result);
mat.delete();