Skip to content

Clean up UI #660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
Expand All @@ -22,7 +21,6 @@
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.example.executorchdemo.executor.EValue;
import com.example.executorchdemo.executor.Module;
import com.example.executorchdemo.executor.Tensor;
Expand All @@ -36,11 +34,11 @@

public class MainActivity extends Activity implements Runnable {
private ImageView mImageView;
private Button mButtonSegment;
private Button mButtonXnnpack;
private Button mButtonHtp;
private ProgressBar mProgressBar;
private Bitmap mBitmap = null;
private Module mModule = null;
private String mBackend = "xnnpack";
private String mImagename = "corgi.jpeg";

// see http://host.robots.ox.ac.uk:8080/pascal/VOC/voc2007/segexamples/index.html for the list of
Expand All @@ -50,11 +48,6 @@ public class MainActivity extends Activity implements Runnable {
private static final int PERSON = 15;
private static final int SHEEP = 17;

private void openClassificationActivity() {
Intent intent = new Intent(this, ClassificationActivity.class);
startActivity(intent);
}

public static String assetFilePath(Context context, String assetName) throws IOException {
File file = new File(context.getFilesDir(), assetName);
if (file.exists() && file.length() > 0) {
Expand All @@ -74,6 +67,17 @@ public static String assetFilePath(Context context, String assetName) throws IOE
}
}

private void populateImage() {
try {
mBitmap = BitmapFactory.decodeStream(getAssets().open(mImagename));
mBitmap = Bitmap.createScaledBitmap(mBitmap, 224, 224, true);
mImageView.setImageBitmap(mBitmap);
} catch (IOException e) {
Log.e("ImageSegmentation", "Error reading assets", e);
finish();
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -94,11 +98,20 @@ protected void onCreate(Bundle savedInstanceState) {
finish();
}

try {
mModule =
Module.load(MainActivity.assetFilePath(getApplicationContext(), "dl3_xnnpack_fp32.pte"));

} catch (IOException e) {
Log.e("ImageSegmentation", "Error reading assets", e);
finish();
}

mImageView = findViewById(R.id.imageView);
mImageView.setImageBitmap(mBitmap);

final Button buttonRestart = findViewById(R.id.restartButton);
buttonRestart.setOnClickListener(
final Button buttonNext = findViewById(R.id.nextButton);
buttonNext.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
if (Objects.equals(mImagename, "corgi.jpeg")) {
Expand All @@ -108,79 +121,62 @@ public void onClick(View v) {
} else {
mImagename = "corgi.jpeg";
}
try {
mBitmap = BitmapFactory.decodeStream(getAssets().open(mImagename));
mBitmap = Bitmap.createScaledBitmap(mBitmap, 224, 224, true);
mImageView.setImageBitmap(mBitmap);
} catch (IOException e) {
Log.e("ImageSegmentation", "Error reading assets", e);
finish();
}
populateImage();
}
});

final Button buttonSwitchBackend = findViewById(R.id.switchBackendButton);
buttonSwitchBackend.setText("Use Qualcomm backend");
buttonSwitchBackend.setOnClickListener(
mButtonXnnpack = findViewById(R.id.xnnpackButton);
mButtonHtp = findViewById(R.id.htpButton);
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mButtonXnnpack.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
try {
if (Objects.equals(mBackend, "xnnpack")) {
mBackend = "qnn";
mModule.destroy();
mModule =
Module.load(
MainActivity.assetFilePath(getApplicationContext(), "dlv3_qnn.pte"));
buttonSwitchBackend.setText("Use XNNPACK backend");
} else {
mBackend = "xnnpack";
mModule.destroy();
mModule =
Module.load(
MainActivity.assetFilePath(
getApplicationContext(), "dl3_xnnpack_fp32.pte"));
buttonSwitchBackend.setText("Use Qualcomm backend");
}
mModule.destroy();
mModule =
Module.load(
MainActivity.assetFilePath(getApplicationContext(), "dl3_xnnpack_fp32.pte"));
} catch (IOException e) {
Log.e("ImageSegmentation", "Error reading assets", e);
finish();
}
Toast toast =
Toast.makeText(getApplicationContext(), "Using: " + mBackend, Toast.LENGTH_SHORT);
toast.setMargin(50, 50);
toast.show();
}
});

final Button classificationDemoButton = findViewById(R.id.classificationDemoButton);
classificationDemoButton.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
openClassificationActivity();
mButtonXnnpack.setEnabled(false);
mProgressBar.setVisibility(ProgressBar.VISIBLE);
mButtonXnnpack.setText(getString(R.string.run_model));

Thread thread = new Thread(MainActivity.this);
thread.start();
}
});

