Add depth model and interface class, update dependencies and android sdk
This commit is contained in:
@@ -4,12 +4,12 @@ plugins{
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "29.0.2"
|
||||
defaultConfig {
|
||||
applicationId "org.vato.carcontroller"
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 29
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
@@ -24,18 +24,24 @@ android {
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
buildFeatures {
|
||||
mlModelBinding true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':protobuf')
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'com.google.android.material:material:1.1.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
implementation 'androidx.preference:preference:1.1.1'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
|
||||
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0-rc1'
|
||||
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test:runner:1.3.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation 'io.grpc:grpc-okhttp:1.29.0' // CURRENT_GRPC_VERSION
|
||||
implementation 'io.grpc:grpc-protobuf-lite:1.29.0' // CURRENT_GRPC_VERSION
|
||||
implementation 'io.grpc:grpc-stub:1.29.0' // CURRENT_GRPC_VERSION
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.vato.carcontroller.depth;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import org.tensorflow.lite.gpu.CompatibilityList;
|
||||
import org.tensorflow.lite.support.image.ColorSpaceType;
|
||||
import org.tensorflow.lite.support.image.TensorImage;
|
||||
import org.tensorflow.lite.support.model.Model;
|
||||
import org.vato.carcontroller.ml.MobilenetNnconv5;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Predicts the depth
|
||||
*/
|
||||
public class DepthPredictionModel implements AutoCloseable {
|
||||
|
||||
private MobilenetNnconv5 model = null;
|
||||
|
||||
private DepthPredictionModel() {
|
||||
}
|
||||
|
||||
public static DepthPredictionModel newModel(Context context) {
|
||||
try {
|
||||
DepthPredictionModel created = new DepthPredictionModel();
|
||||
Model.Options.Builder options = new Model.Options.Builder();
|
||||
CompatibilityList compatList = new CompatibilityList();
|
||||
if (compatList.isDelegateSupportedOnThisDevice()) {
|
||||
// TODO: Choice of gpu and nnapi?
|
||||
options.setDevice(Model.Device.GPU);
|
||||
} else {
|
||||
// TODO: User configurable?
|
||||
options.setNumThreads(4);
|
||||
}
|
||||
created.model = MobilenetNnconv5.newInstance(context, options.build());
|
||||
return created;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap predict(Bitmap bitmap) {
|
||||
// TODO: Resizing/cropping, handle it all in the framework
|
||||
TensorImage image = TensorImage.fromBitmap(bitmap);
|
||||
// Runs model inference and gets result.
|
||||
MobilenetNnconv5.Outputs outputs = model.process(image.getTensorBuffer());
|
||||
TensorImage depth = new TensorImage();
|
||||
depth.load(outputs.getOutputFeature0AsTensorBuffer(), ColorSpaceType.GRAYSCALE);
|
||||
// TODO: Resize back to something similar to original (ignore crop obviously)?
|
||||
return depth.getBitmap();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
model.close();
|
||||
}
|
||||
}
|
||||
BIN
app/src/main/ml/mobilenet_nnconv5.tflite
Normal file
BIN
app/src/main/ml/mobilenet_nnconv5.tflite
Normal file
Binary file not shown.
Reference in New Issue
Block a user