keypadml 0.3.0__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.
Files changed (111) hide show
  1. keypadml-0.3.0/CHANGELOG.md +102 -0
  2. keypadml-0.3.0/CITATION.cff +8 -0
  3. keypadml-0.3.0/LICENSE +202 -0
  4. keypadml-0.3.0/MANIFEST.in +6 -0
  5. keypadml-0.3.0/PKG-INFO +155 -0
  6. keypadml-0.3.0/README.md +127 -0
  7. keypadml-0.3.0/docs/benchmark-plan.md +75 -0
  8. keypadml-0.3.0/docs/benchmark-results.md +71 -0
  9. keypadml-0.3.0/docs/guide.md +259 -0
  10. keypadml-0.3.0/docs/logo.png +0 -0
  11. keypadml-0.3.0/docs/results-format.md +136 -0
  12. keypadml-0.3.0/docs/screenshots/nokia6210_pets.png +0 -0
  13. keypadml-0.3.0/docs/screenshots/nokia6600i_cifar10.png +0 -0
  14. keypadml-0.3.0/docs/screenshots/nokiac7_mnist.png +0 -0
  15. keypadml-0.3.0/docs/screenshots/nokiae72_fmnist.png +0 -0
  16. keypadml-0.3.0/docs/screenshots/results-page-cifar10.png +0 -0
  17. keypadml-0.3.0/docs/screenshots/results-page.png +0 -0
  18. keypadml-0.3.0/docs/screenshots/sonyericssonc902_pets.png +0 -0
  19. keypadml-0.3.0/docs/try-it.md +43 -0
  20. keypadml-0.3.0/examples/big_input.py +113 -0
  21. keypadml-0.3.0/examples/cifar10_cnn.py +105 -0
  22. keypadml-0.3.0/examples/mnist_lenet.py +77 -0
  23. keypadml-0.3.0/java/desktop/kp/desktop/DesktopRun.java +53 -0
  24. keypadml-0.3.0/java/desktop/kp/desktop/PhotoRun.java +110 -0
  25. keypadml-0.3.0/java/phone/kp/Bench.java +546 -0
  26. keypadml-0.3.0/java/phone/kp/BenchMIDlet.java +215 -0
  27. keypadml-0.3.0/java/phone/kp/Camera.java +58 -0
  28. keypadml-0.3.0/java/phone/kp/Card.java +98 -0
  29. keypadml-0.3.0/java/phone/kp/Inputs.java +106 -0
  30. keypadml-0.3.0/java/phone/kp/Jpeg.java +518 -0
  31. keypadml-0.3.0/java/phone/kp/MathX.java +93 -0
  32. keypadml-0.3.0/java/phone/kp/Net.java +223 -0
  33. keypadml-0.3.0/java/phone/kp/Ops.java +286 -0
  34. keypadml-0.3.0/java/phone/kp/Parts.java +64 -0
  35. keypadml-0.3.0/java/phone/kp/Photo.java +158 -0
  36. keypadml-0.3.0/java/phone/kp/ResultsCanvas.java +357 -0
  37. keypadml-0.3.0/java/phone/kp/Saver.java +119 -0
  38. keypadml-0.3.0/java/phone/kp/TryIt.java +706 -0
  39. keypadml-0.3.0/pyproject.toml +51 -0
  40. keypadml-0.3.0/scripts/build_runtime.py +98 -0
  41. keypadml-0.3.0/scripts/make_icon.py +106 -0
  42. keypadml-0.3.0/setup.cfg +4 -0
  43. keypadml-0.3.0/src/keypadml/__init__.py +20 -0
  44. keypadml-0.3.0/src/keypadml/_runtime/desktop/kp/desktop/DesktopRun$1.class +0 -0
  45. keypadml-0.3.0/src/keypadml/_runtime/desktop/kp/desktop/DesktopRun.class +0 -0
  46. keypadml-0.3.0/src/keypadml/_runtime/desktop/kp/desktop/PhotoRun$1.class +0 -0
  47. keypadml-0.3.0/src/keypadml/_runtime/desktop/kp/desktop/PhotoRun.class +0 -0
  48. keypadml-0.3.0/src/keypadml/_runtime/icon.png +0 -0
  49. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Bench$Listener.class +0 -0
  50. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Bench.class +0 -0
  51. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/BenchMIDlet$1.class +0 -0
  52. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/BenchMIDlet$2.class +0 -0
  53. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/BenchMIDlet$3.class +0 -0
  54. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/BenchMIDlet.class +0 -0
  55. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Camera.class +0 -0
  56. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Card$1.class +0 -0
  57. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Card.class +0 -0
  58. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Inputs.class +0 -0
  59. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Jpeg$Huffman.class +0 -0
  60. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Jpeg.class +0 -0
  61. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/MathX.class +0 -0
  62. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Net.class +0 -0
  63. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Ops.class +0 -0
  64. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Parts.class +0 -0
  65. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Photo$Rows.class +0 -0
  66. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Photo.class +0 -0
  67. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/ResultsCanvas.class +0 -0
  68. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/Saver.class +0 -0
  69. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$1.class +0 -0
  70. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$2.class +0 -0
  71. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$3.class +0 -0
  72. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$4.class +0 -0
  73. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$5.class +0 -0
  74. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$6.class +0 -0
  75. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$7.class +0 -0
  76. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$8.class +0 -0
  77. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$Files.class +0 -0
  78. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$Job.class +0 -0
  79. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt$Snapper.class +0 -0
  80. keypadml-0.3.0/src/keypadml/_runtime/phone/kp/TryIt.class +0 -0
  81. keypadml-0.3.0/src/keypadml/_tools.py +88 -0
  82. keypadml-0.3.0/src/keypadml/_version.py +1 -0
  83. keypadml-0.3.0/src/keypadml/cli.py +69 -0
  84. keypadml-0.3.0/src/keypadml/convert.py +576 -0
  85. keypadml-0.3.0/src/keypadml/export.py +311 -0
  86. keypadml-0.3.0/src/keypadml/graph.py +211 -0
  87. keypadml-0.3.0/src/keypadml/jarfile.py +68 -0
  88. keypadml-0.3.0/src/keypadml/photo.py +80 -0
  89. keypadml-0.3.0/src/keypadml/py.typed +0 -0
  90. keypadml-0.3.0/src/keypadml/reference.py +109 -0
  91. keypadml-0.3.0/src/keypadml/report.py +433 -0
  92. keypadml-0.3.0/src/keypadml/runner.py +111 -0
  93. keypadml-0.3.0/src/keypadml/serialize.py +228 -0
  94. keypadml-0.3.0/src/keypadml.egg-info/PKG-INFO +155 -0
  95. keypadml-0.3.0/src/keypadml.egg-info/SOURCES.txt +109 -0
  96. keypadml-0.3.0/src/keypadml.egg-info/dependency_links.txt +1 -0
  97. keypadml-0.3.0/src/keypadml.egg-info/entry_points.txt +2 -0
  98. keypadml-0.3.0/src/keypadml.egg-info/requires.txt +6 -0
  99. keypadml-0.3.0/src/keypadml.egg-info/top_level.txt +1 -0
  100. keypadml-0.3.0/tests/__init__.py +0 -0
  101. keypadml-0.3.0/tests/conftest.py +39 -0
  102. keypadml-0.3.0/tests/data/nokia6600i_big256_parts.json +51 -0
  103. keypadml-0.3.0/tests/data/nokia6600i_big256_v0.3.json +50 -0
  104. keypadml-0.3.0/tests/data/nokia6600i_big288_parts.json +51 -0
  105. keypadml-0.3.0/tests/data/nokia6600i_cifar10_v0.3.json +146 -0
  106. keypadml-0.3.0/tests/data/nokia6600i_lenet_v0.1.txt +235 -0
  107. keypadml-0.3.0/tests/data/nokia6600i_lenet_v0.2.txt +238 -0
  108. keypadml-0.3.0/tests/data/nokia6600i_lenet_v0.3.json +246 -0
  109. keypadml-0.3.0/tests/test_models.py +224 -0
  110. keypadml-0.3.0/tests/test_photo.py +273 -0
  111. keypadml-0.3.0/tests/test_unit.py +613 -0
