Ask Your Question
0

Opencv load tensorflow Style Transfer Model Failed

asked 2018-11-30 04:56:52 -0600

VonChenpPlus gravatar image

Hello Guys, I Use lengstrom's fast-style-transfer Train one Model, and success to use this model to style image by python, like this python evaluate.py --checkpoint path/to/style/model.ckpt \ --in-path dir/of/test/imgs/ \ --out-path dir/for/results/

now, i want to use opencv load this model,then transform model to pb file.

I use follow code to read pb file: cv::dnn::Net cvMaskObjectNet = cv::dnn::readNetFromTensorflow("D:/opt_graph.pb"); but, cv::dnn::readNetFromTensorflow read this model failed(throw exception).

this link is my trained style model:

Could anyone help me? https://drive.google.com/open?id=1ZcK...

edit retag flag offensive close merge delete

Comments

Well somone has the same problem like - external model with opencv fails. This time its yolo and not tensorflow but same problem.

I left some comment on this and how it can be solved in general , maybe it helps. http://answers.opencv.org/question/20...

holger gravatar imageholger ( 2018-11-30 08:02:05 -0600 )edit

@VonChenpPlus, you need to convert your checkpoint to .pb file first. Try to find a guide of how to do it in TensorFlow.

dkurt gravatar imagedkurt ( 2018-12-01 08:48:49 -0600 )edit

@dkurt, i'm convert checkpoint to pb file already.

VonChenpPlus gravatar imageVonChenpPlus ( 2018-12-01 10:15:14 -0600 )edit

@holger ok,thanks. i will try thiese.

VonChenpPlus gravatar imageVonChenpPlus ( 2018-12-01 10:16:01 -0600 )edit

@VonChenpPlus, please help us solving you problem. Add it to your drive.

dkurt gravatar imagedkurt ( 2018-12-01 11:18:19 -0600 )edit

@dkurt,i upload pb file to my https://drive.google.com/open?id=1HHU... please look at it, thanks.

VonChenpPlus gravatar imageVonChenpPlus ( 2018-12-02 19:24:19 -0600 )edit

hello,@dkurt, any update?

VonChenpPlus gravatar imageVonChenpPlus ( 2018-12-03 21:01:50 -0600 )edit

2 answers

Sort by » oldest newest most voted
0

answered 2018-12-06 19:22:58 -0600

VonChenpPlus gravatar image

Hello @dkurt, Thanks your reply. I Test the model use python command like this: python evaluate.py --checkpoint wave.ckpt --in-path inputs/ --out-path outputs/

the output message as follow: Tensor(“add_37:0”, shape=(20, 720, 884, 3), dtype=float32, device=/device:GPU:0)

I think the output name is add_37.

edit flag offensive delete link more
0

answered 2018-12-06 01:33:06 -0600

dkurt gravatar image

@VonChenpPlus, As you may know, there are two stages for deep learning models: training and testing. Attached .pb graph is in training phase that means it has a lot of extra nodes. In example, loss function

image description

and nobody know what else:

image description

To solve it, you may try to turn this model to testing phase by TensorFlow tools:

graph = 'output_graph.pb'
with tf.gfile.FastGFile(graph) as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())

    inp_nodes = ['X_content']
    out_nodes = ['']
    graph_def = optimize_for_inference_lib.optimize_for_inference(graph_def, inp_nodes, out_nodes, tf.float32.as_datatype_enum)

But looking onto this graph I have no idea what the name of output node. May be you can help?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-11-30 04:56:52 -0600

Seen: 549 times

Last updated: Dec 06 '18