keypadml 0.3.0__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {keypadml-0.3.0 → keypadml-0.3.2}/CHANGELOG.md +11 -1
- {keypadml-0.3.0 → keypadml-0.3.2}/CITATION.cff +1 -1
- {keypadml-0.3.0/src/keypadml.egg-info → keypadml-0.3.2}/PKG-INFO +36 -8
- {keypadml-0.3.0 → keypadml-0.3.2}/README.md +35 -7
- keypadml-0.3.2/src/keypadml/_version.py +1 -0
- {keypadml-0.3.0 → keypadml-0.3.2/src/keypadml.egg-info}/PKG-INFO +36 -8
- keypadml-0.3.0/src/keypadml/_version.py +0 -1
- {keypadml-0.3.0 → keypadml-0.3.2}/LICENSE +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/MANIFEST.in +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/benchmark-plan.md +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/benchmark-results.md +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/guide.md +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/logo.png +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/results-format.md +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/screenshots/nokia6210_pets.png +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/screenshots/nokia6600i_cifar10.png +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/screenshots/nokiac7_mnist.png +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/screenshots/nokiae72_fmnist.png +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/screenshots/results-page-cifar10.png +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/screenshots/results-page.png +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/screenshots/sonyericssonc902_pets.png +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/docs/try-it.md +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/examples/big_input.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/examples/cifar10_cnn.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/examples/mnist_lenet.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/desktop/kp/desktop/DesktopRun.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/desktop/kp/desktop/PhotoRun.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Bench.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/BenchMIDlet.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Camera.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Card.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Inputs.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Jpeg.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/MathX.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Net.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Ops.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Parts.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Photo.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/ResultsCanvas.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/Saver.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/java/phone/kp/TryIt.java +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/pyproject.toml +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/scripts/build_runtime.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/scripts/make_icon.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/setup.cfg +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/__init__.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/desktop/kp/desktop/DesktopRun$1.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/desktop/kp/desktop/DesktopRun.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/desktop/kp/desktop/PhotoRun$1.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/desktop/kp/desktop/PhotoRun.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/icon.png +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Bench$Listener.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Bench.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/BenchMIDlet$1.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/BenchMIDlet$2.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/BenchMIDlet$3.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/BenchMIDlet.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Camera.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Card$1.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Card.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Inputs.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Jpeg$Huffman.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Jpeg.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/MathX.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Net.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Ops.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Parts.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Photo$Rows.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Photo.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/ResultsCanvas.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/Saver.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$1.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$2.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$3.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$4.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$5.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$6.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$7.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$8.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$Files.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$Job.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt$Snapper.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/phone/kp/TryIt.class +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_tools.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/cli.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/convert.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/export.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/graph.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/jarfile.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/photo.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/py.typed +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/reference.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/report.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/runner.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/serialize.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml.egg-info/SOURCES.txt +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml.egg-info/dependency_links.txt +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml.egg-info/entry_points.txt +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml.egg-info/requires.txt +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml.egg-info/top_level.txt +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/__init__.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/conftest.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/data/nokia6600i_big256_parts.json +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/data/nokia6600i_big256_v0.3.json +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/data/nokia6600i_big288_parts.json +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/data/nokia6600i_cifar10_v0.3.json +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/data/nokia6600i_lenet_v0.1.txt +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/data/nokia6600i_lenet_v0.2.txt +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/data/nokia6600i_lenet_v0.3.json +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/test_models.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/test_photo.py +0 -0
- {keypadml-0.3.0 → keypadml-0.3.2}/tests/test_unit.py +0 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.3.
|
|
3
|
+
## 0.3.2 (2026-12-03)
|
|
4
|
+
|
|
5
|
+
* README: the quick-start example now makes a jar with Try it (camera and photos), trained on
|
|
6
|
+
dark-on-white digits so that a photo of a digit written on paper is read. No change to the library.
|
|
7
|
+
|
|
8
|
+
## 0.3.1 (2026-12-03)
|
|
9
|
+
|
|
10
|
+
* README: a complete quick-start example (MNIST, a small CNN, one epoch of training, export and
|
|
11
|
+
check on the PC), shorter overview, and links that work on PyPI. No change to the library.
|
|
12
|
+
|
|
13
|
+
## 0.3.0 (2026-12-03)
|
|
4
14
|
|
|
5
15
|
* **Benchmark results on real phones.** The 20 benchmark jars ran on a Nokia 6600i slide, 6210 Navigator,
|
|
6
16
|
E72 and C7; the results files are in `results/<phone model>/` and summarised in the README and
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: keypadml
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Run and benchmark PyTorch CNNs on old Java ME feature phones: export to a .jar, run it on the phone, check it against PyTorch.
|
|
5
5
|
Author: Said Ohamouddou
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -70,21 +70,49 @@ Optional: Java 8 or newer, to test a jar on your PC (`keypadml verify`) or in an
|
|
|
70
70
|
|
|
71
71
|
## Quick start
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
A complete example: dataset, CNN, training and export (needs `pip install keypadml torchvision`).
|
|
74
74
|
|
|
75
75
|
```python
|
|
76
|
+
import torch
|
|
77
|
+
import torch.nn as nn
|
|
78
|
+
import torch.nn.functional as F
|
|
79
|
+
from torchvision import datasets, transforms
|
|
76
80
|
import keypadml
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
# 1. Dataset: MNIST digits, inverted to dark ink on white, like a photo of a digit on paper
|
|
83
|
+
tf = transforms.Compose([transforms.ToTensor(), lambda t: 1 - t])
|
|
84
|
+
train = datasets.MNIST("data", train=True, download=True, transform=tf)
|
|
85
|
+
test = datasets.MNIST("data", train=False, download=True, transform=tf)
|
|
86
|
+
|
|
87
|
+
# 2. A small CNN: two conv blocks and a classifier
|
|
88
|
+
model = nn.Sequential(
|
|
89
|
+
nn.Conv2d(1, 8, 3, padding=1), nn.ReLU(), nn.MaxPool2d(2), # 8 x 14 x 14
|
|
90
|
+
nn.Conv2d(8, 16, 3, padding=1), nn.ReLU(), nn.MaxPool2d(2), # 16 x 7 x 7
|
|
91
|
+
nn.Flatten(), nn.Linear(16 * 7 * 7, 10),
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# 3. Train for one epoch (a few seconds on a CPU)
|
|
95
|
+
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
|
|
96
|
+
for x, y in torch.utils.data.DataLoader(train, batch_size=64, shuffle=True):
|
|
97
|
+
opt.zero_grad()
|
|
98
|
+
F.cross_entropy(model(x), y).backward()
|
|
99
|
+
opt.step()
|
|
100
|
+
|
|
101
|
+
# 4. Export the model with 20 test digits to bench/MNIST.jar
|
|
102
|
+
inputs, labels = keypadml.sample(test, n=20)
|
|
103
|
+
result = keypadml.export(model.eval(), inputs, labels, out_dir="bench", name="MNIST",
|
|
104
|
+
class_names=[str(d) for d in range(10)],
|
|
105
|
+
photo=dict(mean=[0.0], std=[1.0])) # Try it: camera and photos
|
|
80
106
|
print(result) # jar size, parameters, multiply-adds, memory estimate
|
|
81
|
-
keypadml.verify(result) # optional: run the phone's code on this PC
|
|
107
|
+
keypadml.verify(result) # optional (needs Java): run the phone's code on this PC
|
|
82
108
|
```
|
|
83
109
|
|
|
84
|
-
**
|
|
85
|
-
|
|
110
|
+
**Run it on the phone.** Copy `bench/MNIST.jar` to the phone, open it and press **Start**. The
|
|
111
|
+
results are saved on the memory card in `keypadml/<phone model>/`. Then choose **Try it: camera** and
|
|
112
|
+
photograph a digit written large with a dark pen on white paper, filling the middle of the picture:
|
|
113
|
+
the phone shows the digit it reads.
|
|
86
114
|
|
|
87
|
-
**
|
|
115
|
+
**Read the report** on your computer. Here is a real Nokia 6600i run of a LeNet (shortened):
|
|
88
116
|
|
|
89
117
|
```text
|
|
90
118
|
$ keypadml report kp_LeNet_123456.json --ref bench
|
|
@@ -42,21 +42,49 @@ Optional: Java 8 or newer, to test a jar on your PC (`keypadml verify`) or in an
|
|
|
42
42
|
|
|
43
43
|
## Quick start
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
A complete example: dataset, CNN, training and export (needs `pip install keypadml torchvision`).
|
|
46
46
|
|
|
47
47
|
```python
|
|
48
|
+
import torch
|
|
49
|
+
import torch.nn as nn
|
|
50
|
+
import torch.nn.functional as F
|
|
51
|
+
from torchvision import datasets, transforms
|
|
48
52
|
import keypadml
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
# 1. Dataset: MNIST digits, inverted to dark ink on white, like a photo of a digit on paper
|
|
55
|
+
tf = transforms.Compose([transforms.ToTensor(), lambda t: 1 - t])
|
|
56
|
+
train = datasets.MNIST("data", train=True, download=True, transform=tf)
|
|
57
|
+
test = datasets.MNIST("data", train=False, download=True, transform=tf)
|
|
58
|
+
|
|
59
|
+
# 2. A small CNN: two conv blocks and a classifier
|
|
60
|
+
model = nn.Sequential(
|
|
61
|
+
nn.Conv2d(1, 8, 3, padding=1), nn.ReLU(), nn.MaxPool2d(2), # 8 x 14 x 14
|
|
62
|
+
nn.Conv2d(8, 16, 3, padding=1), nn.ReLU(), nn.MaxPool2d(2), # 16 x 7 x 7
|
|
63
|
+
nn.Flatten(), nn.Linear(16 * 7 * 7, 10),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# 3. Train for one epoch (a few seconds on a CPU)
|
|
67
|
+
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
|
|
68
|
+
for x, y in torch.utils.data.DataLoader(train, batch_size=64, shuffle=True):
|
|
69
|
+
opt.zero_grad()
|
|
70
|
+
F.cross_entropy(model(x), y).backward()
|
|
71
|
+
opt.step()
|
|
72
|
+
|
|
73
|
+
# 4. Export the model with 20 test digits to bench/MNIST.jar
|
|
74
|
+
inputs, labels = keypadml.sample(test, n=20)
|
|
75
|
+
result = keypadml.export(model.eval(), inputs, labels, out_dir="bench", name="MNIST",
|
|
76
|
+
class_names=[str(d) for d in range(10)],
|
|
77
|
+
photo=dict(mean=[0.0], std=[1.0])) # Try it: camera and photos
|
|
52
78
|
print(result) # jar size, parameters, multiply-adds, memory estimate
|
|
53
|
-
keypadml.verify(result) # optional: run the phone's code on this PC
|
|
79
|
+
keypadml.verify(result) # optional (needs Java): run the phone's code on this PC
|
|
54
80
|
```
|
|
55
81
|
|
|
56
|
-
**
|
|
57
|
-
|
|
82
|
+
**Run it on the phone.** Copy `bench/MNIST.jar` to the phone, open it and press **Start**. The
|
|
83
|
+
results are saved on the memory card in `keypadml/<phone model>/`. Then choose **Try it: camera** and
|
|
84
|
+
photograph a digit written large with a dark pen on white paper, filling the middle of the picture:
|
|
85
|
+
the phone shows the digit it reads.
|
|
58
86
|
|
|
59
|
-
**
|
|
87
|
+
**Read the report** on your computer. Here is a real Nokia 6600i run of a LeNet (shortened):
|
|
60
88
|
|
|
61
89
|
```text
|
|
62
90
|
$ keypadml report kp_LeNet_123456.json --ref bench
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.2"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: keypadml
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Run and benchmark PyTorch CNNs on old Java ME feature phones: export to a .jar, run it on the phone, check it against PyTorch.
|
|
5
5
|
Author: Said Ohamouddou
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -70,21 +70,49 @@ Optional: Java 8 or newer, to test a jar on your PC (`keypadml verify`) or in an
|
|
|
70
70
|
|
|
71
71
|
## Quick start
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
A complete example: dataset, CNN, training and export (needs `pip install keypadml torchvision`).
|
|
74
74
|
|
|
75
75
|
```python
|
|
76
|
+
import torch
|
|
77
|
+
import torch.nn as nn
|
|
78
|
+
import torch.nn.functional as F
|
|
79
|
+
from torchvision import datasets, transforms
|
|
76
80
|
import keypadml
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
# 1. Dataset: MNIST digits, inverted to dark ink on white, like a photo of a digit on paper
|
|
83
|
+
tf = transforms.Compose([transforms.ToTensor(), lambda t: 1 - t])
|
|
84
|
+
train = datasets.MNIST("data", train=True, download=True, transform=tf)
|
|
85
|
+
test = datasets.MNIST("data", train=False, download=True, transform=tf)
|
|
86
|
+
|
|
87
|
+
# 2. A small CNN: two conv blocks and a classifier
|
|
88
|
+
model = nn.Sequential(
|
|
89
|
+
nn.Conv2d(1, 8, 3, padding=1), nn.ReLU(), nn.MaxPool2d(2), # 8 x 14 x 14
|
|
90
|
+
nn.Conv2d(8, 16, 3, padding=1), nn.ReLU(), nn.MaxPool2d(2), # 16 x 7 x 7
|
|
91
|
+
nn.Flatten(), nn.Linear(16 * 7 * 7, 10),
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# 3. Train for one epoch (a few seconds on a CPU)
|
|
95
|
+
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
|
|
96
|
+
for x, y in torch.utils.data.DataLoader(train, batch_size=64, shuffle=True):
|
|
97
|
+
opt.zero_grad()
|
|
98
|
+
F.cross_entropy(model(x), y).backward()
|
|
99
|
+
opt.step()
|
|
100
|
+
|
|
101
|
+
# 4. Export the model with 20 test digits to bench/MNIST.jar
|
|
102
|
+
inputs, labels = keypadml.sample(test, n=20)
|
|
103
|
+
result = keypadml.export(model.eval(), inputs, labels, out_dir="bench", name="MNIST",
|
|
104
|
+
class_names=[str(d) for d in range(10)],
|
|
105
|
+
photo=dict(mean=[0.0], std=[1.0])) # Try it: camera and photos
|
|
80
106
|
print(result) # jar size, parameters, multiply-adds, memory estimate
|
|
81
|
-
keypadml.verify(result) # optional: run the phone's code on this PC
|
|
107
|
+
keypadml.verify(result) # optional (needs Java): run the phone's code on this PC
|
|
82
108
|
```
|
|
83
109
|
|
|
84
|
-
**
|
|
85
|
-
|
|
110
|
+
**Run it on the phone.** Copy `bench/MNIST.jar` to the phone, open it and press **Start**. The
|
|
111
|
+
results are saved on the memory card in `keypadml/<phone model>/`. Then choose **Try it: camera** and
|
|
112
|
+
photograph a digit written large with a dark pen on white paper, filling the middle of the picture:
|
|
113
|
+
the phone shows the digit it reads.
|
|
86
114
|
|
|
87
|
-
**
|
|
115
|
+
**Read the report** on your computer. Here is a real Nokia 6600i run of a LeNet (shortened):
|
|
88
116
|
|
|
89
117
|
```text
|
|
90
118
|
$ keypadml report kp_LeNet_123456.json --ref bench
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.3.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{keypadml-0.3.0 → keypadml-0.3.2}/src/keypadml/_runtime/desktop/kp/desktop/DesktopRun$1.class
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|