diff --git a/PytorchAndroid/.idea/compiler.xml b/PytorchAndroid/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/PytorchAndroid/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PytorchAndroid/.idea/gradle.xml b/PytorchAndroid/.idea/gradle.xml index 2996d53..9bba60d 100644 --- a/PytorchAndroid/.idea/gradle.xml +++ b/PytorchAndroid/.idea/gradle.xml @@ -1,14 +1,20 @@ + diff --git a/PytorchAndroid/.idea/jarRepositories.xml b/PytorchAndroid/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/PytorchAndroid/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/PytorchAndroid/.idea/misc.xml b/PytorchAndroid/.idea/misc.xml index af0bbdd..3378229 100644 --- a/PytorchAndroid/.idea/misc.xml +++ b/PytorchAndroid/.idea/misc.xml @@ -5,7 +5,7 @@ - + diff --git a/PytorchAndroid/app/build.gradle b/PytorchAndroid/app/build.gradle index 0e1c04e..06042b7 100644 --- a/PytorchAndroid/app/build.gradle +++ b/PytorchAndroid/app/build.gradle @@ -1,31 +1,44 @@ -apply plugin: 'com.android.application' +plugins { + id 'com.android.application' +} android { - compileSdkVersion 28 + compileSdkVersion 30 + buildToolsVersion "30.0.3" + defaultConfig { applicationId "com.johnolafenwa.pytorchandroid" minSdkVersion 21 - targetSdkVersion 28 + targetSdkVersion 30 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'org.pytorch:pytorch_android:1.3.0' - implementation 'org.pytorch:pytorch_android_torchvision:1.3.0' - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation 'com.android.support:design:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + + // add PyTorch dependency + implementation 'org.pytorch:pytorch_android:1.7.1' + implementation 'org.pytorch:pytorch_android_torchvision:1.7.1' + } diff --git a/PytorchAndroid/app/src/main/assets/mobilenet-v2.pt b/PytorchAndroid/app/src/main/assets/mobilenet-v2.pt index 0316eb1..347faa6 100644 Binary files a/PytorchAndroid/app/src/main/assets/mobilenet-v2.pt and b/PytorchAndroid/app/src/main/assets/mobilenet-v2.pt differ diff --git a/PytorchAndroid/app/src/main/java/com/johnolafenwa/pytorchandroid/MainActivity.java b/PytorchAndroid/app/src/main/java/com/johnolafenwa/pytorchandroid/MainActivity.java index be4c147..c90ff80 100644 --- a/PytorchAndroid/app/src/main/java/com/johnolafenwa/pytorchandroid/MainActivity.java +++ b/PytorchAndroid/app/src/main/java/com/johnolafenwa/pytorchandroid/MainActivity.java @@ -4,11 +4,14 @@ import android.graphics.Bitmap; import android.os.Bundle; import android.provider.MediaStore; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; + import android.util.Log; import android.view.View; import android.widget.Button; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + import java.io.File; public class MainActivity extends AppCompatActivity { @@ -46,18 +49,19 @@ public void onClick(View view){ } @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data){ + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); - if(requestCode == cameraRequestCode && resultCode == RESULT_OK){ + if (requestCode == cameraRequestCode && resultCode == RESULT_OK) { - Intent resultView = new Intent(this,Result.class); + Intent resultView = new Intent(this, Result.class); - resultView.putExtra("imagedata",data.getExtras()); + resultView.putExtra("imagedata", data.getExtras()); Bitmap imageBitmap = (Bitmap) data.getExtras().get("data"); String pred = classifier.predict(imageBitmap); - resultView.putExtra("pred",pred); + resultView.putExtra("pred", pred); startActivity(resultView); diff --git a/PytorchAndroid/app/src/main/java/com/johnolafenwa/pytorchandroid/Result.java b/PytorchAndroid/app/src/main/java/com/johnolafenwa/pytorchandroid/Result.java index 3301630..4733796 100644 --- a/PytorchAndroid/app/src/main/java/com/johnolafenwa/pytorchandroid/Result.java +++ b/PytorchAndroid/app/src/main/java/com/johnolafenwa/pytorchandroid/Result.java @@ -2,11 +2,13 @@ import android.graphics.Bitmap; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; + import android.widget.ImageView; import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + public class Result extends AppCompatActivity { @Override diff --git a/PytorchAndroid/app/src/main/res/layout/activity_main.xml b/PytorchAndroid/app/src/main/res/layout/activity_main.xml index 673a506..1f21c22 100644 --- a/PytorchAndroid/app/src/main/res/layout/activity_main.xml +++ b/PytorchAndroid/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - - - - + - \ No newline at end of file + \ No newline at end of file diff --git a/PytorchAndroid/app/src/main/res/layout/activity_result.xml b/PytorchAndroid/app/src/main/res/layout/activity_result.xml index 6557599..21b0208 100644 --- a/PytorchAndroid/app/src/main/res/layout/activity_result.xml +++ b/PytorchAndroid/app/src/main/res/layout/activity_result.xml @@ -1,25 +1,25 @@ - - - - + - \ No newline at end of file + \ No newline at end of file diff --git a/PytorchAndroid/app/src/main/res/layout/content_main.xml b/PytorchAndroid/app/src/main/res/layout/content_main.xml index 63593ba..c82a905 100644 --- a/PytorchAndroid/app/src/main/res/layout/content_main.xml +++ b/PytorchAndroid/app/src/main/res/layout/content_main.xml @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/PytorchAndroid/app/src/main/res/layout/content_result.xml b/PytorchAndroid/app/src/main/res/layout/content_result.xml index 4f453c2..f1d8ad0 100644 --- a/PytorchAndroid/app/src/main/res/layout/content_result.xml +++ b/PytorchAndroid/app/src/main/res/layout/content_result.xml @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/PytorchAndroid/app/src/main/res/values/colors.xml b/PytorchAndroid/app/src/main/res/values/colors.xml index 69b2233..07d0722 100644 --- a/PytorchAndroid/app/src/main/res/values/colors.xml +++ b/PytorchAndroid/app/src/main/res/values/colors.xml @@ -3,4 +3,12 @@ #008577 #00574B #D81B60 + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + #3DDC84 diff --git a/PytorchAndroid/app/src/main/res/values/themes.xml b/PytorchAndroid/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..8327200 --- /dev/null +++ b/PytorchAndroid/app/src/main/res/values/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/PytorchAndroid/build.gradle b/PytorchAndroid/build.gradle index 458d06a..ec19a1f 100644 --- a/PytorchAndroid/build.gradle +++ b/PytorchAndroid/build.gradle @@ -1,14 +1,12 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { repositories { google() jcenter() - } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' - + classpath "com.android.tools.build:gradle:4.1.3" + // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -18,10 +16,9 @@ allprojects { repositories { google() jcenter() - } } task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/PytorchAndroid/gradle.properties b/PytorchAndroid/gradle.properties index 82618ce..01b80d7 100644 --- a/PytorchAndroid/gradle.properties +++ b/PytorchAndroid/gradle.properties @@ -6,10 +6,14 @@ # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx1536m +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true - - +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true diff --git a/PytorchAndroid/gradle/wrapper/gradle-wrapper.properties b/PytorchAndroid/gradle/wrapper/gradle-wrapper.properties index 4bb639e..b5a7ec3 100644 --- a/PytorchAndroid/gradle/wrapper/gradle-wrapper.properties +++ b/PytorchAndroid/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Oct 16 16:50:54 WAT 2019 +#Sat Apr 26 09:48:01 IST 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip diff --git a/mobilenet-v2.pt b/mobilenet-v2.pt new file mode 100644 index 0000000..347faa6 Binary files /dev/null and b/mobilenet-v2.pt differ