Skip to content

[mobile][android] Tutorial corrections and aligning with the android api #267

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

Conversation

IvanKobzarev
Copy link
Contributor

No description provided.

@@ -71,9 +71,9 @@ Further in this doc you can find how to rebuild it only for specific list of and

`org.pytorch:pytorch_android_torchvision` - additional library with utility functions for converting `android.media.Image` and `android.graphics.Bitmap` to tensors.

#### 4. Reading static image from android asset
#### 4. Reading image from android asset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization "Reading Image from Android Asset"


All logic happens in [org.pytorch.helloworld.MainActivity](https://github.com/pytorch/android-demo-app/blob/master/HelloWorldApp/app/src/main/java/org/pytorch/helloworld/MainActivity.java#L31-L69).
All logic happens in [`org.pytorch.helloworld.MainActivity`](https://github.com/pytorch/android-demo-app/blob/master/HelloWorldApp/app/src/main/java/org/pytorch/helloworld/MainActivity.java#L31-L69).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"All [the] logic happens in ..."


All logic happens in [org.pytorch.helloworld.MainActivity](https://github.com/pytorch/android-demo-app/blob/master/HelloWorldApp/app/src/main/java/org/pytorch/helloworld/MainActivity.java#L31-L69).
All logic happens in [`org.pytorch.helloworld.MainActivity`](https://github.com/pytorch/android-demo-app/blob/master/HelloWorldApp/app/src/main/java/org/pytorch/helloworld/MainActivity.java#L31-L69).
As a first step we read `image.jpg` to `android.graphics.Bitmap` using standard android api.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"As a first step we read image.jpg to android.graphics.Bitmap using [the] standard [A]ndroid [API]."

@@ -90,13 +90,13 @@ Module module = Module.load(assetFilePath(this, "model.pt"));
Tensor inputTensor = TensorImageUtils.bitmapToFloat32Tensor(bitmap,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization " Preparing Input"

@@ -90,13 +90,13 @@ Module module = Module.load(assetFilePath(this, "model.pt"));
Tensor inputTensor = TensorImageUtils.bitmapToFloat32Tensor(bitmap,
TensorImageUtils.TORCHVISION_NORM_MEAN_RGB, TensorImageUtils.TORCHVISION_NORM_STD_RGB);
```
`org.pytorch.torchvision.TensorImageUtils` is part of 'org.pytorch:pytorch_android_torchvision' library.
`org.pytorch.torchvision.TensorImageUtils` is part of `org.pytorch:pytorch_android_torchvision` library.
`TensorImageUtils#bitmapToFloat32Tensor` method creates tensor in [torch vision format](https://pytorch.org/docs/stable/torchvision/models.html) using `android.graphics.Bitmap` as a source.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"[The] TensorImageUtils#bitmapToFloat32Tensor method creates tensor[s] in [the] [torchvision] format ..."

1. Builds libtorch for android for all 4 android abis (armeabi-v7a, arm64-v8a, x86, x86_64)
2. Creates symbolic links to the results of those builds:

1\. Builds libtorch for android for all 4 android abis (armeabi-v7a, arm64-v8a, x86, x86_64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change tenses:
"Builds..." --> "Build"
"Creates..." ---> "Create"
"runs..." ----> "run"

@@ -244,41 +248,38 @@ org.pytorch.Tensor

If the reader is familiar with pytorch python api, we can think that org.pytorch.Tensor represents torch.tensor, org.pytorch.Module torch.Module<?>, while org.pytorch.IValue represents value of TorchScript variable, supporting all its types. ( https://pytorch.org/docs/stable/jit.html#types )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Capitalization "pytorch python api" --> "PyTorch Python API"
  • Remove the <?> after Module
  • Remove spaces before and after parenthesis around the url

Revision:
"If the reader is familiar with [the PyTorch Python API], we can think [of] org.pytorch.Tensor [representing] torch.tensor, org.pytorch.Module [representing] torch.Module, [and] org.pytorch.IValue [representing the] of TorchScript [the] variable, supporting all its types.


Java’s primitive type byte is signed and java does not have unsigned 8 bit type. For dtype=uint8 api uses byte that will be reinterpretted as uint8 on native side. On java side unsigned value of byte can be read as (byte & 0xFF).
Java’s primitive type byte is signed and java does not have unsigned 8 bit type. For dtype=uint8 api uses byte that will be reinterpretted as uint8 on native side. On java side unsigned value of byte can be read as `byte & 0xFF`.

#### Tensor content layout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization "Tensor Content Layout"


IValue represents a TorchScript variable that can be one of the supported (by torchscript) types ( https://pytorch.org/docs/stable/jit.html#types ). IValue is a tagged union. For every supported type it has a factory method, method to check the type and a getter method to retrieve a value.
Getters throw IllegalStateException if called for inappropriate type.
IValue represents a TorchScript variable that can be one of the supported (by torchscript) types ( [https://pytorch.org/docs/stable/jit.html#types](https://pytorch.org/docs/stable/jit.html#types) ).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hyperlink to the word types
types


### org.pytorch.Module (Module)
[github](https://github.com/pytorch/pytorch/blob/master/android/pytorch_android/src/main/java/org/pytorch/Module.java)
### [`org.pytorch.Module`](https://github.com/pytorch/pytorch/blob/master/android/pytorch_android/src/main/java/org/pytorch/Module.java)

Module is a wrapper of torch.jit.ScriptModule (`torch::jit::script::Module` in pytorch c++ api) which can be constructed with factory method load providing absolute path to the file with serialized TorchScript.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization "PyTorch C++ API"
"... with [the] factory method"

@IvanKobzarev IvanKobzarev force-pushed the ik_android_tutorial_fixes_1007 branch from 47a50ad to b956376 Compare October 8, 2019 20:50
@@ -12,7 +12,7 @@ published: true

## Quick start with a HelloWorld example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling and Capitalization: "Quickstart with a HelloWorld Example"

@@ -12,7 +12,7 @@ published: true

## Quick start with a HelloWorld example

[HelloWorld](https://github.com/pytorch/android-demo-app/tree/master/HelloWorldApp) is a simple image classification application that demonstrates how to use PyTorch android api.
[HelloWorld](https://github.com/pytorch/android-demo-app/tree/master/HelloWorldApp) is a simple image classification application that demonstrates how to use PyTorch Android API.
This application runs TorchScript serialized TorchVision pretrained resnet18 model on static image which is packaged inside the app as android asset.

#### 1. Model preparation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization "Model Preparation"

@IvanKobzarev IvanKobzarev force-pushed the ik_android_tutorial_fixes_1007 branch from b956376 to 0f4b92a Compare October 8, 2019 21:32
@IvanKobzarev IvanKobzarev force-pushed the ik_android_tutorial_fixes_1007 branch from 0f4b92a to c3ac4d7 Compare October 8, 2019 22:09
@brucejlin1 brucejlin1 merged commit 06ab4d7 into pytorch:mobile-launch Oct 9, 2019
patmellon pushed a commit to shiftlab/pytorch.github.io that referenced this pull request Oct 9, 2019
…fixes_1007

[mobile][android] Tutorial corrections and aligning with the android api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants