{"action":"closed","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/9678","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/9678/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/9678/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/9678/events","html_url":"https://github.com/tensorflow/tensorflow/issues/9678","id":226481182,"number":9678,"title":"Convert magenta/image_stylization model on Android, but doesn't work","user":{"login":"haikuoyao","id":8957771,"avatar_url":"https://avatars3.githubusercontent.com/u/8957771?v=3","gravatar_id":"","url":"https://api.github.com/users/haikuoyao","html_url":"https://github.com/haikuoyao","followers_url":"https://api.github.com/users/haikuoyao/followers","following_url":"https://api.github.com/users/haikuoyao/following{/other_user}","gists_url":"https://api.github.com/users/haikuoyao/gists{/gist_id}","starred_url":"https://api.github.com/users/haikuoyao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haikuoyao/subscriptions","organizations_url":"https://api.github.com/users/haikuoyao/orgs","repos_url":"https://api.github.com/users/haikuoyao/repos","events_url":"https://api.github.com/users/haikuoyao/events{/privacy}","received_events_url":"https://api.github.com/users/haikuoyao/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"andrewharp","id":3376817,"avatar_url":"https://avatars2.githubusercontent.com/u/3376817?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewharp","html_url":"https://github.com/andrewharp","followers_url":"https://api.github.com/users/andrewharp/followers","following_url":"https://api.github.com/users/andrewharp/following{/other_user}","gists_url":"https://api.github.com/users/andrewharp/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewharp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewharp/subscriptions","organizations_url":"https://api.github.com/users/andrewharp/orgs","repos_url":"https://api.github.com/users/andrewharp/repos","events_url":"https://api.github.com/users/andrewharp/events{/privacy}","received_events_url":"https://api.github.com/users/andrewharp/received_events","type":"User","site_admin":false},"assignees":[{"login":"andrewharp","id":3376817,"avatar_url":"https://avatars2.githubusercontent.com/u/3376817?v=3","gravatar_id":"","url":"https://api.github.com/users/andrewharp","html_url":"https://github.com/andrewharp","followers_url":"https://api.github.com/users/andrewharp/followers","following_url":"https://api.github.com/users/andrewharp/following{/other_user}","gists_url":"https://api.github.com/users/andrewharp/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewharp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewharp/subscriptions","organizations_url":"https://api.github.com/users/andrewharp/orgs","repos_url":"https://api.github.com/users/andrewharp/repos","events_url":"https://api.github.com/users/andrewharp/events{/privacy}","received_events_url":"https://api.github.com/users/andrewharp/received_events","type":"User","site_admin":false}],"milestone":null,"comments":8,"created_at":"2017-05-05T05:59:21Z","updated_at":"2017-05-08T09:50:19Z","closed_at":"2017-05-08T09:50:19Z","body":"I try [TF Stylize on Android](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android) and it works perfectly.  Also I find the training code of this [image stylization model](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/StylizeActivity.java#L70). Its name is [magenta/image_stylization](https://github.com/tensorflow/magenta/tree/master/magenta/models/image_stylization) and provides two pre-trained models: [Monet](http://download.magenta.tensorflow.org/models/multistyle-pastiche-generator-monet.ckpt) and [Varied](http://download.magenta.tensorflow.org/models/multistyle-pastiche-generator-varied.ckpt). The first one had 10 styles and second has 32.\r\n\r\nSo my idea it to use them to replace [image stylization model](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/StylizeActivity.java#L74).\r\n\r\nHere is what I did.\r\n1 Save `*.ckpt` model to `*.pb`  \r\nSave graph  \r\n```\r\nimport tensorflow as tf\r\nimport model\r\nimport ops\r\n\r\nnum_styles = 10\r\nimgWidth = 216\r\nimgHeight = 216\r\nchannel = 3\r\ncheckpoint = \"models/multistyle-pastiche-generator-monet.ckpt\"\r\n\r\ninputImage = tf.placeholder(tf.float32,shape=[None,imgWidth,imgHeight,channel],name=\"input\")\r\nstyles = tf.placeholder(tf.float32,shape=[num_styles],name=\"style_num\")\r\n\r\nwith tf.name_scope(\"\"):\r\n    transform = model.transform(inputImage,\r\n                            normalizer_fn=ops.weighted_instance_norm,\r\n                            normalizer_params={\r\n                                # 'weights': tf.constant(mixture),\r\n                                'weights' : styles,\r\n                                'num_categories': num_styles,\r\n                                'center': True,\r\n                                'scale': True})\r\n\r\nmodel_saver = tf.train.Saver(tf.global_variables())\r\n\r\nwith tf.Session() as sess:\r\n    tf.train.write_graph(sess.graph_def, \"models/\", \"input.pb\")\r\n```\r\n\r\nFreeze Graph\r\n```\r\nbazel-bin/tensorflow/python/tools/freeze_graph \\\r\n --input_graph=input.pb --input_checkpoint=multistyle-pastiche-generator-monet.ckpt \\\r\n --output_node_names=transformer/expand/conv3/conv/Sigmoid --input_binary=False \\\r\n --output_graph=frozen.pb\r\n```\r\n\r\nInference\r\n```\r\nbazel-bin/tensorflow/python/tools/optimize_for_inference \\\r\n--input=frozen.pb --output=inference.pb \\\r\n--input_names=input --output_names=transformer/expand/conv3/conv/Sigmoid \\\r\n--frozen_graph=True\r\n```\r\n\r\nQuantize\r\n```\r\nbazel-bin/tensorflow/tools/quantization/quantize_graph \\\r\n--input=inference.pb \\\r\n--output=quantize_graph.pb \\\r\n--output_node_names=transformer/expand/conv3/conv/Sigmoid  \\\r\n--mode=weights_rounded\r\n```\r\n\r\n2 Replace model with `quantize_graph.pb`\r\n\r\nThen I got an issue.\r\nI can see there are 10 styles and they display on the screen :\r\n![screenshot_2017-05-05-14-10-21](https://cloud.githubusercontent.com/assets/8957771/25735287/d52a1700-319c-11e7-86e1-642ad06539e7.jpg)\r\n\r\nHowever, the image is not transformed.  There's no style on the image. It's the just original image.\r\nTF version is 1.1.0. Android is 6.0.1\r\n\r\nAnyone met the same issue or anyone knew how exactly to convert these two models  and use on mobile?\r\n\r\n"}}
{"actor":{"display_login":"haikuoyao"}}