[英]tensorflow lite: error when converting retrained graph model to lite format
Followed Steps 遵循的步骤
Step1- Clone the git repository: 步骤1-克隆git仓库:
git clone https://github.com/googlecodelabs/tensorflow-for-poets-2
cd tensorflow-for-poets-2
Step2- Download the training images or gather the custom images: 步骤2-下载训练图像或收集自定义图像:
curl http://download.tensorflow.org/example_images/flower_photos.tgz \
| tar xz -C tf_files
Step3- set the image size and architecture: 步骤3-设置图像大小和体系结构:
IMAGE_SIZE=224
ARCHITECTURE="mobilenet_0.50_${IMAGE_SIZE}"
Step4- Retrain the model 步骤4-重新训练模型
python -m scripts.retrain \
--bottleneck_dir=tf_files/bottlenecks \
--model_dir=tf_files/models/"${ARCHITECTURE}" \
--summaries_dir=tf_files/training_summaries/"${ARCHITECTURE}" \
--output_graph=tf_files/retrained_graph.pb \
--output_labels=tf_files/retrained_labels.txt \
--architecture="${ARCHITECTURE}" \
--image_dir=tf_files/flower_photos
Step5- Using retrained model check the classify image 步骤5-使用重新训练的模型检查分类图像
python -m scripts.label_image \
--graph=tf_files/retrained_graph.pb\ --
image=tf_files/flower_photos/daisy/3475870145_685a19116d.jpg
Evaluation time (1-image): 0.281s 评估时间(1张图像):0.281s
daisy 0.725841 dandelion 0.200525 tulips 0.0411526 roses 0.0318613 sunflowers 0.000619742 雏菊0.725841蒲公英0.200525郁金香0.0411526玫瑰0.0318613向日葵0.000619742
Step6:Optimize the model 步骤6:优化模型
IMAGE_SIZE=224
toco \
--input_file=tf_files/retrained_graph.pb \
--output_file=tf_files/optimized_graph.pb \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TENSORFLOW_GRAPHDEF \
--input_shape=1,${IMAGE_SIZE},${IMAGE_SIZE},3 \
--input_array=input \
--output_array=final_result
Step7- Verify the optimized model of classifying image 步骤7-验证分类图像的优化模型
python -m scripts.label_image \
--graph=tf_files/optimized_graph.pb \
--image=tf_files/flower_photos/daisy/3475870145_685a19116d.jpg
Evaluation time (1-image): 0.126s 评估时间(1张图像):0.126s
daisy 0.725845 dandelion 0.200523 tulips 0.0411517 roses 0.031861 sunflowers 0.00061973 雏菊0.725845蒲公英0.200523郁金香0.0411517玫瑰0.031861向日葵0.00061973
Step8- Convert to model to TFlite format 步骤8-将模型转换为TFlite格式
IMAGE_SIZE=224
toco \
--input_file=tf_files/retrained_graph.pb \
--output_file=tf_files/optimized_graph.lite \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--input_shape=1,${IMAGE_SIZE},${IMAGE_SIZE},3 \
--input_array=input \
--output_array=final_result \
--inference_type=FLOAT \
--input_type=FLOAT
Still getting the issue of 0-th input should have 602112 bytes, but found 150528 bytes 仍然遇到第0个输入的问题,应该有602112字节,但是找到了150528字节
Please give a better solution to overcome/achieve this issue to solve 请提供更好的解决方案来克服/解决此问题
Been trying to do this all morning, with 1.9 and above (and possibly 1.8 too, haven't tested.) you need to drop the --input_format
field, and change the --input_file
param to --graph_def_file
整天都在尝试使用1.9及更高版本(可能还有1.8,尚未测试)进行此操作。您需要删除
--input_format
字段,并将--input_file
参数更改为--graph_def_file
So you end up with a command that looks a bit like: 因此,您最终得到的命令看起来像:
toco \
--graph_def_file=tf_files/retrained_graph.pb \
--output_file=tf_files/optimized_graph.lite \
--output_format=TFLITE \
--input_shape=1,${IMAGE_SIZE},${IMAGE_SIZE},3 \
--input_array=input \
--output_array=final_result \
--inference_type=FLOAT \
--inference_input_type=FLOAT
I was then able to complete the poets example and get my tflite file to work on android. 然后,我能够完成诗人的示例,并使我的tflite文件在android上工作。
Source: https://github.com/googlecodelabs/tensorflow-for-poets-2/issues/68 来源: https : //github.com/googlecodelabs/tensorflow-for-poets-2/issues/68
I assume you are trying to use your model in the android-app that comes with Tensorflow for Poets. 我假设您正在尝试在Tensorflow for Poets随附的android-app中使用您的模型。 If that is the case and you are getting this error in Android Studio, you should have a look at your ImageClassifier.java file.
如果是这种情况,并且您在Android Studio中遇到此错误,则应该查看ImageClassifier.java文件。
My guess is that your static final int DIM_IMG_SIZE_X and static final int DIM_IMG_SIZE_Y are not the same value as your IMG_SIZE. 我的猜测是,您的静态最终int DIM_IMG_SIZE_X和静态最终int DIM_IMG_SIZE_Y与您的IMG_SIZE值不同。 If you set those two values to 224, that should solve the problem.
如果将这两个值设置为224,则应该可以解决问题。
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.