Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit edcf1f8

Browse files
docs: usage: mnist: Complete MNIST tutorial
- Added png configloader to reading .mnistpng files - Using the .mnistpng extension for now because we're making the images into 28x28 flat arrays, which is specific to the mnist example. - Added images to examples/MNIST for predicting - Documentation for MNIST prediction - CSVSource can now replace data in columns if that data is a filename with the data in that file loaded by the configloader given by the files extention. Signed-off-by: John Andersen <[email protected]>
1 parent a9a7ea3 commit edcf1f8

32 files changed

+494
-38
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ docs/plugins/service/http
2424
*pip-wheel-metadata/
2525
*.gz
2626
doctest/
27+
*.mnistpng

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Added
9+
- PNG ConfigLoader for reading images as arrays to predict using MNIST trained models
910
- Docstrings and doctestable examples to `record.py`.
1011
- Inputs can be validated using operations
1112
- `validate` parameter in `Input` takes `Operation.instance_name`

configloader/png/.coveragerc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[run]
2+
source =
3+
dffml_config_png
4+
tests
5+
branch = True
6+
7+
[report]
8+
exclude_lines =
9+
no cov
10+
no qa
11+
noqa
12+
pragma: no cover
13+
if __name__ == .__main__.:

configloader/png/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.log
2+
*.pyc
3+
.cache/
4+
.coverage
5+
.idea/
6+
.vscode/
7+
*.egg-info/
8+
build/
9+
dist/
10+
docs/build/
11+
venv/
12+
wheelhouse/
13+
*.egss
14+
.mypy_cache/
15+
*.swp
16+
.venv/
17+
.eggs/
18+
*.modeldir
19+
*.db
20+
htmlcov/

configloader/png/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) 2019 Intel, Saksham
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

configloader/png/MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include README.md
2+
include LICENSE
3+
include setup_common.py

configloader/png/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# DFFML Config for png
2+
3+
## About
4+
5+
Allows for reading of 'PNG' images for [MNIST dataset](../../docs/usage/mnist.rst)
6+
7+
## License
8+
9+
png Models are distributed under the terms of the
10+
[MIT License](LICENSE).

configloader/png/dffml_config_png/__init__.py

Whitespace-only changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Description of what this config does
3+
"""
4+
from typing import Dict
5+
from io import BytesIO
6+
from PIL import Image
7+
import numpy as np
8+
9+
from dffml.util.entrypoint import entrypoint
10+
from dffml.util.cli.arg import Arg
11+
from dffml.base import BaseConfig
12+
from dffml.configloader.configloader import (
13+
BaseConfigLoaderContext,
14+
BaseConfigLoader,
15+
)
16+
17+
18+
class PNGConfigLoaderContext(BaseConfigLoaderContext):
19+
async def loadb(self, resource: bytes) -> list:
20+
image_array = np.array(Image.open(BytesIO(resource)).convert("L"))
21+
img_pil = Image.fromarray(image_array)
22+
img_28x28 = np.array(img_pil.resize((28, 28), Image.ANTIALIAS))
23+
img_784 = tuple(img_28x28.flatten())
24+
return img_784
25+
26+
async def dumpb(self, resource: Dict) -> bytes:
27+
raise NotImplementedError
28+
29+
30+
@entrypoint("mnistpng")
31+
class PNGConfigLoader(BaseConfigLoader):
32+
CONTEXT = PNGConfigLoaderContext
33+
34+
@classmethod
35+
def args(cls, args, *above) -> Dict[str, Arg]:
36+
return args
37+
38+
@classmethod
39+
def config(cls, config, *above) -> BaseConfig:
40+
return BaseConfig()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = "0.0.1"

0 commit comments

Comments
 (0)