mdietrichstein / tensorflow-open_nsfw

Tensorflow Implementation of Yahoo's Open NSFW Model
Other
430 stars 136 forks source link

Converting to tflite #14

Closed restys closed 5 years ago

restys commented 6 years ago

Been struggling to convert the model to tflite. I've used export_savedmodel.py to freeze it and then try to following to convert: toco \ --graph_def_file=frozen_open_nsfw.pb --output_file=optimized_graph.tflite \ --output_format=TFLITE \ --input_arrays=input \ --output_arrays=predictions \

This results the following errors: 2018-08-16 01:54:39.677658: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: TensorArrayV3 2018-08-16 01:54:39.677802: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: TensorArrayScatterV3 2018-08-16 01:54:39.677834: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: TensorArrayV3 2018-08-16 01:54:39.677847: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Enter

Any ideas?

Thanks a lot

hristorv commented 6 years ago

Hello, Did you manage to convert it to TFlite ?

restys commented 6 years ago

Nop ):

mmgweiyang commented 5 years ago

I have the same problem when using the command line. But i generated the tflite using python API. by modifying the export_savedmodel.py.

with tf.Session() as sess:
    model.build(weights_path=weights_path,input_type=InputType.TENSOR)

    sess.run(tf.global_variables_initializer())

    converter = tf.contrib.lite.TocoConverter.from_session(sess, [model.input], [model.predictions])
    tflite_model = converter.convert()
    open("converted_model.tflite", "wb").write(tflite_model)
mdietrichstein commented 5 years ago

I have added a new script (tools/export_tflite.py) which exports a tflite model. There are some limitations though. Please check the README file.