Comments (13)
Thanks @sercant
But I hav some problem...
in Shell...Traceback (most recent call last): File "tf-convert-tflite.py", line 89, in <module> main(**vars(args)) File "tf-convert-tflite.py", line 47, in main tflite_model = converter.convert() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 439, in convert **converter_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 309, in toco_convert_impl input_data.SerializeToString()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 109, in toco_convert_protos (stdout, stderr)) RuntimeError: TOCO failed see console for info. /bin/sh: toco_from_protos: command not found None
I can't handling this shell error... So How can i do solve this problem?
has anyone solved this error, i'm getting same error for my model
Hey @chin87, I think this is due to a bug in Tensorflow right now. Be sure that toco_from_protos
is in your PATH
variable.
Also, I have an updated version of the script at my repo if you want to check it out. You will need to modify it to work with this repo though.
from mobile-semantic-segmentation.
@akirasosa please help
from mobile-semantic-segmentation.
Hello @kei9327,
Here is a script that I wrote to convert the model to tf-lite. Also, the model is being tested with the python tf-lite interpreter in the code but you can just comment that part out if you don't need it.
https://gist.github.com/sercant/478cac13391e1b69b2be07654cf3d21e
tf-convert-tflite.py
import argparse
import cv2
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from data import standardize
prefix = 'hair_recognition'
def main(pb_file, img_file):
"""
Predict and visualize by TensorFlow.
:param pb_file:
:param img_file:
:return:
"""
with tf.gfile.GFile(pb_file, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def, name=prefix)
for op in graph.get_operations():
print(op.name)
x = graph.get_tensor_by_name('%s/input_1:0' % prefix)
y = graph.get_tensor_by_name('%s/output_0:0' % prefix)
loaded_image = cv2.cvtColor(cv2.imread(img_file,-1), cv2.COLOR_BGR2RGB)
resized_image =cv2.resize(loaded_image, (128, 128))
input_image = np.expand_dims(np.float32(resized_image[:128, :128]),axis=0)/255.0
# images = np.load(img_file).astype(float)
# img_h = images.shape[1]
# img_w = images.shape[2]
with tf.Session(graph=graph) as sess:
# for img in images:
# batched = img.reshape(-1, img_h, img_w, 3)
normalized = standardize(input_image)
converter = tf.contrib.lite.TocoConverter.from_session(sess, [x], [y])
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
# Load TFLite model and allocate tensors.
interpreter = tf.contrib.lite.Interpreter(model_content=tflite_model)
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# Test model on random input data.
# input_shape = input_details[0]['shape']
input_data = np.array(normalized, dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
# print(output_data)
# pred = sess.run(y, feed_dict={
# x: normalized
# })
plt.imshow(output_data.reshape(128, 128))
plt.show()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'--pb_file',
type=str,
default='artifacts/model.pb',
)
parser.add_argument(
'--img_file',
type=str,
default='data/glasshair.jpg',
help='image file as numpy format'
)
args, _ = parser.parse_known_args()
main(**vars(args))
from mobile-semantic-segmentation.
Thanks @sercant
But I hav some problem...
in Shell...
Traceback (most recent call last):
File "tf-convert-tflite.py", line 89, in <module>
main(**vars(args))
File "tf-convert-tflite.py", line 47, in main
tflite_model = converter.convert()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 439, in convert
**converter_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 309, in toco_convert_impl
input_data.SerializeToString())
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 109, in toco_convert_protos
(stdout, stderr))
RuntimeError: TOCO failed see console for info.
/bin/sh: toco_from_protos: command not found
None
I can't handling this shell error... So How can i do solve this problem?
from mobile-semantic-segmentation.
Hi, I have rewrite code using PyTorch and tf-lite is TODO now.
from mobile-semantic-segmentation.
did you notice better accuracy when using pytorch?
from mobile-semantic-segmentation.
Thanks @sercant
But I hav some problem...
in Shell...
Traceback (most recent call last): File "tf-convert-tflite.py", line 89, in <module> main(**vars(args)) File "tf-convert-tflite.py", line 47, in main tflite_model = converter.convert() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 439, in convert **converter_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 309, in toco_convert_impl input_data.SerializeToString()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 109, in toco_convert_protos (stdout, stderr)) RuntimeError: TOCO failed see console for info. /bin/sh: toco_from_protos: command not found None
I can't handling this shell error... So How can i do solve this problem?
Maybe it's because of the python or tensorflow version difference. I am using Python 3.6.5 and Tensorflow 1.12.0.
from mobile-semantic-segmentation.
Thanks @sercant
But I hav some problem...
in Shell...Traceback (most recent call last): File "tf-convert-tflite.py", line 89, in <module> main(**vars(args)) File "tf-convert-tflite.py", line 47, in main tflite_model = converter.convert() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 439, in convert **converter_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 309, in toco_convert_impl input_data.SerializeToString()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 109, in toco_convert_protos (stdout, stderr)) RuntimeError: TOCO failed see console for info. /bin/sh: toco_from_protos: command not found None
I can't handling this shell error... So How can i do solve this problem?
Maybe it's because of the python or tensorflow version difference. I am using Python 3.6.5 and Tensorflow 1.12.0.
If it's not an excuse, Do you have any pretrain data (TFLite)?
from mobile-semantic-segmentation.
Thanks @sercant
But I hav some problem...
in Shell...Traceback (most recent call last): File "tf-convert-tflite.py", line 89, in <module> main(**vars(args)) File "tf-convert-tflite.py", line 47, in main tflite_model = converter.convert() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 439, in convert **converter_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 309, in toco_convert_impl input_data.SerializeToString()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 109, in toco_convert_protos (stdout, stderr)) RuntimeError: TOCO failed see console for info. /bin/sh: toco_from_protos: command not found None
I can't handling this shell error... So How can i do solve this problem?
Maybe it's because of the python or tensorflow version difference. I am using Python 3.6.5 and Tensorflow 1.12.0.
If it's not an excuse, Do you have any pretrain data (TFLite)?
Here is the one I converted using shared pre-trained model.
from mobile-semantic-segmentation.
@sercant how did the model performed on your implementation? I just tried this today and it performed really bad... not only is it slow ~1100ms it also just tries to predict a hair in the middle of the screen everytime.
from mobile-semantic-segmentation.
@sercant how did the model performed on your implementation? I just tried this today and it performed really bad... not only is it slow ~1100ms it also just tries to predict a hair in the middle of the screen everytime.
Yes, it was the same case for me regarding both performance and the behavior. I don't know why it tries to find a hair in the middle of the screen all the time. Maybe the checkpoint provided in #17 was overfitted.
from mobile-semantic-segmentation.
Thanks @sercant
But I hav some problem...
in Shell...
Traceback (most recent call last): File "tf-convert-tflite.py", line 89, in <module> main(**vars(args)) File "tf-convert-tflite.py", line 47, in main tflite_model = converter.convert() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 439, in convert **converter_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 309, in toco_convert_impl input_data.SerializeToString()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 109, in toco_convert_protos (stdout, stderr)) RuntimeError: TOCO failed see console for info. /bin/sh: toco_from_protos: command not found None
I can't handling this shell error... So How can i do solve this problem?
has anyone solved this error, i'm getting same error for my model
from mobile-semantic-segmentation.
Hi @sercant @akirasosa sorry for bringing up this 2 year old issue. Any news on adding a script to convert to tflite?
@sercant , does your script still works with this repo? Thank you in advance!
from mobile-semantic-segmentation.
Related Issues (20)
- How to calculate the mean and std value? HOT 1
- ImportError: cannot import name 'relu6' HOT 3
- Generate ppm files for custom datasets HOT 1
- Is there a way to test the trained model on a single image ? HOT 2
- I trained with my own dataset input size is 224x224, but the output is 112 x 112 HOT 3
- do you train on Mobilenetv2 Unet pytorch? HOT 1
- dataset transform? HOT 1
- How long to train the model? HOT 3
- output size of the converted model is wrong HOT 2
- which dataset did you use when you trained the pre_trained model ? HOT 3
- Any Inference Speed Record in CPU Mode HOT 9
- Why you didn't need to add a relu operation after deconvolution? HOT 1
- Please consider Hydra
- Is is possible to have dataset with different image sizes?
- Is it possible to convert the model to Tensorflow JS model?
- How to run the model? HOT 2
- integrate with Lightning ecosystem CI
- README Training Instructions Broken
- Output data type is MultiArray after run_convert_coreml.py
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobile-semantic-segmentation.