Merge branch 'depth-prediction' into 'master'
Depth prediction See merge request vato007/picar!8
This commit is contained in:
@@ -11,7 +11,7 @@ cache:
|
|||||||
- .gradle/
|
- .gradle/
|
||||||
|
|
||||||
protoc_gen:
|
protoc_gen:
|
||||||
image: vato.ddns.net:8083/gradle
|
image: vato.ddns.net:8083/gradle:6.7.1
|
||||||
stage: protoc
|
stage: protoc
|
||||||
rules:
|
rules:
|
||||||
- changes:
|
- changes:
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ plugins{
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 30
|
||||||
buildToolsVersion "29.0.2"
|
buildToolsVersion "29.0.2"
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "org.vato.carcontroller"
|
applicationId "org.vato.carcontroller"
|
||||||
minSdkVersion 26
|
minSdkVersion 26
|
||||||
targetSdkVersion 29
|
targetSdkVersion 30
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
@@ -24,18 +24,24 @@ android {
|
|||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = 1.8
|
||||||
}
|
}
|
||||||
|
buildFeatures {
|
||||||
|
mlModelBinding true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':protobuf')
|
implementation project(':protobuf')
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||||
implementation 'com.google.android.material:material:1.1.0'
|
implementation 'com.google.android.material:material:1.3.0'
|
||||||
implementation 'androidx.preference:preference:1.1.1'
|
implementation 'androidx.preference:preference:1.1.1'
|
||||||
testImplementation 'junit:junit:4.12'
|
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
|
||||||
androidTestImplementation 'androidx.test:runner:1.2.0'
|
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0-rc1'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
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-okhttp:1.29.0' // CURRENT_GRPC_VERSION
|
||||||
implementation 'io.grpc:grpc-protobuf-lite: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
|
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.
@@ -6,7 +6,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:4.0.1'
|
classpath 'com.android.tools.build:gradle:4.1.3'
|
||||||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
|
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
|||||||
Reference in New Issue
Block a user