@@ -0,0 +1,102 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 (unreleased)
4
+
5
+ * **Benchmark results on real phones.** The 20 benchmark jars ran on a Nokia 6600i slide, 6210 Navigator,
6
+ E72 and C7; the results files are in `results/<phone model>/` and summarised in the README and
7
+ `docs/benchmark-results.md`.
8
+ * **New name: keypadml** (was retrobench, a name other projects use). The package, the command and
9
+ the import are `keypadml`; the jar's classes are in package `kp`; files are saved as
10
+ `kp_<name>_<n>.json` in `keypadml/<phone model>/` on the memory card, with the format
11
+ `"keypadml-results"`. Files from jars made under the earlier name (`rb_*.json`, `rb_*.txt`,
12
+ `"retrobench-results"`) are still read.
13
+ * **Far too big models are refused.** When the memory estimate is more than twice the limit of old
14
+ phones (about 3.7 MB), `export()` raises `ModelTooBigError` (saying whether the weights or the
15
+ activations are too big) and writes no files; `force=True` builds the jar anyway. Between the limit
16
+ and twice it, it warns as before.
17
+ * **One folder per phone.** Results files and Try it logs are saved in `keypadml/<phone model>/` on
18
+ the memory card (the model as the phone names itself, e.g. `Nokia6600i-1c`), so one card can collect
19
+ several phones' results. `export(..., phone_folder=False)` keeps the old place, the top of the card.
20
+ * **Try it: the camera and photos.** `export(..., photo=dict(mean=..., std=...))` lets an image model's
21
+ jar classify a camera snapshot or a photo from the memory card after the benchmark, showing the top
22
+ classes, what the model saw and how long it took. Memory is checked before every picture. The phone's
23
+ preparation is reproduced exactly by the new `keypadml.prepare_photo`. Camera and file code is
24
+ loaded only when used, so phones without JSR-135 or JSR-75 still run the benchmark. Tested on a
25
+ Nokia 6600i (`capture://image`, `encoding=image/jpeg`): 14.6 s from Snap to the answer with a CIFAR-10
26
+ ResNet-8.
27
+ Photos too big to open whole (camera photos of several megapixels) are read from their EXIF thumbnail,
28
+ or by keypadml's own JPEG decoder at 1/2, 1/4 or 1/8 size (`java/phone/kp/Jpeg.java`), which holds
29
+ one row of blocks at a time. Each try is saved as `kp_<name>_try_<n>.json`.
30
+ * **Loading takes about half the memory.** Some phones (Nokia 6600i) hold an opened jar file whole in
31
+ the Java heap, so loading needed the weights twice. The jar now stores `model.bin`, `inputs.bin` and
32
+ `ref.bin` in 32 KB parts, opened one at a time. The data itself and the model ids are unchanged.
33
+ `load_ms` now includes opening the model, so it cannot be compared with older jars, and `verify`
34
+ runs only the new layout. The example jars are rebuilt with the same models and inputs. On a Nokia
35
+ 6600i the largest float32 model that ran went from 230,348 to 486,306 weights.
36
+ * **Memory estimate.** `export()` now counts the PC's outputs and the results text, warns above
37
+ 1.9 MB (was 1.5), and its warning says whether the weights or the activations are too big. The out-of-memory message on the
38
+ phone and the jar-size warning are corrected too (a Nokia 6600i installs 4 MB).
39
+ * **Report: memory.** When the heap growth can't be the model's, the report shows the heap in use after
40
+ loading. This works for existing results files: it was "NOT MEASURABLE" before.
41
+ * **Report: the ± of the mean was too small.** It came from the per-input medians, which hide the
42
+ phone's pauses (LeNet on a Nokia 6600i: ± 0.2 ms, now ± 3.1 ms). Medians are unchanged.
43
+ * **Faster convolutions, same results.** The general convolution applies each weight along output rows
44
+ ("weight-stationary"); every output adds the same terms in the same order, so outputs are bit for bit
45
+ the same (150 random networks and all example jars). On a PC in interpreter mode it takes 10-32% less
46
+ time (LeNet, CIFAR-10, Pets 304). Times measured with earlier jars can't be compared with new ones.
47
+ The 1x1 convolution no longer skips zero weights, so speed no longer depends on weight values.
48
+ * Clean-up: unused fields and QR-code leftovers removed; one parity constant and one memory line on the
49
+ phone; weights and reference freed before the results text; phone classes built without debug data
50
+ (about 9% smaller); `export.json` no longer has `torch_accuracy_float_inputs`.
51
+ * `benchmarks/pets.py`: trains and exports the Pets jars of `docs/benchmark-plan.md`.
52
+ * **Parity limit 1e-5** (was 1e-3): a single wrong weight in LeNet gave 7e-4 and passed. Correct runs on a
53
+ Nokia 6600i give about 1e-6 or less.
54
+ * README: how to choose the image size and the number of inputs.
55
+ * **Results page on the phone.** When the run ends the phone shows the main numbers (top-1,
56
+ median and first-run time, parity, memory) and the test inputs as small pictures with the
57
+ model's answer: green when right, red (true class in brackets) when wrong. Left/right pages
58
+ through the inputs; non-image inputs are listed as text. `export(class_names=[...])` shows
59
+ names instead of class numbers.
60
+ * **JSON results file.** The phone saves `kp_<name>_<n>.json` (results format version 2,
61
+ `docs/results-format.md`). `keypadml report` reads it and still reads the `.txt` files of
62
+ 0.1–0.2 jars.
63
+ * **QR codes removed** (phone QR pages, `keypadml scan`, the `scan` extra and OpenCV). The jar's
64
+ runtime is about 7 KB smaller.
65
+ * **`keypadml emulate` shows the real layout.** MicroEmulator's `--resizableDevice` kept the
66
+ app's drawing area at 176×176; emulate now makes a device profile of the requested size.
67
+ * `bench.cfg` carries `input_shape`, so the phone knows the inputs are images.
68
+ * **CIFAR-10 example** (`examples/cifar10_cnn.py`): a small colour-photo CNN (2.8 M multiply-adds,
69
+ 77.9% on the CIFAR-10 test set) exported with its class names.
70
+ * **Single big images.** With one input the results page shows it large, with the five most likely
71
+ classes and their probabilities. `export()` says how many inputs fit, or that even one does not.
72
+ * The results page, the phone's summary, the JSON file and `keypadml report` show the input
73
+ shape and batch size (e.g. `Input 3x32x32, batch 1, 50 x 3 runs`).
74
+ * **Less memory for big inputs.** The phone writes each input straight into the network's input
75
+ buffer instead of copying it in (4 bytes per input value saved, and the copy is no longer timed);
76
+ the export's heap estimate now matches what the phone needs.
77
+ * **Big-input example** (`examples/big_input.py`): one 256 × 256 colour photo, with a
78
+ stride-4 first layer; `--sizes 256 288` adds a bigger one.
79
+ * **Logo.** A pixel-art icon (an old phone with a benchmark chart on its screen) in every jar:
80
+ shown in the phone's app menu and on the start screen. `scripts/make_icon.py` draws it.
81
+
82
+ ## 0.2.0 (unreleased)
83
+
84
+ From the first run on a real Nokia 6600i slide:
85
+ * **Clean timings.** 0.1 jars updated the progress screen every 4 inputs; the phone redrew it in the
86
+ background *during the next timed run* (+60 ms there, and ~300-700 ms pauses about every 11 s).
87
+ Now the screen is updated at most every 5 s, only between timed runs, and the benchmark waits
88
+ for the redraw and collects garbage before timing resumes. Results files say `timing=isolated`;
89
+ `retrobench report` adds a note to files from older jars.
90
+ * **Memory.** Some phones (Series 40) report heap figures that cannot hold the model. The phone
91
+ now also writes the least the model + inputs can take (`heap_model_min_bytes`); when the
92
+ measurement is below it, the phone and `retrobench report` say "not measurable" and show the
93
+ lower bound and the export's estimate instead of a wrong number.
94
+ * QR data pages carry both (older pages still decode).
95
+
96
+ ## 0.1.0 (unreleased)
97
+
98
+ First version: `export`, `verify`, `emulate`, `report`, `sample`; CLI `retrobench report | verify | emulate | info`.
99
+ Conv/linear/BatchNorm/activation/pooling/residual/concat/squeeze-excitation support; float32 or int8 weights;
100
+ uint8 or float32 inputs; per-layer timing; parity check against a float64 reference.
101
+ Results as QR codes on the phone (plain-text summary + complete data pages), `retrobench scan`
102
+ (webcam, images or scanned texts), and an on-phone parity check against reference outputs embedded in the jar.
@@ -0,0 +1,8 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use keypadml in your research, please cite it."
3
+ title: "keypadml: benchmarking PyTorch CNNs on legacy Java ME phones"
4
+ type: software
5
+ authors:
6
+ - name: "Said Ohamouddou"
7
+ license: Apache-2.0
8
+ version: 0.3.0
keypadml-0.3.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ include LICENSE README.md CHANGELOG.md CITATION.cff
2
+ recursive-include java *.java
3
+ recursive-include scripts *.py
4
+ recursive-include docs *.md *.png
5
+ recursive-include examples *.py
6
+ recursive-include tests *.py *.json *.txt
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: keypadml
3
+ Version: 0.3.0
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
+ Author: Said Ohamouddou
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/said-ohamouddou/padkeml
8
+ Project-URL: Documentation, https://github.com/said-ohamouddou/padkeml/blob/main/docs/guide.md
9
+ Project-URL: Issues, https://github.com/said-ohamouddou/padkeml/issues
10
+ Project-URL: Changelog, https://github.com/said-ohamouddou/padkeml/blob/main/CHANGELOG.md
11
+ Keywords: pytorch,benchmark,edge ai,tinyml,java me,midp,cldc,mobile,inference
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Java
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: Topic :: System :: Benchmark
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: torch>=1.13
23
+ Requires-Dist: numpy>=1.21
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest>=7; extra == "test"
26
+ Requires-Dist: torchvision>=0.14; extra == "test"
27
+ Dynamic: license-file
28
+
29
+ <p align="center">
30
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/logo.png" width="138" alt="keypadml logo: a pixel-art feature phone whose green screen shows a rising bar chart">
31
+ </p>
32
+
33
+ <h1 align="center">keypadml</h1>
34
+
35
+ <p align="center"><b>Run and benchmark PyTorch CNNs on old Java ME feature phones.</b></p>
36
+
37
+ <p align="center">
38
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/nokia6600i_cifar10.png" height="300"
39
+ alt="Nokia 6600i slide showing the results page of a CIFAR-10 ResNet-8: top-1 95%, median 8389 ms, parity OK, and eight test photos with their predicted classes">
40
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/nokia6210_pets.png" height="300"
41
+ alt="Nokia 6210 Navigator showing the results page of a cat-or-dog network at 88 by 88 pixels: a dog photo predicted as dog with 92%, median 1248 ms, parity OK">
42
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/sonyericssonc902_pets.png" height="300"
43
+ alt="Sony Ericsson C902 showing the results page of a cat-or-dog network at 96 by 96 pixels: a dog photo predicted as dog with 91%, median 6119 ms, parity OK">
44
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/nokiae72_fmnist.png" height="300"
45
+ alt="Nokia E72 showing the results page of a Fashion-MNIST LeNet: top-1 90%, median 121 ms, parity OK, and four clothing images with their predicted classes">
46
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/nokiac7_mnist.png" height="300"
47
+ alt="Nokia C7 showing the results page of an MNIST LeNet: top-1 100%, median 95 ms, parity OK, and four handwritten digits with their predicted classes">
48
+ </p>
49
+ <p align="center"><sub>Nokia 6600i slide · Nokia 6210 Navigator · Sony Ericsson C902 · Nokia E72 · Nokia C7</sub></p>
50
+
51
+ keypadml turns a PyTorch model and a few test inputs into a `.jar` file for any phone with
52
+ **CLDC 1.1 and MIDP 2.0** (Nokia Series 40 and S60, Sony Ericsson, Samsung, …). On the phone, the app:
53
+
54
+ - runs the model on every input and **times** each run;
55
+ - **checks** that its outputs match PyTorch's;
56
+ - shows the results on screen and **saves** them as a JSON file.
57
+
58
+ Back on your computer, `keypadml report` gives you latency, accuracy, memory, per-layer times
59
+ and the parity check. No Java toolkit is needed: the jar contains a small precompiled
60
+ interpreter, and your model travels inside it as data.
61
+
62
+ ## Install
63
+
64
+ ```bash
65
+ pip install keypadml # Python 3.9+, PyTorch 1.13+
66
+ ```
67
+
68
+ Optional: Java 8 or newer, to test a jar on your PC (`keypadml verify`) or in an emulator
69
+ (`keypadml emulate`).
70
+
71
+ ## Quick start
72
+
73
+ **1. Export** your model with a few test inputs:
74
+
75
+ ```python
76
+ import keypadml
77
+
78
+ inputs, labels = keypadml.sample(test_dataset, n=50)
79
+ result = keypadml.export(model, inputs, labels, out_dir="bench", name="LeNet")
80
+ print(result) # jar size, parameters, multiply-adds, memory estimate
81
+ keypadml.verify(result) # optional: run the phone's code on this PC
82
+ ```
83
+
84
+ **2. Run on the phone.** Copy `bench/LeNet.jar` to the phone, open it and press **Start**.
85
+ The results are saved on the memory card in `keypadml/<phone model>/`.
86
+
87
+ **3. Read the report** on your computer (a real Nokia 6600i run, shortened):
88
+
89
+ ```text
90
+ $ keypadml report kp_LeNet_123456.json --ref bench
91
+
92
+ keypadml report: LeNet (model id 554f28fb7a9d)
93
+ device Nokia6600i-1c/36.16 [CLDC-1.1, MIDP-2.1]
94
+ workload 100 inputs x 5 runs (+2 warm-up), input 1x28x28, batch 1, 61,706 parameters
95
+ accuracy top-1 97.00%, top-5 100.00% (PyTorch on the PC: 97.00%)
96
+ latency median 321.0 ms, mean 325.2 ± 3.1 ms (95% CI), min 317, p90 324, max 772 ms
97
+ first run 343 ms, model load 122 ms, 3.07 inputs/s
98
+ memory heap 2048 KB, 364 KB in use after loading
99
+ parity OK: max relative difference 2.6e-07, same top-1 as PyTorch 100%
100
+ slowest layers (ms per run):
101
+ 183.00 57.4% conv conv2 1.31 MMAC/s
102
+ 93.00 29.2% conv conv1 1.26 MMAC/s
103
+ ```
104
+
105
+ ## Results on real phones
106
+
107
+ The same 20 benchmark jars ran on four phones. Median time per input:
108
+
109
+ | Phone | MNIST LeNet | Keyword spotting | CIFAR-10 ResNet-8 | Pets 304 px | Speed (M multiply-adds/s) |
110
+ |---|---:|---:|---:|---:|---:|
111
+ | Nokia 6600i slide (2008) | 303 ms | 1.89 s | 8.39 s | 40.8 s | 1.41 |
112
+ | Nokia 6210 Navigator (2008) | 417 ms | 2.68 s | 12.0 s | 61.7 s | 0.94 |
113
+ | Nokia E72 (2009) | 121 ms | 743 ms | 3.50 s | 16.6 s | 3.47 |
114
+ | Nokia C7 (2010) | 96 ms | 573 ms | 2.71 s | 13.0 s | 4.43 |
115
+
116
+ - **Every run matched PyTorch:** all 80 runs gave the same top-1 class, with outputs within 7.2e-6.
117
+ - **Time follows multiply-adds:** each phone has one speed, so you can predict a model's time before
118
+ installing it.
119
+ - **Memory is the limit:** a 2 MB heap fits colour images up to about 300 × 300.
120
+
121
+ Full tables (image size, five architectures, nine tasks): [docs/benchmark-results.md](https://github.com/said-ohamouddou/padkeml/blob/main/docs/benchmark-results.md).
122
+ Raw files: [`results/`](https://github.com/said-ohamouddou/padkeml/tree/main/results/).
123
+
124
+ ## Features
125
+
126
+ - **Supported layers:** convolutions (including depthwise), linear, batch norm (folded), pooling,
127
+ residual additions, concatenation, squeeze-excitation and common activations. Tested with LeNet,
128
+ ResNet, MobileNet V2/V3, SqueezeNet and EfficientNet-B0.
129
+ - **Memory check before you install:** `export()` estimates the phone's memory, warns above 1.9 MB
130
+ and refuses models that need more than twice that.
131
+ - **Results page on the phone:** test inputs as pictures with the predicted class, green when right
132
+ and red when wrong.
133
+ - **Try it:** image models can also classify a **camera snapshot** or a **photo** from the memory card.
134
+ See [docs/try-it.md](https://github.com/said-ohamouddou/padkeml/blob/main/docs/try-it.md).
135
+
136
+ ## Documentation
137
+
138
+ | | |
139
+ |---|---|
140
+ | [User guide](https://github.com/said-ohamouddou/padkeml/blob/main/docs/guide.md) | Workflow, examples, export options, supported models, choosing image size and number of inputs, limits of old phones |
141
+ | [Try it](https://github.com/said-ohamouddou/padkeml/blob/main/docs/try-it.md) | Camera and photo mode |
142
+ | [Benchmark results](https://github.com/said-ohamouddou/padkeml/blob/main/docs/benchmark-results.md) | All results on the four phones |
143
+ | [Benchmark plan](https://github.com/said-ohamouddou/padkeml/blob/main/docs/benchmark-plan.md) | How the 20 benchmark jars were made and run |
144
+ | [Results file format](https://github.com/said-ohamouddou/padkeml/blob/main/docs/results-format.md) | The JSON file the phone saves |
145
+
146
+ ## Licence
147
+
148
+ Apache-2.0. `keypadml emulate` downloads MicroEmulator on first use, and the runtime build script
149
+ downloads ProGuard and the CLDC/MIDP API jars; none of them is bundled. Jars you export contain your
150
+ model's weights and inputs, so check their licences before sharing them. "Java" and other names are
151
+ trademarks of their owners.
152
+
153
+ ## Citing
154
+
155
+ See [`CITATION.cff`](https://github.com/said-ohamouddou/padkeml/blob/main/CITATION.cff).
@@ -0,0 +1,127 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/logo.png" width="138" alt="keypadml logo: a pixel-art feature phone whose green screen shows a rising bar chart">
3
+ </p>
4
+
5
+ <h1 align="center">keypadml</h1>
6
+
7
+ <p align="center"><b>Run and benchmark PyTorch CNNs on old Java ME feature phones.</b></p>
8
+
9
+ <p align="center">
10
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/nokia6600i_cifar10.png" height="300"
11
+ alt="Nokia 6600i slide showing the results page of a CIFAR-10 ResNet-8: top-1 95%, median 8389 ms, parity OK, and eight test photos with their predicted classes">
12
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/nokia6210_pets.png" height="300"
13
+ alt="Nokia 6210 Navigator showing the results page of a cat-or-dog network at 88 by 88 pixels: a dog photo predicted as dog with 92%, median 1248 ms, parity OK">
14
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/sonyericssonc902_pets.png" height="300"
15
+ alt="Sony Ericsson C902 showing the results page of a cat-or-dog network at 96 by 96 pixels: a dog photo predicted as dog with 91%, median 6119 ms, parity OK">
16
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/nokiae72_fmnist.png" height="300"
17
+ alt="Nokia E72 showing the results page of a Fashion-MNIST LeNet: top-1 90%, median 121 ms, parity OK, and four clothing images with their predicted classes">
18
+ <img src="https://raw.githubusercontent.com/said-ohamouddou/padkeml/main/docs/screenshots/nokiac7_mnist.png" height="300"
19
+ alt="Nokia C7 showing the results page of an MNIST LeNet: top-1 100%, median 95 ms, parity OK, and four handwritten digits with their predicted classes">
20
+ </p>
21
+ <p align="center"><sub>Nokia 6600i slide · Nokia 6210 Navigator · Sony Ericsson C902 · Nokia E72 · Nokia C7</sub></p>
22
+
23
+ keypadml turns a PyTorch model and a few test inputs into a `.jar` file for any phone with
24
+ **CLDC 1.1 and MIDP 2.0** (Nokia Series 40 and S60, Sony Ericsson, Samsung, …). On the phone, the app:
25
+
26
+ - runs the model on every input and **times** each run;
27
+ - **checks** that its outputs match PyTorch's;
28
+ - shows the results on screen and **saves** them as a JSON file.
29
+
30
+ Back on your computer, `keypadml report` gives you latency, accuracy, memory, per-layer times
31
+ and the parity check. No Java toolkit is needed: the jar contains a small precompiled
32
+ interpreter, and your model travels inside it as data.
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ pip install keypadml # Python 3.9+, PyTorch 1.13+
38
+ ```
39
+
40
+ Optional: Java 8 or newer, to test a jar on your PC (`keypadml verify`) or in an emulator
41
+ (`keypadml emulate`).
42
+
43
+ ## Quick start
44
+
45
+ **1. Export** your model with a few test inputs:
46
+
47
+ ```python
48
+ import keypadml
49
+
50
+ inputs, labels = keypadml.sample(test_dataset, n=50)
51
+ result = keypadml.export(model, inputs, labels, out_dir="bench", name="LeNet")
52
+ print(result) # jar size, parameters, multiply-adds, memory estimate
53
+ keypadml.verify(result) # optional: run the phone's code on this PC
54
+ ```
55
+
56
+ **2. Run on the phone.** Copy `bench/LeNet.jar` to the phone, open it and press **Start**.
57
+ The results are saved on the memory card in `keypadml/<phone model>/`.
58
+
59
+ **3. Read the report** on your computer (a real Nokia 6600i run, shortened):
60
+
61
+ ```text
62
+ $ keypadml report kp_LeNet_123456.json --ref bench
63
+
64
+ keypadml report: LeNet (model id 554f28fb7a9d)
65
+ device Nokia6600i-1c/36.16 [CLDC-1.1, MIDP-2.1]
66
+ workload 100 inputs x 5 runs (+2 warm-up), input 1x28x28, batch 1, 61,706 parameters
67
+ accuracy top-1 97.00%, top-5 100.00% (PyTorch on the PC: 97.00%)
68
+ latency median 321.0 ms, mean 325.2 ± 3.1 ms (95% CI), min 317, p90 324, max 772 ms
69
+ first run 343 ms, model load 122 ms, 3.07 inputs/s
70
+ memory heap 2048 KB, 364 KB in use after loading
71
+ parity OK: max relative difference 2.6e-07, same top-1 as PyTorch 100%
72
+ slowest layers (ms per run):
73
+ 183.00 57.4% conv conv2 1.31 MMAC/s
74
+ 93.00 29.2% conv conv1 1.26 MMAC/s
75
+ ```
76
+
77
+ ## Results on real phones
78
+
79
+ The same 20 benchmark jars ran on four phones. Median time per input:
80
+
81
+ | Phone | MNIST LeNet | Keyword spotting | CIFAR-10 ResNet-8 | Pets 304 px | Speed (M multiply-adds/s) |
82
+ |---|---:|---:|---:|---:|---:|
83
+ | Nokia 6600i slide (2008) | 303 ms | 1.89 s | 8.39 s | 40.8 s | 1.41 |
84
+ | Nokia 6210 Navigator (2008) | 417 ms | 2.68 s | 12.0 s | 61.7 s | 0.94 |
85
+ | Nokia E72 (2009) | 121 ms | 743 ms | 3.50 s | 16.6 s | 3.47 |
86
+ | Nokia C7 (2010) | 96 ms | 573 ms | 2.71 s | 13.0 s | 4.43 |
87
+
88
+ - **Every run matched PyTorch:** all 80 runs gave the same top-1 class, with outputs within 7.2e-6.
89
+ - **Time follows multiply-adds:** each phone has one speed, so you can predict a model's time before
90
+ installing it.
91
+ - **Memory is the limit:** a 2 MB heap fits colour images up to about 300 × 300.
92
+
93
+ Full tables (image size, five architectures, nine tasks): [docs/benchmark-results.md](https://github.com/said-ohamouddou/padkeml/blob/main/docs/benchmark-results.md).
94
+ Raw files: [`results/`](https://github.com/said-ohamouddou/padkeml/tree/main/results/).
95
+
96
+ ## Features
97
+
98
+ - **Supported layers:** convolutions (including depthwise), linear, batch norm (folded), pooling,
99
+ residual additions, concatenation, squeeze-excitation and common activations. Tested with LeNet,
100
+ ResNet, MobileNet V2/V3, SqueezeNet and EfficientNet-B0.
101
+ - **Memory check before you install:** `export()` estimates the phone's memory, warns above 1.9 MB
102
+ and refuses models that need more than twice that.
103
+ - **Results page on the phone:** test inputs as pictures with the predicted class, green when right
104
+ and red when wrong.
105
+ - **Try it:** image models can also classify a **camera snapshot** or a **photo** from the memory card.
106
+ See [docs/try-it.md](https://github.com/said-ohamouddou/padkeml/blob/main/docs/try-it.md).
107
+
108
+ ## Documentation
109
+
110
+ | | |
111
+ |---|---|
112
+ | [User guide](https://github.com/said-ohamouddou/padkeml/blob/main/docs/guide.md) | Workflow, examples, export options, supported models, choosing image size and number of inputs, limits of old phones |
113
+ | [Try it](https://github.com/said-ohamouddou/padkeml/blob/main/docs/try-it.md) | Camera and photo mode |
114
+ | [Benchmark results](https://github.com/said-ohamouddou/padkeml/blob/main/docs/benchmark-results.md) | All results on the four phones |
115
+ | [Benchmark plan](https://github.com/said-ohamouddou/padkeml/blob/main/docs/benchmark-plan.md) | How the 20 benchmark jars were made and run |
116
+ | [Results file format](https://github.com/said-ohamouddou/padkeml/blob/main/docs/results-format.md) | The JSON file the phone saves |
117
+
118
+ ## Licence
119
+
120
+ Apache-2.0. `keypadml emulate` downloads MicroEmulator on first use, and the runtime build script
121
+ downloads ProGuard and the CLDC/MIDP API jars; none of them is bundled. Jars you export contain your
122
+ model's weights and inputs, so check their licences before sharing them. "Java" and other names are
123
+ trademarks of their owners.
124
+
125
+ ## Citing
126
+
127
+ See [`CITATION.cff`](https://github.com/said-ohamouddou/padkeml/blob/main/CITATION.cff).