Skip to content

Commit

Permalink
[init] Initial content
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanKobzarev committed Sep 30, 2019
1 parent 5b9777a commit d9ca4b1
Show file tree
Hide file tree
Showing 101 changed files with 3,747 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
local.properties
**/*.iml
.gradle
.idea/
.externalNativeBuild
build
7 changes: 7 additions & 0 deletions PyTorchDemoApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
local.properties
**/*.iml
.gradle
.idea/
.externalNativeBuild
build
1 change: 1 addition & 0 deletions PyTorchDemoApp/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions PyTorchDemoApp/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apply plugin: 'com.android.application'

repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}

android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
compileSdkVersion 28
defaultConfig {
applicationId "org.pytorch.demo"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.camera:camera-core:1.0.0-alpha05"
implementation 'com.google.android.material:material:1.0.0-beta01'

implementation 'org.pytorch:pytorch_android:0.0.8-SNAPSHOT'
implementation 'org.pytorch:pytorch_android_torchvision:0.0.8-SNAPSHOT'
}
33 changes: 33 additions & 0 deletions PyTorchDemoApp/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.pytorch.demo">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity
android:name=".WelcomeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".MainActivity"></activity>
<activity android:name=".vision.VisionListActivity" />
<activity android:name=".nlp.NLPListActivity" />
<activity
android:name=".vision.ImageClassificationActivity"
android:label="@string/image_classification_title"></activity>
<activity android:name=".nlp.TextClassificationActivity" />

</application>

<uses-permission android:name="android.permission.CAMERA" />

</manifest>
Binary file not shown.
Binary file not shown.
Binary file added PyTorchDemoApp/app/src/main/assets/resnet18.pt
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.pytorch.demo;

import android.os.Bundle;
import android.view.ViewStub;

import androidx.annotation.LayoutRes;
import androidx.appcompat.app.AppCompatActivity;

public abstract class AbstractListActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_stub);
findViewById(R.id.list_back).setOnClickListener(v -> finish());
final ViewStub listContentStub = findViewById(R.id.list_content_stub);
listContentStub.setLayoutResource(getListContentLayoutRes());
listContentStub.inflate();
}

protected abstract @LayoutRes
int getListContentLayoutRes();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package org.pytorch.demo;

import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class BaseModuleActivity extends AppCompatActivity {
private static final int UNSET = 0;

protected HandlerThread mBackgroundThread;
protected Handler mBackgroundHandler;
protected Handler mUIHandler;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUIHandler = new Handler(getMainLooper());
}

@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
final Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
}
startBackgroundThread();
}

protected void startBackgroundThread() {
mBackgroundThread = new HandlerThread("ModuleActivity");
mBackgroundThread.start();
mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
}

@Override
protected void onDestroy() {
stopBackgroundThread();
super.onDestroy();
}

protected void stopBackgroundThread() {
mBackgroundThread.quitSafely();
try {
mBackgroundThread.join();
mBackgroundThread = null;
mBackgroundHandler = null;
} catch (InterruptedException e) {
Log.e(Constants.TAG, "Error on stopping background thread", e);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_model, menu);
menu.findItem(R.id.action_info).setVisible(getInfoViewCode() != UNSET);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_info) {
onMenuItemInfoSelected();
}
return super.onOptionsItemSelected(item);
}

protected int getInfoViewCode() {
return UNSET;
}

protected String getInfoViewAdditionalText() {
return null;
}

private void onMenuItemInfoSelected() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setCancelable(true)
.setView(InfoViewFactory.newInfoView(this, getInfoViewCode(), getInfoViewAdditionalText()));

builder.show();
}

@UiThread
protected void showErrorDialog(View.OnClickListener clickListener) {
final View view = InfoViewFactory.newErrorDialogView(this);
view.setOnClickListener(clickListener);
final AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.CustomDialog)
.setCancelable(false)
.setView(view);
builder.show();
}
}
Loading

0 comments on commit d9ca4b1

Please sign in to comment.