我想使用tensorflow lite在Android手机中运行一个tensorflow模型(.pb)。因此,我使用以下命令创建了.tflite文件:
从图像生成.pb文件
IMAGE_SIZE=224
ARCHITECTURE="mobilenet_0.50_${IMAGE_SIZE}"
!python3 /content/retrain.py \
--image_dir=/content/flowers \
--how_many_training_steps=200 \
--output_graph=/content/retrained_graph.pb \
--output_labels=/content/retrained_labels.txt \
--architecture="${ARCHITECTURE}" \
--model_dir=/content \
生成tflite。 .pb
中的文件IMAGE_SIZE=299
!tflite_convert \
--graph_def_file=/content/retrained_graph.pb \
--output_file=/content/fff.tflite \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--input_shape=1,299,299,3 \
--input_array=Placeholder \
--output_array=final_result \
--inference_type=FLOAT \
--input_data_type=FLOAT
在Android Studio项目“资产文件夹”中插入.tflite时,它显示了锁定符号(红色箭头)。但是,从github下载的原始.tflite没有锁符号(黑色箭头)。我试图运行该项目,然后显示以下错误。您能帮我解决这个问题吗?为什么无法访问我的自定义.tflite并带有锁定符号?我认为这会造成所有这些问题。
!https://drive.google.com/open?id=1A1vIK-sRq1MsMf4bwxnMUgMrjoI4KJyf
11-09 21:51:15.231 1926-8159/? E/COLUMBUS-11-09 21:51:13.938 7593-7699/tejashwi.com.tensorflowsample E/AndroidRuntime: FATAL EXCEPTION: Camera Background
Process: tejashwi.com.tensorflowsample, PID: 7593
java.lang.IllegalArgumentException: Cannot convert between a TensorFlowLite buffer with 268203 bytes and a ByteBuffer with 150528 bytes.
at org.tensorflow.lite.Tensor.throwIfShapeIsIncompatible(Tensor.java:281)
at org.tensorflow.lite.Tensor.throwIfDataIsIncompatible(Tensor.java:258)
at org.tensorflow.lite.Tensor.setTo(Tensor.java:119)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:167)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:275)
at org.tensorflow.lite.Interpreter.run(Interpreter.java:249)
at tejashwi.com.tensorflowsample.TensorFlowImageClassifier.recognizeImage(TensorFlowImageClassifier.java:70)
at tejashwi.com.tensorflowsample.MainActivity$3.onImageAvailable(MainActivity.java:291)
at android.media.ImageReader$ListenerHandler.handleMessage(ImageReader.java:687)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.os.HandlerThread.run(HandlerThread.java:61)
11-09 21:54:07.371 1926-9043/? E/COLUMBUS-AD-SDK-AndroidUtils: Get MCC/MNC exception
java.lang.SecurityException: getSubscriberId: Neither user 10027 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1715)
at android.os.Parcel.readException(Parcel.java:1668)
at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getSubscriberIdForSubscriber(IPhoneSubInfo.java:562)
at android.telephony.TelephonyManager.getSubscriberId(TelephonyManager.java:2228)
at android.telephony.TelephonyManager.getSubscriberId(TelephonyManager.java:2208)
at com.miui.zeus.columbus.util.a.b(AndroidUtils.java:109)
at com.miui.zeus.columbus.ad.nativead.NativeAdServer.buildUserInfo(NativeAdServer.java:98)
at com.miui.zeus.columbus.ad.nativead.NativeAdServer.buildHttpRequest(NativeAdServer.java:145)
at com.miui.zeus.columbus.remote.e.connect(Server.java:64)
at com.miui.zeus.columbus.remote.e.connect(Server.java:51)
at com.miui.zeus.columbus.ad.nativead.NativeAdServer.connect(NativeAdServer.java:55)
at com.miui.zeus.columbus.ad.nativead.NativeAdServer.requestNativeAd(NativeAdServer.java:51)
at com.miui.zeus.columbus.ad.nativead.NativeAdManager$1.execute(NativeAdManager.java:95)
at com.miui.zeus.columbus.common.ThrowableCaughtRunnable.run(ThrowableCaughtRunnable.java:23)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:760)
答案 0 :(得分:0)
我能知道您使用的体系结构,也许是引起问题的原因...
答案 1 :(得分:0)
将299替换为224和--input_array=input
。如果可行,请对此答案进行投票。