amitshekhariitbhu / android-tensorflow-lite-example Goto Github PK
View Code? Open in Web Editor NEWAndroid TensorFlow Lite Machine Learning Example
Home Page: https://amitshekhar.me
License: Apache License 2.0
Android TensorFlow Lite Machine Learning Example
Home Page: https://amitshekhar.me
License: Apache License 2.0
Hi, many thanks for the article and the sample-code.
It works fine with the model mentioned in your project. However, I trained my own model (using the tensorflow-for-poets 1 and 2 tutorials) but I get an error using my model with your code:
"Cannot convert between a TensorFlowLite buffer with XXX bytes and a ByteBuffer with XXX bytes."
This happens when running the following statement:
interpreter.run(byteBuffer, result);
My model works fine with the sample-project in "the tensorflow-for-poets2 tutorial.
Just wondering what can be the issue. Any ideas?
Thanks.
Hi there.
I wanted to know if it is possible to store and read the trained .tflite
model from the Android device's internal storage instead of the assets folder?
The issue I am having is with the startOffset
value in the loadModelFile(AssetManager assetManager, String modelPath)
function. currently, it comes from AssetFileDescriptor fileDescriptor = assetManager.openFd(modelPath)
.
This file descriptor is used to get the start offset and declared length. Is there another way to read it from internal memory instead and still get the start offset and declaredLength? If not, is there a way to calculate the startOffset of a new model and its declared length when reading the raw binary from internal storage?
Hi @amitshekhariitbhu this work has been great so far, But when i tried to call the Image Scanner activity from another activity and get the result it is not working(activity not close) also onBackPressed() working and finally how can we train the model to recognize more object.
Below is my code:
Intent sendCapturedCode = new Intent();
sendCapturedCode.putExtra(getString(R.string.captured_image_tflow_result), imageAnalysesResult);
sendCapturedCode.putExtra(getString(R.string.captured_image_bitmap), capturedBitmap);
setResult(RESULT_OK, sendCapturedCode);
finish();
https://letslearnai.com/2018/03/17/android-tensorflow-lite-machine-learning-example.html
Im trying to reach this link but it looks that it has been deleted , can you give me another link to this article please.
Thank you in advanced
if I have a XXXX.pb File what is DetecotClasiter ,plese tell me what can i do ?
I tried to convert the model I made into tflite and execute it.
I don't know what the problem is, but if i press the detection button, the app is shut down.
The model I made is sort of cat type, and I think there was a problem in the process of modifying the model to tflite.
Is there a way to find out if the model is .tflite file?
Installed the default tflite apk file in the mobile device using the android studio environment. By default, the installed app has to detect the 90 common objects. The detecting accuracy is very poor.
System information
I didn't make any changes to the TFLIte framework. I cloned the GitHub repo (https://github.com/tensorflow/examples.git) and opened the object detection folder in the android studio. I generated a build and installed that generated Apk file.
Used windows 10 with android studio
Mobile device (Samsung A30)
TensorFlow installed from (https://github.com/tensorflow/examples.git
TensorFlow version 1.15
Describe the current behavior
After installing the tflite default(90 classes) apk file into the mobile. Checked with various object what mentioned in the labelmap file. But the prediction outcome is not correct most of the time.
Why this poor accuracy with the default TFLite Apk file.
please make option how to integrate the multidetector and the object tracking, l
so that bounding box can be made around the object that's been detected ..!!!
How to enable GPU support on Android for YOLOv2 and YOLOv3. I have already converted YOLOv2.pb and YOLOv3.pb to respective .tflite. Can u please tell me what modifications I need to do to enable that?
I re-retrain my model and once I put inside it said:
Cannot copy to a TensorFlowLite tensor (Image) with 602112 bytes from a Java Buffer with 150528 bytes.
1 x 224 x 224 x 3 x 4 will get correct result but now it misses x 4
how can I fix it?
HI
Could anybody say me how I can increase image size and quality? (in posenet example)
OS: Ubuntu 16.0.4 64bit
Python version: 3.6.5 on virtual env
Tensorflow version: 1.11.0
I retrained a model with model architecture (mobilenet_v1_224) . cant freeze it because it says it is already frozen after retraining. then I convert it using toco. I import it to assets folder ,the graph.tflite and labels.txt, edit the model and label variables in MainActivity,
but when I launched it in my device and hit "Detect Object" button, it crashes.Am I missing something? How can I fix this. Please help me, Thank you very much!!
hello sir, i need to learn about machine learning and i start with your amazing project but when i run, this error showed and i have no idea, can you help me found the solution ?
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformNativeLibsWithStripDebugSymbolForDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'E:\Ade\old\sdk\ndk-bundle\toolchains\mips64el-linux-android-4.9\prebuilt\windows-x86_64\bin\mips64el-linux-android-strip''
at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:220)
at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:204)
at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:340)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86)
at org.gradle.internal.operations.BuildOperationIdentifierPreservingRunnable.run(BuildOperationIdentifierPreservingRunnable.java:39)
... 6 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'E:\Ade\old\sdk\ndk-bundle\toolchains\mips64el-linux-android-4.9\prebuilt\windows-x86_64\bin\mips64el-linux-android-strip'
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(WindowsProcessLauncher.java:22)
at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:68)
... 7 more
Caused by: java.io.IOException: Cannot run program "E:\Ade\old\sdk\ndk-bundle\toolchains\mips64el-linux-android-4.9\prebuilt\windows-x86_64\bin\mips64el-linux-android-strip" (in directory "E:\Ade\new\tutor\MLearning\Android-TensorFlow-Lite-Example-master\app"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
... 10 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 11 more
I have changed the required things for inceptionV3 as mentioned below but still its not working. its giving me an error :
cannot convert an tensorflowlite tensor with type float32 to a java object of type [[b (which is compatible with the tensorflowlite type uint8)
Changes that I did :
private static final int INPUT_SIZE = 299;
/**
* The inception net requires additional normalization of the used input.
*/
private static final int IMAGE_MEAN = 128;
private static final float IMAGE_STD = 128.0f;
private ByteBuffer convertBitmapToByteBufferForInceptionV3(Bitmap bitmap) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BATCH_SIZE * inputSize * inputSize * PIXEL_SIZE * 4);
byteBuffer.order(ByteOrder.nativeOrder());
int[] intValues = new int[inputSize * inputSize];
bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
int pixel = 0;
for (int i = 0; i < inputSize; ++i) {
for (int j = 0; j < inputSize; ++j) {
final int val = intValues[pixel++];
byteBuffer.putFloat((((val >> 16) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
byteBuffer.putFloat((((val >> 8) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
byteBuffer.putFloat(((val & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
}
}
return byteBuffer;
}
I have cloned this repo, and when I try to build the project, this is what I get as an error in the Build log:
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
I use Android Studio 3.2.1 on Mac OS
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.