mButtonSegment = findViewById(R.id.segmentButton);
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mButtonSegment.setOnClickListener(
mButtonHtp.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
mButtonSegment.setEnabled(false);
try {
mModule.destroy();
mModule =
Module.load(MainActivity.assetFilePath(getApplicationContext(), "dlv3_qnn.pte"));
} catch (IOException e) {
Log.e("ImageSegmentation", "Error reading assets", e);
finish();
}
mButtonHtp.setEnabled(false);
mProgressBar.setVisibility(ProgressBar.VISIBLE);
mButtonSegment.setText(getString(R.string.run_model));
mButtonHtp.setText(getString(R.string.run_model));

Thread thread = new Thread(MainActivity.this);
thread.start();
}
});

try {
mModule =
Module.load(MainActivity.assetFilePath(getApplicationContext(), "dl3_xnnpack_fp32.pte"));
} catch (IOException e) {
Log.e("ImageSegmentation", "Error reading assets", e);
finish();
}
final Button resetImage = findViewById(R.id.resetImage);
resetImage.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
populateImage();
}
});
}

@Override
Expand Down Expand Up @@ -240,17 +236,11 @@ public void run() {
@Override
public void run() {
mImageView.setImageBitmap(transferredBitmap);
mButtonSegment.setEnabled(true);
mButtonSegment.setText("segment");
mButtonXnnpack.setEnabled(true);
mButtonXnnpack.setText(R.string.run_xnnpack);
mButtonHtp.setEnabled(true);
mButtonHtp.setText(R.string.run_htp);
mProgressBar.setVisibility(ProgressBar.INVISIBLE);

Toast toast =
Toast.makeText(
getApplicationContext(),
"Inference time (ms): " + inferenceTime,
Toast.LENGTH_SHORT);
toast.setMargin(50, 50);
toast.show();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,57 @@
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/segmentButton"
android:id="@+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="segment"
android:layout_marginTop="10dp"
android:text="@string/next"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintHorizontal_bias="0.45"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />


<ProgressBar
android:id="@+id/progressBar"
android:visibility="invisible"
android:layout_marginTop="10dp"
<Button
android:id="@+id/resetImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
android:text="@string/reset"
android:textAllCaps="false"
app:layout_constraintRight_toRightOf="@+id/nextButton"
app:layout_constraintStart_toEndOf="@+id/nextButton"
app:layout_constraintTop_toTopOf="@+id/nextButton" />

<Button
android:id="@+id/restartButton"
android:id="@+id/xnnpackButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/restart"
android:layout_marginTop="20dp"
android:text="@string/run_xnnpack"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintHorizontal_bias="0.45"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/segmentButton" />
app:layout_constraintTop_toBottomOf="@+id/nextButton" />

<Button
android:id="@+id/switchBackendButton"
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/switch_backend"
android:textAllCaps="false"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintHorizontal_bias="0.45"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/restartButton" />
app:layout_constraintTop_toBottomOf="@+id/nextButton" />

<Button
android:id="@+id/classificationDemoButton"
android:id="@+id/htpButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/classification_demo"
android:text="@string/run_htp"
android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/switchBackendButton" />

app:layout_constraintStart_toEndOf="@+id/xnnpackButton"
app:layout_constraintTop_toTopOf="@+id/xnnpackButton" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
<string name="image_view">Image View</string>
<string name="detect">Detect</string>
<string name="run_model">Running the model...</string>
<string name="restart">Restart</string>
<string name="next">Next</string>
<string name="select">Select</string>
<string name="live">Live</string>
<string name="classification_demo">Classification demo</string>
<string name="segmentation_demo">Segmentation Demo</string>
<string name="switch_backend">Switch backend</string>
<string name="run_htp">HTP</string>
<string name="run_xnnpack">XNNPACK</string>
<string name="reset">Reset</string>
</resources>