Skip to content

Uses Travis #1

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

Merged
merged 10 commits into from
Mar 12, 2022
Merged
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
24 changes: 0 additions & 24 deletions .github/workflows/pytest.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python
python:
- "3.9"
install:
- pip install pipenv
- pipenv install

script:
# Your test script goes here
- pytest -v --color=yes src # Runs in pipenv
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test:
pytest

lint:
pylint src

lintfix:
autopep8 src --recursive --in-place --aggressive

lintfixhard:
autopep8 src --recursive --in-place --aggressive --aggressive

install:
pipenv install

lock:
pipenv lock

clean:
pipenv clean
17 changes: 17 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
tensorflow = "*"
matplotlib = "*"
autopep8 = "*"

[requires]
python_version = "3.9"

[dev-packages]
pylint = "*"
pytest = "*"
autopep8 = "*"
988 changes: 988 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

56 changes: 47 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,68 @@
# Machine Learning
Machine Learning tools, techniques, gists and projects. Some of this code is referenced in our Blog.

This repository uses `conda` as an environment manager.
The base python version is `3.9.7`.
This repository uses `pipenv` as an environment manager.
The base python version is `3.9`.

## Install dependencies
You can follow [this instructions](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html)
to install conda.
You will need a base `python` installed in your system.
```bash
python --version
```

Then you will need to install `pip` and `pipenv`.
```bash
python -m pip install --user pip --upgrade pip
python -m pip install --user pipenv
```

Once conda is installed run the following command to install all dependencies
into a separate environment called `machine-learning`.
Install the dependencies with
```bash
conda create --name machine-learning --file requirements.txt
make install
```
This calls `pipenv`, which will create a virtual environment for this project.

To enter a shell on this environment run
```bash
make shell
```

## Tests
Run the entire test suite with `pytest`.
Use
```bash
make test
```

## Code Style
We use PEP8 as a style guide for python code.

Check lint errors with
```bash
make lint
```

We use `autopep8` to automatically fix errors.

User
```bash
make lintfix
```
of
```bash
make lintfixhard
```

for in-place fixing of lint errors under the `/src` dir.


## Contribution
1. Create a new feature branch that compares to the main branch and open a PR.
1. Ensure you have written appropriate tests and run `pytest`
1. Ensure you have written appropriate tests and they are passing.
1. Ensure the code passes the style guide conventions.

Update the `requirements.txt` file using the following command from the
main directory:
```bash
conda list -e > requirements.txt
make lock
```
2 changes: 1 addition & 1 deletion path_adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main():
file_name = 'extra_python_folders.pth'
with open(os.path.join(site_packages_dir, file_name), 'w') as f:
f.write(src_path)
print("Added to conda path: " + src_path)
print("Added to path: " + src_path)

if __name__ == "__main__":
main()
84 changes: 0 additions & 84 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/computer_vision/cnn/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .fashion_mnist_classifier import FashionMNISTClassifier
from .fashion_mnist_classifier import FashionMNISTClassifier
1 change: 1 addition & 0 deletions src/computer_vision/cnn/fashion_mnist_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Support packages
import pickle


class FashionMNISTClassifier:
def __init__(self, model_path, train_history_path):
self.model_path = model_path
Expand Down
13 changes: 7 additions & 6 deletions src/computer_vision/cnn/fashion_mnist_classifier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@

tensorflow.random.set_seed(123)


def test_full_cycle():
classifier = FashionMNISTClassifier("./model.h5", "./hist")
classifier.build_model()
classifier.load_dataset()
classifier.train_data = ( # just use 300 data samples for unit testing
classifier.train_data = ( # just use 300 data samples for unit testing
classifier.train_data[0][:300],
classifier.train_data[1][:300]
)

classifier.compile()
classifier.train(128, 2, 0.1)

assert classifier.model # The model is accessible
assert classifier.train_hist # The training history is accessible
assert classifier.train_hist.get('accuracy') # The accuracy was recorded
assert classifier.model # The model is accessible
assert classifier.train_hist # The training history is accessible
assert classifier.train_hist.get('accuracy') # The accuracy was recorded

accuracy = classifier.train_hist['accuracy']

assert len(accuracy) == 2 # There is one measurement for every epoch
assert accuracy[0] < accuracy [1] # The second epoch is an improvement
assert len(accuracy) == 2 # There is one measurement for every epoch
assert accuracy[0] < accuracy[1] # The second epoch is an improvement