lengstrom / fast-style-transfer

TensorFlow CNN for fast style transfer ⚡🖥🎨🖼
10.91k stars 2.6k forks source link

cannot run on iOS #197

Open icaruslucifer opened 5 years ago

icaruslucifer commented 5 years ago

After executing the freeze command, I get the pb file and load it into the iPhone. The following error occurs, but there is no problem with the fst_frozen.pb you gave.

error info in iOS device: Running model failed: Invalid argument: NodeDef mentions attr 'dilations' not in Op<name=Conv2D; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_HALF, DT_FLOAT, DT_DOUBLE]; attr=strides:list(int); attr=use_cudnn_on_gpu:bool,default=true; attr=padding:string,allowed=["SAME", "VALID"]; attr=data_format:string,default="NHWC",allowed=["NHWC", "NCHW"]>; NodeDef: Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/cpu:0"](ExpandDims, Variable/read). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.). [[Node: Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/cpu:0"](ExpandDims, Variable/read)]]

M-Quadra commented 5 years ago

The tensorflow provides an api to convert .pb file into .tflite file. It can run in the iPhone/Simulator.

from tensorflow.python.framework import graph_util
import tensorflow as tf

graph_def_file = "/xxxxxxxxxxx/ts-flz.pb"
input_arrays = ["img_placeholder"]
output_arrays = ["add_37"]

converter = tf.lite.TFLiteConverter.from_frozen_graph(graph_def_file, input_arrays, output_arrays)
tflite_model = converter.convert()
open("ts.tflite", "wb").write(tflite_model)