ItchyB commited on
Commit
3215e11
1 Parent(s): 7d07110

starting new practical learning branch using nbdev

Browse files
.vscode/settings.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "python.formatting.provider": "autopep8",
3
+ "C_Cpp.default.configurationProvider": "ms-vscode.makefile-tools",
4
+ "esbonio.sphinx.confDir": ""
5
+ }
lesson02/.gitconfig ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by nbdev_install_hooks
2
+ #
3
+ # If you need to disable this instrumentation do:
4
+ # git config --local --unset include.path
5
+ #
6
+ # To restore:
7
+ # git config --local include.path ../.gitconfig
8
+ #
9
+ [merge "nbdev-merge"]
10
+ name = resolve conflicts with nbdev_fix
11
+ driver = nbdev_merge %O %A %B %P
lesson02/.gitignore ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+
5
+ # C extensions
6
+ *.so
7
+
8
+ # Distribution / packaging
9
+ .Python
10
+ env/
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+
26
+ # PyInstaller
27
+ # Usually these files are written by a python script from a template
28
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
29
+ *.manifest
30
+ *.spec
31
+
32
+ # Installer logs
33
+ pip-log.txt
34
+ pip-delete-this-directory.txt
35
+
36
+ # Unit test / coverage reports
37
+ htmlcov/
38
+ .tox/
39
+ .coverage
40
+ .coverage.*
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+ *.cover
45
+
46
+ # Translations
47
+ *.mo
48
+ *.pot
49
+
50
+ # Django stuff:
51
+ *.log
52
+
53
+ # Sphinx documentation
54
+ docs/_build/
55
+
56
+ # PyBuilder
57
+ target/
58
+
59
+ # DotEnv configuration
60
+ .env
61
+
62
+ # Database
63
+ *.db
64
+ *.rdb
65
+
66
+ # Pycharm
67
+ .idea
68
+
69
+ # VS Code
70
+ .vscode/
71
+
72
+ # Spyder
73
+ .spyproject/
74
+
75
+ # Jupyter NB Checkpoints
76
+ .ipynb_checkpoints/
77
+
78
+ # exclude data from source control by default
79
+ /data/
80
+
81
+ # Mac OS-specific storage files
82
+ .DS_Store
83
+
84
+ # vim
85
+ *.swp
86
+ *.swo
87
+
88
+ # Mypy cache
89
+ .mypy_cache/
lesson02/LICENSE ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ The MIT License (MIT)
2
+ Copyright (c) 2023, Byron Wright
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
lesson02/Makefile ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .PHONY: clean data lint requirements sync_data_to_s3 sync_data_from_s3
2
+
3
+ #################################################################################
4
+ # GLOBALS #
5
+ #################################################################################
6
+
7
+ PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
8
+ BUCKET = [OPTIONAL] your-bucket-for-syncing-data (do not include 's3://')
9
+ PROFILE = default
10
+ PROJECT_NAME = lesson02
11
+ PYTHON_INTERPRETER = python3
12
+
13
+ ifeq (,$(shell which conda))
14
+ HAS_CONDA=False
15
+ else
16
+ HAS_CONDA=True
17
+ endif
18
+
19
+ #################################################################################
20
+ # COMMANDS #
21
+ #################################################################################
22
+
23
+ ## Install Python Dependencies
24
+ requirements: test_environment
25
+ $(PYTHON_INTERPRETER) -m pip install -U pip setuptools wheel
26
+ $(PYTHON_INTERPRETER) -m pip install -r requirements.txt
27
+
28
+ ## Make Dataset
29
+ data: requirements
30
+ $(PYTHON_INTERPRETER) src/data/make_dataset.py data/raw data/processed
31
+
32
+ ## Delete all compiled Python files
33
+ clean:
34
+ find . -type f -name "*.py[co]" -delete
35
+ find . -type d -name "__pycache__" -delete
36
+
37
+ ## Lint using flake8
38
+ lint:
39
+ flake8 src
40
+
41
+ ## Upload Data to S3
42
+ sync_data_to_s3:
43
+ ifeq (default,$(PROFILE))
44
+ aws s3 sync data/ s3://$(BUCKET)/data/
45
+ else
46
+ aws s3 sync data/ s3://$(BUCKET)/data/ --profile $(PROFILE)
47
+ endif
48
+
49
+ ## Download Data from S3
50
+ sync_data_from_s3:
51
+ ifeq (default,$(PROFILE))
52
+ aws s3 sync s3://$(BUCKET)/data/ data/
53
+ else
54
+ aws s3 sync s3://$(BUCKET)/data/ data/ --profile $(PROFILE)
55
+ endif
56
+
57
+ ## Set up python interpreter environment
58
+ create_environment:
59
+ ifeq (True,$(HAS_CONDA))
60
+ @echo ">>> Detected conda, creating conda environment."
61
+ ifeq (3,$(findstring 3,$(PYTHON_INTERPRETER)))
62
+ conda create --name $(PROJECT_NAME) python=3
63
+ else
64
+ conda create --name $(PROJECT_NAME) python=2.7
65
+ endif
66
+ @echo ">>> New conda env created. Activate with:\nsource activate $(PROJECT_NAME)"
67
+ else
68
+ $(PYTHON_INTERPRETER) -m pip install -q virtualenv virtualenvwrapper
69
+ @echo ">>> Installing virtualenvwrapper if not already installed.\nMake sure the following lines are in shell startup file\n\
70
+ export WORKON_HOME=$$HOME/.virtualenvs\nexport PROJECT_HOME=$$HOME/Devel\nsource /usr/local/bin/virtualenvwrapper.sh\n"
71
+ @bash -c "source `which virtualenvwrapper.sh`;mkvirtualenv $(PROJECT_NAME) --python=$(PYTHON_INTERPRETER)"
72
+ @echo ">>> New virtualenv created. Activate with:\nworkon $(PROJECT_NAME)"
73
+ endif
74
+
75
+ ## Test python environment is setup correctly
76
+ test_environment:
77
+ $(PYTHON_INTERPRETER) test_environment.py
78
+
79
+ #################################################################################
80
+ # PROJECT RULES #
81
+ #################################################################################
82
+
83
+
84
+
85
+ #################################################################################
86
+ # Self Documenting Commands #
87
+ #################################################################################
88
+
89
+ .DEFAULT_GOAL := help
90
+
91
+ # Inspired by <http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html>
92
+ # sed script explained:
93
+ # /^##/:
94
+ # * save line in hold space
95
+ # * purge line
96
+ # * Loop:
97
+ # * append newline + line to hold space
98
+ # * go to next line
99
+ # * if line starts with doc comment, strip comment character off and loop
100
+ # * remove target prerequisites
101
+ # * append hold space (+ newline) to line
102
+ # * replace newline plus comments by `---`
103
+ # * print line
104
+ # Separate expressions are necessary because labels cannot be delimited by
105
+ # semicolon; see <http://stackoverflow.com/a/11799865/1968>
106
+ .PHONY: help
107
+ help:
108
+ @echo "$$(tput bold)Available rules:$$(tput sgr0)"
109
+ @echo
110
+ @sed -n -e "/^## / { \
111
+ h; \
112
+ s/.*//; \
113
+ :doc" \
114
+ -e "H; \
115
+ n; \
116
+ s/^## //; \
117
+ t doc" \
118
+ -e "s/:.*//; \
119
+ G; \
120
+ s/\\n## /---/; \
121
+ s/\\n/ /g; \
122
+ p; \
123
+ }" ${MAKEFILE_LIST} \
124
+ | LC_ALL='C' sort --ignore-case \
125
+ | awk -F '---' \
126
+ -v ncol=$$(tput cols) \
127
+ -v indent=19 \
128
+ -v col_on="$$(tput setaf 6)" \
129
+ -v col_off="$$(tput sgr0)" \
130
+ '{ \
131
+ printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
132
+ n = split($$2, words, " "); \
133
+ line_length = ncol - indent; \
134
+ for (i = 1; i <= n; i++) { \
135
+ line_length -= length(words[i]) + 1; \
136
+ if (line_length <= 0) { \
137
+ line_length = ncol - indent - length(words[i]) - 1; \
138
+ printf "\n%*s ", -indent, " "; \
139
+ } \
140
+ printf "%s ", words[i]; \
141
+ } \
142
+ printf "\n"; \
143
+ }' \
144
+ | more $(shell test $(shell uname) = Darwin && echo '--no-init --raw-control-chars')
lesson02/README.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Lesson02
2
+ ==============================
3
+
4
+ Lesson02 fastai
5
+
6
+ Project Organization
7
+ ------------
8
+
9
+ ├── LICENSE
10
+ ├── Makefile <- Makefile with commands like `make data` or `make train`
11
+ ├── README.md <- The top-level README for developers using this project.
12
+ ├── data
13
+ │   ├── external <- Data from third party sources.
14
+ │   ├── interim <- Intermediate data that has been transformed.
15
+ │   ├── processed <- The final, canonical data sets for modeling.
16
+ │   └── raw <- The original, immutable data dump.
17
+
18
+ ├── docs <- A default Sphinx project; see sphinx-doc.org for details
19
+
20
+ ├── models <- Trained and serialized models, model predictions, or model summaries
21
+
22
+ ├── notebooks <- Jupyter notebooks. Naming convention is a number (for ordering),
23
+ │ the creator's initials, and a short `-` delimited description, e.g.
24
+ │ `1.0-jqp-initial-data-exploration`.
25
+
26
+ ├── references <- Data dictionaries, manuals, and all other explanatory materials.
27
+
28
+ ├── reports <- Generated analysis as HTML, PDF, LaTeX, etc.
29
+ │   └── figures <- Generated graphics and figures to be used in reporting
30
+
31
+ ├── requirements.txt <- The requirements file for reproducing the analysis environment, e.g.
32
+ │ generated with `pip freeze > requirements.txt`
33
+
34
+ ├── setup.py <- makes project pip installable (pip install -e .) so src can be imported
35
+ ├── src <- Source code for use in this project.
36
+ │   ├── __init__.py <- Makes src a Python module
37
+ │ │
38
+ │   ├── data <- Scripts to download or generate data
39
+ │   │   └── make_dataset.py
40
+ │ │
41
+ │   ├── features <- Scripts to turn raw data into features for modeling
42
+ │   │   └── build_features.py
43
+ │ │
44
+ │   ├── models <- Scripts to train models and then use trained models to make
45
+ │ │ │ predictions
46
+ │   │   ├── predict_model.py
47
+ │   │   └── train_model.py
48
+ │ │
49
+ │   └── visualization <- Scripts to create exploratory and results oriented visualizations
50
+ │   └── visualize.py
51
+
52
+ └── tox.ini <- tox file with settings for running tox; see tox.readthedocs.io
53
+
54
+
55
+ --------
56
+
57
+ <p><small>Project based on the <a target="_blank" href="https://drivendata.github.io/cookiecutter-data-science/">cookiecutter data science project template</a>. #cookiecutterdatascience</small></p>
lesson02/docs/Makefile ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line.
5
+ SPHINXOPTS =
6
+ SPHINXBUILD = sphinx-build
7
+ PAPER =
8
+ BUILDDIR = _build
9
+
10
+ # Internal variables.
11
+ PAPEROPT_a4 = -D latex_paper_size=a4
12
+ PAPEROPT_letter = -D latex_paper_size=letter
13
+ ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
14
+ # the i18n builder cannot share the environment and doctrees with the others
15
+ I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
16
+
17
+ .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
18
+
19
+ help:
20
+ @echo "Please use \`make <target>' where <target> is one of"
21
+ @echo " html to make standalone HTML files"
22
+ @echo " dirhtml to make HTML files named index.html in directories"
23
+ @echo " singlehtml to make a single large HTML file"
24
+ @echo " pickle to make pickle files"
25
+ @echo " json to make JSON files"
26
+ @echo " htmlhelp to make HTML files and a HTML help project"
27
+ @echo " qthelp to make HTML files and a qthelp project"
28
+ @echo " devhelp to make HTML files and a Devhelp project"
29
+ @echo " epub to make an epub"
30
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
31
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
32
+ @echo " text to make text files"
33
+ @echo " man to make manual pages"
34
+ @echo " texinfo to make Texinfo files"
35
+ @echo " info to make Texinfo files and run them through makeinfo"
36
+ @echo " gettext to make PO message catalogs"
37
+ @echo " changes to make an overview of all changed/added/deprecated items"
38
+ @echo " linkcheck to check all external links for integrity"
39
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
40
+
41
+ clean:
42
+ -rm -rf $(BUILDDIR)/*
43
+
44
+ html:
45
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
46
+ @echo
47
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
48
+
49
+ dirhtml:
50
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
51
+ @echo
52
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
53
+
54
+ singlehtml:
55
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
56
+ @echo
57
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
58
+
59
+ pickle:
60
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
61
+ @echo
62
+ @echo "Build finished; now you can process the pickle files."
63
+
64
+ json:
65
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
66
+ @echo
67
+ @echo "Build finished; now you can process the JSON files."
68
+
69
+ htmlhelp:
70
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
71
+ @echo
72
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
73
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
74
+
75
+ qthelp:
76
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
77
+ @echo
78
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
79
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
80
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/lesson02.qhcp"
81
+ @echo "To view the help file:"
82
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/lesson02.qhc"
83
+
84
+ devhelp:
85
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
86
+ @echo
87
+ @echo "Build finished."
88
+ @echo "To view the help file:"
89
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/lesson02"
90
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/lesson02"
91
+ @echo "# devhelp"
92
+
93
+ epub:
94
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
95
+ @echo
96
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
97
+
98
+ latex:
99
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
100
+ @echo
101
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
102
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
103
+ "(use \`make latexpdf' here to do that automatically)."
104
+
105
+ latexpdf:
106
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
107
+ @echo "Running LaTeX files through pdflatex..."
108
+ $(MAKE) -C $(BUILDDIR)/latex all-pdf
109
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
110
+
111
+ text:
112
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
113
+ @echo
114
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
115
+
116
+ man:
117
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
118
+ @echo
119
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
120
+
121
+ texinfo:
122
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
123
+ @echo
124
+ @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
125
+ @echo "Run \`make' in that directory to run these through makeinfo" \
126
+ "(use \`make info' here to do that automatically)."
127
+
128
+ info:
129
+ $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
130
+ @echo "Running Texinfo files through makeinfo..."
131
+ make -C $(BUILDDIR)/texinfo info
132
+ @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
133
+
134
+ gettext:
135
+ $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
136
+ @echo
137
+ @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
138
+
139
+ changes:
140
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
141
+ @echo
142
+ @echo "The overview file is in $(BUILDDIR)/changes."
143
+
144
+ linkcheck:
145
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
146
+ @echo
147
+ @echo "Link check complete; look for any errors in the above output " \
148
+ "or in $(BUILDDIR)/linkcheck/output.txt."
149
+
150
+ doctest:
151
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
152
+ @echo "Testing of doctests in the sources finished, look at the " \
153
+ "results in $(BUILDDIR)/doctest/output.txt."
lesson02/docs/commands.rst ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ Commands
2
+ ========
3
+
4
+ The Makefile contains the central entry points for common tasks related to this project.
5
+
6
+ Syncing data to S3
7
+ ^^^^^^^^^^^^^^^^^^
8
+
9
+ * `make sync_data_to_s3` will use `aws s3 sync` to recursively sync files in `data/` up to `s3://[OPTIONAL] your-bucket-for-syncing-data (do not include 's3://')/data/`.
10
+ * `make sync_data_from_s3` will use `aws s3 sync` to recursively sync files from `s3://[OPTIONAL] your-bucket-for-syncing-data (do not include 's3://')/data/` to `data/`.
lesson02/docs/conf.py ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Lesson02 documentation build configuration file, created by
4
+ # sphinx-quickstart.
5
+ #
6
+ # This file is execfile()d with the current directory set to its containing dir.
7
+ #
8
+ # Note that not all possible configuration values are present in this
9
+ # autogenerated file.
10
+ #
11
+ # All configuration values have a default; values that are commented out
12
+ # serve to show the default.
13
+
14
+ import os
15
+ import sys
16
+
17
+ # If extensions (or modules to document with autodoc) are in another directory,
18
+ # add these directories to sys.path here. If the directory is relative to the
19
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
20
+ # sys.path.insert(0, os.path.abspath('.'))
21
+
22
+ # -- General configuration -----------------------------------------------------
23
+
24
+ # If your documentation needs a minimal Sphinx version, state it here.
25
+ # needs_sphinx = '1.0'
26
+
27
+ # Add any Sphinx extension module names here, as strings. They can be extensions
28
+ # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
29
+ extensions = []
30
+
31
+ # Add any paths that contain templates here, relative to this directory.
32
+ templates_path = ['_templates']
33
+
34
+ # The suffix of source filenames.
35
+ source_suffix = '.rst'
36
+
37
+ # The encoding of source files.
38
+ # source_encoding = 'utf-8-sig'
39
+
40
+ # The master toctree document.
41
+ master_doc = 'index'
42
+
43
+ # General information about the project.
44
+ project = u'Lesson02'
45
+
46
+ # The version info for the project you're documenting, acts as replacement for
47
+ # |version| and |release|, also used in various other places throughout the
48
+ # built documents.
49
+ #
50
+ # The short X.Y version.
51
+ version = '0.1'
52
+ # The full version, including alpha/beta/rc tags.
53
+ release = '0.1'
54
+
55
+ # The language for content autogenerated by Sphinx. Refer to documentation
56
+ # for a list of supported languages.
57
+ # language = None
58
+
59
+ # There are two options for replacing |today|: either, you set today to some
60
+ # non-false value, then it is used:
61
+ # today = ''
62
+ # Else, today_fmt is used as the format for a strftime call.
63
+ # today_fmt = '%B %d, %Y'
64
+
65
+ # List of patterns, relative to source directory, that match files and
66
+ # directories to ignore when looking for source files.
67
+ exclude_patterns = ['_build']
68
+
69
+ # The reST default role (used for this markup: `text`) to use for all documents.
70
+ # default_role = None
71
+
72
+ # If true, '()' will be appended to :func: etc. cross-reference text.
73
+ # add_function_parentheses = True
74
+
75
+ # If true, the current module name will be prepended to all description
76
+ # unit titles (such as .. function::).
77
+ # add_module_names = True
78
+
79
+ # If true, sectionauthor and moduleauthor directives will be shown in the
80
+ # output. They are ignored by default.
81
+ # show_authors = False
82
+
83
+ # The name of the Pygments (syntax highlighting) style to use.
84
+ pygments_style = 'sphinx'
85
+
86
+ # A list of ignored prefixes for module index sorting.
87
+ # modindex_common_prefix = []
88
+
89
+
90
+ # -- Options for HTML output ---------------------------------------------------
91
+
92
+ # The theme to use for HTML and HTML Help pages. See the documentation for
93
+ # a list of builtin themes.
94
+ html_theme = 'default'
95
+
96
+ # Theme options are theme-specific and customize the look and feel of a theme
97
+ # further. For a list of options available for each theme, see the
98
+ # documentation.
99
+ # html_theme_options = {}
100
+
101
+ # Add any paths that contain custom themes here, relative to this directory.
102
+ # html_theme_path = []
103
+
104
+ # The name for this set of Sphinx documents. If None, it defaults to
105
+ # "<project> v<release> documentation".
106
+ # html_title = None
107
+
108
+ # A shorter title for the navigation bar. Default is the same as html_title.
109
+ # html_short_title = None
110
+
111
+ # The name of an image file (relative to this directory) to place at the top
112
+ # of the sidebar.
113
+ # html_logo = None
114
+
115
+ # The name of an image file (within the static path) to use as favicon of the
116
+ # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
117
+ # pixels large.
118
+ # html_favicon = None
119
+
120
+ # Add any paths that contain custom static files (such as style sheets) here,
121
+ # relative to this directory. They are copied after the builtin static files,
122
+ # so a file named "default.css" will overwrite the builtin "default.css".
123
+ html_static_path = ['_static']
124
+
125
+ # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
126
+ # using the given strftime format.
127
+ # html_last_updated_fmt = '%b %d, %Y'
128
+
129
+ # If true, SmartyPants will be used to convert quotes and dashes to
130
+ # typographically correct entities.
131
+ # html_use_smartypants = True
132
+
133
+ # Custom sidebar templates, maps document names to template names.
134
+ # html_sidebars = {}
135
+
136
+ # Additional templates that should be rendered to pages, maps page names to
137
+ # template names.
138
+ # html_additional_pages = {}
139
+
140
+ # If false, no module index is generated.
141
+ # html_domain_indices = True
142
+
143
+ # If false, no index is generated.
144
+ # html_use_index = True
145
+
146
+ # If true, the index is split into individual pages for each letter.
147
+ # html_split_index = False
148
+
149
+ # If true, links to the reST sources are added to the pages.
150
+ # html_show_sourcelink = True
151
+
152
+ # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
153
+ # html_show_sphinx = True
154
+
155
+ # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
156
+ # html_show_copyright = True
157
+
158
+ # If true, an OpenSearch description file will be output, and all pages will
159
+ # contain a <link> tag referring to it. The value of this option must be the
160
+ # base URL from which the finished HTML is served.
161
+ # html_use_opensearch = ''
162
+
163
+ # This is the file name suffix for HTML files (e.g. ".xhtml").
164
+ # html_file_suffix = None
165
+
166
+ # Output file base name for HTML help builder.
167
+ htmlhelp_basename = 'lesson02doc'
168
+
169
+
170
+ # -- Options for LaTeX output --------------------------------------------------
171
+
172
+ latex_elements = {
173
+ # The paper size ('letterpaper' or 'a4paper').
174
+ # 'papersize': 'letterpaper',
175
+
176
+ # The font size ('10pt', '11pt' or '12pt').
177
+ # 'pointsize': '10pt',
178
+
179
+ # Additional stuff for the LaTeX preamble.
180
+ # 'preamble': '',
181
+ }
182
+
183
+ # Grouping the document tree into LaTeX files. List of tuples
184
+ # (source start file, target name, title, author, documentclass [howto/manual]).
185
+ latex_documents = [
186
+ ('index',
187
+ 'lesson02.tex',
188
+ u'Lesson02 Documentation',
189
+ u"Byron Wright", 'manual'),
190
+ ]
191
+
192
+ # The name of an image file (relative to this directory) to place at the top of
193
+ # the title page.
194
+ # latex_logo = None
195
+
196
+ # For "manual" documents, if this is true, then toplevel headings are parts,
197
+ # not chapters.
198
+ # latex_use_parts = False
199
+
200
+ # If true, show page references after internal links.
201
+ # latex_show_pagerefs = False
202
+
203
+ # If true, show URL addresses after external links.
204
+ # latex_show_urls = False
205
+
206
+ # Documents to append as an appendix to all manuals.
207
+ # latex_appendices = []
208
+
209
+ # If false, no module index is generated.
210
+ # latex_domain_indices = True
211
+
212
+
213
+ # -- Options for manual page output --------------------------------------------
214
+
215
+ # One entry per manual page. List of tuples
216
+ # (source start file, name, description, authors, manual section).
217
+ man_pages = [
218
+ ('index', 'lesson02', u'Lesson02 Documentation',
219
+ [u"Byron Wright"], 1)
220
+ ]
221
+
222
+ # If true, show URL addresses after external links.
223
+ # man_show_urls = False
224
+
225
+
226
+ # -- Options for Texinfo output ------------------------------------------------
227
+
228
+ # Grouping the document tree into Texinfo files. List of tuples
229
+ # (source start file, target name, title, author,
230
+ # dir menu entry, description, category)
231
+ texinfo_documents = [
232
+ ('index', 'lesson02', u'Lesson02 Documentation',
233
+ u"Byron Wright", 'Lesson02',
234
+ 'Lesson02 fastai', 'Miscellaneous'),
235
+ ]
236
+
237
+ # Documents to append as an appendix to all manuals.
238
+ # texinfo_appendices = []
239
+
240
+ # If false, no module index is generated.
241
+ # texinfo_domain_indices = True
242
+
243
+ # How to display URL addresses: 'footnote', 'no', or 'inline'.
244
+ # texinfo_show_urls = 'footnote'
lesson02/docs/getting-started.rst ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Getting started
2
+ ===============
3
+
4
+ This is where you describe how to get set up on a clean install, including the
5
+ commands necessary to get the raw data (using the `sync_data_from_s3` command,
6
+ for example), and then how to make the cleaned, final data sets.
lesson02/docs/index.rst ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .. Lesson02 documentation master file, created by
2
+ sphinx-quickstart.
3
+ You can adapt this file completely to your liking, but it should at least
4
+ contain the root `toctree` directive.
5
+
6
+ Lesson02 documentation!
7
+ ==============================================
8
+
9
+ Contents:
10
+
11
+ .. toctree::
12
+ :maxdepth: 2
13
+
14
+ getting-started
15
+ commands
16
+
17
+
18
+
19
+ Indices and tables
20
+ ==================
21
+
22
+ * :ref:`genindex`
23
+ * :ref:`modindex`
24
+ * :ref:`search`
lesson02/docs/make.bat ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @ECHO OFF
2
+
3
+ REM Command file for Sphinx documentation
4
+
5
+ if "%SPHINXBUILD%" == "" (
6
+ set SPHINXBUILD=sphinx-build
7
+ )
8
+ set BUILDDIR=_build
9
+ set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
10
+ set I18NSPHINXOPTS=%SPHINXOPTS% .
11
+ if NOT "%PAPER%" == "" (
12
+ set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
13
+ set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
14
+ )
15
+
16
+ if "%1" == "" goto help
17
+
18
+ if "%1" == "help" (
19
+ :help
20
+ echo.Please use `make ^<target^>` where ^<target^> is one of
21
+ echo. html to make standalone HTML files
22
+ echo. dirhtml to make HTML files named index.html in directories
23
+ echo. singlehtml to make a single large HTML file
24
+ echo. pickle to make pickle files
25
+ echo. json to make JSON files
26
+ echo. htmlhelp to make HTML files and a HTML help project
27
+ echo. qthelp to make HTML files and a qthelp project
28
+ echo. devhelp to make HTML files and a Devhelp project
29
+ echo. epub to make an epub
30
+ echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
31
+ echo. text to make text files
32
+ echo. man to make manual pages
33
+ echo. texinfo to make Texinfo files
34
+ echo. gettext to make PO message catalogs
35
+ echo. changes to make an overview over all changed/added/deprecated items
36
+ echo. linkcheck to check all external links for integrity
37
+ echo. doctest to run all doctests embedded in the documentation if enabled
38
+ goto end
39
+ )
40
+
41
+ if "%1" == "clean" (
42
+ for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
43
+ del /q /s %BUILDDIR%\*
44
+ goto end
45
+ )
46
+
47
+ if "%1" == "html" (
48
+ %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
49
+ if errorlevel 1 exit /b 1
50
+ echo.
51
+ echo.Build finished. The HTML pages are in %BUILDDIR%/html.
52
+ goto end
53
+ )
54
+
55
+ if "%1" == "dirhtml" (
56
+ %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
57
+ if errorlevel 1 exit /b 1
58
+ echo.
59
+ echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
60
+ goto end
61
+ )
62
+
63
+ if "%1" == "singlehtml" (
64
+ %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
65
+ if errorlevel 1 exit /b 1
66
+ echo.
67
+ echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
68
+ goto end
69
+ )
70
+
71
+ if "%1" == "pickle" (
72
+ %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
73
+ if errorlevel 1 exit /b 1
74
+ echo.
75
+ echo.Build finished; now you can process the pickle files.
76
+ goto end
77
+ )
78
+
79
+ if "%1" == "json" (
80
+ %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
81
+ if errorlevel 1 exit /b 1
82
+ echo.
83
+ echo.Build finished; now you can process the JSON files.
84
+ goto end
85
+ )
86
+
87
+ if "%1" == "htmlhelp" (
88
+ %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
89
+ if errorlevel 1 exit /b 1
90
+ echo.
91
+ echo.Build finished; now you can run HTML Help Workshop with the ^
92
+ .hhp project file in %BUILDDIR%/htmlhelp.
93
+ goto end
94
+ )
95
+
96
+ if "%1" == "qthelp" (
97
+ %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
98
+ if errorlevel 1 exit /b 1
99
+ echo.
100
+ echo.Build finished; now you can run "qcollectiongenerator" with the ^
101
+ .qhcp project file in %BUILDDIR%/qthelp, like this:
102
+ echo.^> qcollectiongenerator %BUILDDIR%\qthelp\lesson02.qhcp
103
+ echo.To view the help file:
104
+ echo.^> assistant -collectionFile %BUILDDIR%\qthelp\lesson02.ghc
105
+ goto end
106
+ )
107
+
108
+ if "%1" == "devhelp" (
109
+ %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
110
+ if errorlevel 1 exit /b 1
111
+ echo.
112
+ echo.Build finished.
113
+ goto end
114
+ )
115
+
116
+ if "%1" == "epub" (
117
+ %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
118
+ if errorlevel 1 exit /b 1
119
+ echo.
120
+ echo.Build finished. The epub file is in %BUILDDIR%/epub.
121
+ goto end
122
+ )
123
+
124
+ if "%1" == "latex" (
125
+ %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
126
+ if errorlevel 1 exit /b 1
127
+ echo.
128
+ echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
129
+ goto end
130
+ )
131
+
132
+ if "%1" == "text" (
133
+ %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
134
+ if errorlevel 1 exit /b 1
135
+ echo.
136
+ echo.Build finished. The text files are in %BUILDDIR%/text.
137
+ goto end
138
+ )
139
+
140
+ if "%1" == "man" (
141
+ %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
142
+ if errorlevel 1 exit /b 1
143
+ echo.
144
+ echo.Build finished. The manual pages are in %BUILDDIR%/man.
145
+ goto end
146
+ )
147
+
148
+ if "%1" == "texinfo" (
149
+ %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
150
+ if errorlevel 1 exit /b 1
151
+ echo.
152
+ echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
153
+ goto end
154
+ )
155
+
156
+ if "%1" == "gettext" (
157
+ %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
158
+ if errorlevel 1 exit /b 1
159
+ echo.
160
+ echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
161
+ goto end
162
+ )
163
+
164
+ if "%1" == "changes" (
165
+ %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
166
+ if errorlevel 1 exit /b 1
167
+ echo.
168
+ echo.The overview file is in %BUILDDIR%/changes.
169
+ goto end
170
+ )
171
+
172
+ if "%1" == "linkcheck" (
173
+ %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
174
+ if errorlevel 1 exit /b 1
175
+ echo.
176
+ echo.Link check complete; look for any errors in the above output ^
177
+ or in %BUILDDIR%/linkcheck/output.txt.
178
+ goto end
179
+ )
180
+
181
+ if "%1" == "doctest" (
182
+ %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
183
+ if errorlevel 1 exit /b 1
184
+ echo.
185
+ echo.Testing of doctests in the sources finished, look at the ^
186
+ results in %BUILDDIR%/doctest/output.txt.
187
+ goto end
188
+ )
189
+
190
+ :end
lesson02/models/.gitkeep ADDED
File without changes
lesson02/notebooks/.gitkeep ADDED
File without changes
lesson02/notebooks/Lesson02.ipynb ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stderr",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.\n",
13
+ " warnings.warn(\n",
14
+ "/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=ResNet34_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet34_Weights.DEFAULT` to get the most up-to-date weights.\n",
15
+ " warnings.warn(msg)\n"
16
+ ]
17
+ }
18
+ ],
19
+ "source": [
20
+ "#id first_training\n",
21
+ "#caption Results from the first training\n",
22
+ "# CLICK ME\n",
23
+ "#|export\n",
24
+ "from fastai.vision.all import *\n",
25
+ "path = untar_data(URLs.PETS)/'images'\n",
26
+ "\n",
27
+ "def is_cat(x): return x[0].isupper()\n",
28
+ "dls = ImageDataLoaders.from_name_func(\n",
29
+ " path, get_image_files(path), \n",
30
+ " valid_pct=0.2, \n",
31
+ " seed=42,\n",
32
+ " label_func=is_cat, \n",
33
+ " item_tfms=Resize(224)\n",
34
+ ")\n",
35
+ "\n",
36
+ "learn = vision_learner(dls, resnet34, metrics=error_rate)\n",
37
+ "learn.fine_tune(1)"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "execution_count": 6,
43
+ "metadata": {},
44
+ "outputs": [
45
+ {
46
+ "data": {
47
+ "application/vnd.jupyter.widget-view+json": {
48
+ "model_id": "7714f88d5b1a4e198c60d4303a7dbf50",
49
+ "version_major": 2,
50
+ "version_minor": 0
51
+ },
52
+ "text/plain": [
53
+ "FileUpload(value=(), description='Upload')"
54
+ ]
55
+ },
56
+ "metadata": {},
57
+ "output_type": "display_data"
58
+ }
59
+ ],
60
+ "source": [
61
+ "\n",
62
+ "from ipywidgets import widgets\n",
63
+ "from IPython.display import display\n",
64
+ "uploader = widgets.FileUpload()\n",
65
+ "display(uploader)"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 10,
71
+ "metadata": {},
72
+ "outputs": [],
73
+ "source": [
74
+ "#|export\n",
75
+ "# For the book, we can't actually click an upload button, so we fake it\n",
76
+ "uploader = SimpleNamespace(data = ['../data/interim/th-1.webp'])"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 11,
82
+ "metadata": {},
83
+ "outputs": [
84
+ {
85
+ "data": {
86
+ "text/html": [
87
+ "\n",
88
+ " <div>\n",
89
+ " <progress value='0' class='' max='1' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
90
+ " 0.00% [0/1 00:00&lt;?]\n",
91
+ " </div>\n",
92
+ " "
93
+ ],
94
+ "text/plain": [
95
+ "<IPython.core.display.HTML object>"
96
+ ]
97
+ },
98
+ "metadata": {},
99
+ "output_type": "display_data"
100
+ },
101
+ {
102
+ "ename": "AttributeError",
103
+ "evalue": "read",
104
+ "output_type": "error",
105
+ "traceback": [
106
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
107
+ "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
108
+ "Cell \u001b[0;32mIn[11], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m img \u001b[39m=\u001b[39m PILImage\u001b[39m.\u001b[39mcreate(uploader\u001b[39m.\u001b[39mdata[\u001b[39m0\u001b[39m])\n\u001b[0;32m----> 2\u001b[0m is_cat,_,probs \u001b[39m=\u001b[39m learn\u001b[39m.\u001b[39;49mpredict(img)\n\u001b[1;32m 3\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mIs this a cat?: \u001b[39m\u001b[39m{\u001b[39;00mis_cat\u001b[39m}\u001b[39;00m\u001b[39m.\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 4\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mProbability it\u001b[39m\u001b[39m'\u001b[39m\u001b[39ms a cat: \u001b[39m\u001b[39m{\u001b[39;00mprobs[\u001b[39m1\u001b[39m]\u001b[39m.\u001b[39mitem()\u001b[39m:\u001b[39;00m\u001b[39m.6f\u001b[39m\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n",
109
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/learner.py:321\u001b[0m, in \u001b[0;36mLearner.predict\u001b[0;34m(self, item, rm_type_tfms, with_input)\u001b[0m\n\u001b[1;32m 319\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mpredict\u001b[39m(\u001b[39mself\u001b[39m, item, rm_type_tfms\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, with_input\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m):\n\u001b[1;32m 320\u001b[0m dl \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdls\u001b[39m.\u001b[39mtest_dl([item], rm_type_tfms\u001b[39m=\u001b[39mrm_type_tfms, num_workers\u001b[39m=\u001b[39m\u001b[39m0\u001b[39m)\n\u001b[0;32m--> 321\u001b[0m inp,preds,_,dec_preds \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mget_preds(dl\u001b[39m=\u001b[39;49mdl, with_input\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m, with_decoded\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m)\n\u001b[1;32m 322\u001b[0m i \u001b[39m=\u001b[39m \u001b[39mgetattr\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdls, \u001b[39m'\u001b[39m\u001b[39mn_inp\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m-\u001b[39m\u001b[39m1\u001b[39m)\n\u001b[1;32m 323\u001b[0m inp \u001b[39m=\u001b[39m (inp,) \u001b[39mif\u001b[39;00m i\u001b[39m==\u001b[39m\u001b[39m1\u001b[39m \u001b[39melse\u001b[39;00m tuplify(inp)\n",
110
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/learner.py:308\u001b[0m, in \u001b[0;36mLearner.get_preds\u001b[0;34m(self, ds_idx, dl, with_input, with_decoded, with_loss, act, inner, reorder, cbs, **kwargs)\u001b[0m\n\u001b[1;32m 306\u001b[0m \u001b[39mif\u001b[39;00m with_loss: ctx_mgrs\u001b[39m.\u001b[39mappend(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mloss_not_reduced())\n\u001b[1;32m 307\u001b[0m \u001b[39mwith\u001b[39;00m ContextManagers(ctx_mgrs):\n\u001b[0;32m--> 308\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_do_epoch_validate(dl\u001b[39m=\u001b[39;49mdl)\n\u001b[1;32m 309\u001b[0m \u001b[39mif\u001b[39;00m act \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m: act \u001b[39m=\u001b[39m getcallable(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mloss_func, \u001b[39m'\u001b[39m\u001b[39mactivation\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m 310\u001b[0m res \u001b[39m=\u001b[39m cb\u001b[39m.\u001b[39mall_tensors()\n",
111
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/learner.py:244\u001b[0m, in \u001b[0;36mLearner._do_epoch_validate\u001b[0;34m(self, ds_idx, dl)\u001b[0m\n\u001b[1;32m 242\u001b[0m \u001b[39mif\u001b[39;00m dl \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m: dl \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdls[ds_idx]\n\u001b[1;32m 243\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdl \u001b[39m=\u001b[39m dl\n\u001b[0;32m--> 244\u001b[0m \u001b[39mwith\u001b[39;00m torch\u001b[39m.\u001b[39mno_grad(): \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_with_events(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mall_batches, \u001b[39m'\u001b[39;49m\u001b[39mvalidate\u001b[39;49m\u001b[39m'\u001b[39;49m, CancelValidException)\n",
112
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/learner.py:199\u001b[0m, in \u001b[0;36mLearner._with_events\u001b[0;34m(self, f, event_type, ex, final)\u001b[0m\n\u001b[1;32m 198\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_with_events\u001b[39m(\u001b[39mself\u001b[39m, f, event_type, ex, final\u001b[39m=\u001b[39mnoop):\n\u001b[0;32m--> 199\u001b[0m \u001b[39mtry\u001b[39;00m: \u001b[39mself\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mbefore_\u001b[39m\u001b[39m{\u001b[39;00mevent_type\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m); f()\n\u001b[1;32m 200\u001b[0m \u001b[39mexcept\u001b[39;00m ex: \u001b[39mself\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mafter_cancel_\u001b[39m\u001b[39m{\u001b[39;00mevent_type\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m)\n\u001b[1;32m 201\u001b[0m \u001b[39mself\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mafter_\u001b[39m\u001b[39m{\u001b[39;00mevent_type\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m); final()\n",
113
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/learner.py:205\u001b[0m, in \u001b[0;36mLearner.all_batches\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 203\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mall_batches\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[1;32m 204\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mn_iter \u001b[39m=\u001b[39m \u001b[39mlen\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdl)\n\u001b[0;32m--> 205\u001b[0m \u001b[39mfor\u001b[39;00m o \u001b[39min\u001b[39;00m \u001b[39menumerate\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdl): \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mone_batch(\u001b[39m*\u001b[39mo)\n",
114
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/data/load.py:127\u001b[0m, in \u001b[0;36mDataLoader.__iter__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 125\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mbefore_iter()\n\u001b[1;32m 126\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m__idxs\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mget_idxs() \u001b[39m# called in context of main process (not workers/subprocesses)\u001b[39;00m\n\u001b[0;32m--> 127\u001b[0m \u001b[39mfor\u001b[39;00m b \u001b[39min\u001b[39;00m _loaders[\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfake_l\u001b[39m.\u001b[39mnum_workers\u001b[39m==\u001b[39m\u001b[39m0\u001b[39m](\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mfake_l):\n\u001b[1;32m 128\u001b[0m \u001b[39m# pin_memory causes tuples to be converted to lists, so convert them back to tuples\u001b[39;00m\n\u001b[1;32m 129\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mpin_memory \u001b[39mand\u001b[39;00m \u001b[39mtype\u001b[39m(b) \u001b[39m==\u001b[39m \u001b[39mlist\u001b[39m: b \u001b[39m=\u001b[39m \u001b[39mtuple\u001b[39m(b)\n\u001b[1;32m 130\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdevice \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m: b \u001b[39m=\u001b[39m to_device(b, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdevice)\n",
115
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/torch/utils/data/dataloader.py:628\u001b[0m, in \u001b[0;36m_BaseDataLoaderIter.__next__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 625\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_sampler_iter \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 626\u001b[0m \u001b[39m# TODO(https://github.com/pytorch/pytorch/issues/76750)\u001b[39;00m\n\u001b[1;32m 627\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_reset() \u001b[39m# type: ignore[call-arg]\u001b[39;00m\n\u001b[0;32m--> 628\u001b[0m data \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_next_data()\n\u001b[1;32m 629\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_num_yielded \u001b[39m+\u001b[39m\u001b[39m=\u001b[39m \u001b[39m1\u001b[39m\n\u001b[1;32m 630\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_dataset_kind \u001b[39m==\u001b[39m _DatasetKind\u001b[39m.\u001b[39mIterable \u001b[39mand\u001b[39;00m \\\n\u001b[1;32m 631\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_IterableDataset_len_called \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m \\\n\u001b[1;32m 632\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_num_yielded \u001b[39m>\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_IterableDataset_len_called:\n",
116
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/torch/utils/data/dataloader.py:671\u001b[0m, in \u001b[0;36m_SingleProcessDataLoaderIter._next_data\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 669\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_next_data\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[1;32m 670\u001b[0m index \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_next_index() \u001b[39m# may raise StopIteration\u001b[39;00m\n\u001b[0;32m--> 671\u001b[0m data \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_dataset_fetcher\u001b[39m.\u001b[39;49mfetch(index) \u001b[39m# may raise StopIteration\u001b[39;00m\n\u001b[1;32m 672\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_pin_memory:\n\u001b[1;32m 673\u001b[0m data \u001b[39m=\u001b[39m _utils\u001b[39m.\u001b[39mpin_memory\u001b[39m.\u001b[39mpin_memory(data, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_pin_memory_device)\n",
117
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py:43\u001b[0m, in \u001b[0;36m_IterableDatasetFetcher.fetch\u001b[0;34m(self, possibly_batched_index)\u001b[0m\n\u001b[1;32m 41\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mStopIteration\u001b[39;00m\n\u001b[1;32m 42\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m---> 43\u001b[0m data \u001b[39m=\u001b[39m \u001b[39mnext\u001b[39;49m(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mdataset_iter)\n\u001b[1;32m 44\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcollate_fn(data)\n",
118
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/data/load.py:138\u001b[0m, in \u001b[0;36mDataLoader.create_batches\u001b[0;34m(self, samps)\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdataset \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m: \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mit \u001b[39m=\u001b[39m \u001b[39miter\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdataset)\n\u001b[1;32m 137\u001b[0m res \u001b[39m=\u001b[39m \u001b[39mfilter\u001b[39m(\u001b[39mlambda\u001b[39;00m o:o \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m, \u001b[39mmap\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdo_item, samps))\n\u001b[0;32m--> 138\u001b[0m \u001b[39myield from\u001b[39;00m \u001b[39mmap\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdo_batch, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mchunkify(res))\n",
119
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastcore/basics.py:230\u001b[0m, in \u001b[0;36mchunked\u001b[0;34m(it, chunk_sz, drop_last, n_chunks)\u001b[0m\n\u001b[1;32m 228\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(it, Iterator): it \u001b[39m=\u001b[39m \u001b[39miter\u001b[39m(it)\n\u001b[1;32m 229\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mTrue\u001b[39;00m:\n\u001b[0;32m--> 230\u001b[0m res \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39;49m(itertools\u001b[39m.\u001b[39;49mislice(it, chunk_sz))\n\u001b[1;32m 231\u001b[0m \u001b[39mif\u001b[39;00m res \u001b[39mand\u001b[39;00m (\u001b[39mlen\u001b[39m(res)\u001b[39m==\u001b[39mchunk_sz \u001b[39mor\u001b[39;00m \u001b[39mnot\u001b[39;00m drop_last): \u001b[39myield\u001b[39;00m res\n\u001b[1;32m 232\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39m(res)\u001b[39m<\u001b[39mchunk_sz: \u001b[39mreturn\u001b[39;00m\n",
120
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/data/load.py:153\u001b[0m, in \u001b[0;36mDataLoader.do_item\u001b[0;34m(self, s)\u001b[0m\n\u001b[1;32m 152\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mdo_item\u001b[39m(\u001b[39mself\u001b[39m, s):\n\u001b[0;32m--> 153\u001b[0m \u001b[39mtry\u001b[39;00m: \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mafter_item(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mcreate_item(s))\n\u001b[1;32m 154\u001b[0m \u001b[39mexcept\u001b[39;00m SkipItemException: \u001b[39mreturn\u001b[39;00m \u001b[39mNone\u001b[39;00m\n",
121
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/data/load.py:160\u001b[0m, in \u001b[0;36mDataLoader.create_item\u001b[0;34m(self, s)\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mcreate_item\u001b[39m(\u001b[39mself\u001b[39m, s):\n\u001b[0;32m--> 160\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mindexed: \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mdataset[s \u001b[39mor\u001b[39;49;00m \u001b[39m0\u001b[39;49m]\n\u001b[1;32m 161\u001b[0m \u001b[39melif\u001b[39;00m s \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m: \u001b[39mreturn\u001b[39;00m \u001b[39mnext\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mit)\n\u001b[1;32m 162\u001b[0m \u001b[39melse\u001b[39;00m: \u001b[39mraise\u001b[39;00m \u001b[39mIndexError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mCannot index an iterable dataset numerically - must use `None`.\u001b[39m\u001b[39m\"\u001b[39m)\n",
122
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/data/core.py:458\u001b[0m, in \u001b[0;36mDatasets.__getitem__\u001b[0;34m(self, it)\u001b[0m\n\u001b[1;32m 457\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__getitem__\u001b[39m(\u001b[39mself\u001b[39m, it):\n\u001b[0;32m--> 458\u001b[0m res \u001b[39m=\u001b[39m \u001b[39mtuple\u001b[39m([tl[it] \u001b[39mfor\u001b[39;00m tl \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtls])\n\u001b[1;32m 459\u001b[0m \u001b[39mreturn\u001b[39;00m res \u001b[39mif\u001b[39;00m is_indexer(it) \u001b[39melse\u001b[39;00m \u001b[39mlist\u001b[39m(\u001b[39mzip\u001b[39m(\u001b[39m*\u001b[39mres))\n",
123
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/data/core.py:458\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 457\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__getitem__\u001b[39m(\u001b[39mself\u001b[39m, it):\n\u001b[0;32m--> 458\u001b[0m res \u001b[39m=\u001b[39m \u001b[39mtuple\u001b[39m([tl[it] \u001b[39mfor\u001b[39;00m tl \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtls])\n\u001b[1;32m 459\u001b[0m \u001b[39mreturn\u001b[39;00m res \u001b[39mif\u001b[39;00m is_indexer(it) \u001b[39melse\u001b[39;00m \u001b[39mlist\u001b[39m(\u001b[39mzip\u001b[39m(\u001b[39m*\u001b[39mres))\n",
124
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/data/core.py:417\u001b[0m, in \u001b[0;36mTfmdLists.__getitem__\u001b[0;34m(self, idx)\u001b[0m\n\u001b[1;32m 415\u001b[0m res \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39m\u001b[39m__getitem__\u001b[39m(idx)\n\u001b[1;32m 416\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_after_item \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m: \u001b[39mreturn\u001b[39;00m res\n\u001b[0;32m--> 417\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_after_item(res) \u001b[39mif\u001b[39;00m is_indexer(idx) \u001b[39melse\u001b[39;00m res\u001b[39m.\u001b[39mmap(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_after_item)\n",
125
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/data/core.py:377\u001b[0m, in \u001b[0;36mTfmdLists._after_item\u001b[0;34m(self, o)\u001b[0m\n\u001b[0;32m--> 377\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_after_item\u001b[39m(\u001b[39mself\u001b[39m, o): \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtfms(o)\n",
126
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastcore/transform.py:208\u001b[0m, in \u001b[0;36mPipeline.__call__\u001b[0;34m(self, o)\u001b[0m\n\u001b[0;32m--> 208\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\u001b[39mself\u001b[39m, o): \u001b[39mreturn\u001b[39;00m compose_tfms(o, tfms\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mfs, split_idx\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msplit_idx)\n",
127
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastcore/transform.py:158\u001b[0m, in \u001b[0;36mcompose_tfms\u001b[0;34m(x, tfms, is_enc, reverse, **kwargs)\u001b[0m\n\u001b[1;32m 156\u001b[0m \u001b[39mfor\u001b[39;00m f \u001b[39min\u001b[39;00m tfms:\n\u001b[1;32m 157\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m is_enc: f \u001b[39m=\u001b[39m f\u001b[39m.\u001b[39mdecode\n\u001b[0;32m--> 158\u001b[0m x \u001b[39m=\u001b[39m f(x, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 159\u001b[0m \u001b[39mreturn\u001b[39;00m x\n",
128
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastcore/transform.py:81\u001b[0m, in \u001b[0;36mTransform.__call__\u001b[0;34m(self, x, **kwargs)\u001b[0m\n\u001b[0;32m---> 81\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\u001b[39mself\u001b[39m, x, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs): \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_call(\u001b[39m'\u001b[39;49m\u001b[39mencodes\u001b[39;49m\u001b[39m'\u001b[39;49m, x, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
129
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastcore/transform.py:91\u001b[0m, in \u001b[0;36mTransform._call\u001b[0;34m(self, fn, x, split_idx, **kwargs)\u001b[0m\n\u001b[1;32m 89\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_call\u001b[39m(\u001b[39mself\u001b[39m, fn, x, split_idx\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m 90\u001b[0m \u001b[39mif\u001b[39;00m split_idx\u001b[39m!=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msplit_idx \u001b[39mand\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39msplit_idx \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m: \u001b[39mreturn\u001b[39;00m x\n\u001b[0;32m---> 91\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_do_call(\u001b[39mgetattr\u001b[39;49m(\u001b[39mself\u001b[39;49m, fn), x, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
130
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastcore/transform.py:97\u001b[0m, in \u001b[0;36mTransform._do_call\u001b[0;34m(self, f, x, **kwargs)\u001b[0m\n\u001b[1;32m 95\u001b[0m \u001b[39mif\u001b[39;00m f \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m: \u001b[39mreturn\u001b[39;00m x\n\u001b[1;32m 96\u001b[0m ret \u001b[39m=\u001b[39m f\u001b[39m.\u001b[39mreturns(x) \u001b[39mif\u001b[39;00m \u001b[39mhasattr\u001b[39m(f,\u001b[39m'\u001b[39m\u001b[39mreturns\u001b[39m\u001b[39m'\u001b[39m) \u001b[39melse\u001b[39;00m \u001b[39mNone\u001b[39;00m\n\u001b[0;32m---> 97\u001b[0m \u001b[39mreturn\u001b[39;00m retain_type(f(x, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs), x, ret)\n\u001b[1;32m 98\u001b[0m res \u001b[39m=\u001b[39m \u001b[39mtuple\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_do_call(f, x_, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs) \u001b[39mfor\u001b[39;00m x_ \u001b[39min\u001b[39;00m x)\n\u001b[1;32m 99\u001b[0m \u001b[39mreturn\u001b[39;00m retain_type(res, x)\n",
131
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastcore/dispatch.py:120\u001b[0m, in \u001b[0;36mTypeDispatch.__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 118\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39minst \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m: f \u001b[39m=\u001b[39m MethodType(f, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39minst)\n\u001b[1;32m 119\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mowner \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m: f \u001b[39m=\u001b[39m MethodType(f, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mowner)\n\u001b[0;32m--> 120\u001b[0m \u001b[39mreturn\u001b[39;00m f(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
132
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/vision/core.py:125\u001b[0m, in \u001b[0;36mPILBase.create\u001b[0;34m(cls, fn, **kwargs)\u001b[0m\n\u001b[1;32m 123\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(fn,\u001b[39mbytes\u001b[39m): fn \u001b[39m=\u001b[39m io\u001b[39m.\u001b[39mBytesIO(fn)\n\u001b[1;32m 124\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(fn,Image\u001b[39m.\u001b[39mImage) \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(fn,\u001b[39mcls\u001b[39m): \u001b[39mreturn\u001b[39;00m \u001b[39mcls\u001b[39m(fn)\n\u001b[0;32m--> 125\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mcls\u001b[39m(load_image(fn, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mmerge(\u001b[39mcls\u001b[39;49m\u001b[39m.\u001b[39;49m_open_args, kwargs)))\n",
133
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/fastai/vision/core.py:98\u001b[0m, in \u001b[0;36mload_image\u001b[0;34m(fn, mode)\u001b[0m\n\u001b[1;32m 96\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mload_image\u001b[39m(fn, mode\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m):\n\u001b[1;32m 97\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mOpen and load a `PIL.Image` and convert to `mode`\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m---> 98\u001b[0m im \u001b[39m=\u001b[39m Image\u001b[39m.\u001b[39;49mopen(fn)\n\u001b[1;32m 99\u001b[0m im\u001b[39m.\u001b[39mload()\n\u001b[1;32m 100\u001b[0m im \u001b[39m=\u001b[39m im\u001b[39m.\u001b[39m_new(im\u001b[39m.\u001b[39mim)\n",
134
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/PIL/Image.py:3236\u001b[0m, in \u001b[0;36mopen\u001b[0;34m(fp, mode, formats)\u001b[0m\n\u001b[1;32m 3233\u001b[0m fp \u001b[39m=\u001b[39m io\u001b[39m.\u001b[39mBytesIO(fp\u001b[39m.\u001b[39mread())\n\u001b[1;32m 3234\u001b[0m exclusive_fp \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n\u001b[0;32m-> 3236\u001b[0m prefix \u001b[39m=\u001b[39m fp\u001b[39m.\u001b[39;49mread(\u001b[39m16\u001b[39m)\n\u001b[1;32m 3238\u001b[0m preinit()\n\u001b[1;32m 3240\u001b[0m accept_warnings \u001b[39m=\u001b[39m []\n",
135
+ "File \u001b[0;32m/opt/homebrew/Caskroom/mambaforge/base/lib/python3.10/site-packages/PIL/Image.py:529\u001b[0m, in \u001b[0;36mImage.__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 527\u001b[0m deprecate(\u001b[39m\"\u001b[39m\u001b[39mImage categories\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m10\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mis_animated\u001b[39m\u001b[39m\"\u001b[39m, plural\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n\u001b[1;32m 528\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_category\n\u001b[0;32m--> 529\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mAttributeError\u001b[39;00m(name)\n",
136
+ "\u001b[0;31mAttributeError\u001b[0m: read"
137
+ ]
138
+ }
139
+ ],
140
+ "source": [
141
+ "#|export\n",
142
+ "img = PILImage.create(uploader.data[0])\n",
143
+ "is_cat,_,probs = learn.predict(img)\n",
144
+ "print(f\"Is this a cat?: {is_cat}.\")\n",
145
+ "print(f\"Probability it's a cat: {probs[1].item():.6f}\")"
146
+ ]
147
+ }
148
+ ],
149
+ "metadata": {
150
+ "kernelspec": {
151
+ "display_name": "base",
152
+ "language": "python",
153
+ "name": "python3"
154
+ },
155
+ "language_info": {
156
+ "codemirror_mode": {
157
+ "name": "ipython",
158
+ "version": 3
159
+ },
160
+ "file_extension": ".py",
161
+ "mimetype": "text/x-python",
162
+ "name": "python",
163
+ "nbconvert_exporter": "python",
164
+ "pygments_lexer": "ipython3",
165
+ "version": "3.10.9"
166
+ },
167
+ "orig_nbformat": 4,
168
+ "vscode": {
169
+ "interpreter": {
170
+ "hash": "59f3145cc67fcda0343c2852f1f97113a2e6e98841e887156424448e7071ad54"
171
+ }
172
+ }
173
+ },
174
+ "nbformat": 4,
175
+ "nbformat_minor": 2
176
+ }
lesson02/references/.gitkeep ADDED
File without changes
lesson02/reports/.gitkeep ADDED
File without changes
lesson02/reports/figures/.gitkeep ADDED
File without changes
lesson02/requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # local package
2
+ #-e .
3
+
4
+ # external requirements
5
+ click
6
+ Sphinx
7
+ coverage
8
+ awscli
9
+ flake8
10
+ python-dotenv>=0.5.1
lesson02/setup.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from setuptools import find_packages, setup
2
+
3
+ setup(
4
+ name='src',
5
+ packages=find_packages(),
6
+ version='0.1.0',
7
+ description='Lesson02 fastai',
8
+ author='Byron Wright',
9
+ license='MIT',
10
+ )
lesson02/src/__init__.py ADDED
File without changes
lesson02/src/app.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ def greet(name):
5
+ return "Hello " + name + "!!"
6
+
7
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
8
+ iface.launch()
lesson02/src/data/.gitkeep ADDED
File without changes
lesson02/src/data/__init__.py ADDED
File without changes
lesson02/src/data/make_dataset.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ import logging
3
+ from pathlib import Path
4
+
5
+ import click
6
+ from dotenv import find_dotenv, load_dotenv
7
+
8
+
9
+ @click.command()
10
+ @click.argument('input_filepath', type=click.Path(exists=True))
11
+ @click.argument('output_filepath', type=click.Path())
12
+ def main(input_filepath, output_filepath):
13
+ """ Runs data processing scripts to turn raw data from (../raw) into
14
+ cleaned data ready to be analyzed (saved in ../processed).
15
+ """
16
+ logger = logging.getLogger(__name__)
17
+ logger.info('making final data set from raw data')
18
+
19
+
20
+ if __name__ == '__main__':
21
+ log_fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
22
+ logging.basicConfig(level=logging.INFO, format=log_fmt)
23
+
24
+ # not used in this stub but often useful for finding various files
25
+ project_dir = Path(__file__).resolve().parents[2]
26
+
27
+ # find .env automagically by walking up directories until it's found, then
28
+ # load up the .env entries as environment variables
29
+ load_dotenv(find_dotenv())
30
+
31
+ main()
lesson02/src/fastai-export.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # %%
2
+ #id first_training
3
+ #caption Results from the first training
4
+ # CLICK ME
5
+ #|export
6
+ from fastai.vision.all import *
7
+
8
+ path = untar_data(URLs.PETS)/'images'
9
+
10
+ def is_cat(x): return x[0].isupper()
11
+ dls = ImageDataLoaders.from_name_func(
12
+ path, get_image_files(path),
13
+ valid_pct=0.2,
14
+ seed=42,
15
+ label_func=is_cat,
16
+ item_tfms=Resize(224)
17
+ )
18
+
19
+ learn = vision_learner(dls, resnet34, metrics=error_rate)
20
+ learn.fine_tune(1)
21
+
22
+ # %%
23
+
24
+ from IPython.display import display
25
+ from ipywidgets import widgets
26
+
27
+ uploader = widgets.FileUpload()
28
+ display(uploader)
29
+
30
+ # %%
31
+ #|export
32
+ # For the book, we can't actually click an upload button, so we fake it
33
+ uploader = SimpleNamespace(data = ['data/interim/th-1.webp'])
34
+
35
+ # %%
36
+ #|export
37
+ img = PILImage.create(uploader.data[0])
38
+ is_cat,_,probs = learn.predict(img)
39
+ print(f"Is this a cat?: {is_cat}.")
40
+ print(f"Probability it's a cat: {probs[1].item():.6f}")
41
+
42
+
lesson02/src/features/.gitkeep ADDED
File without changes
lesson02/src/features/__init__.py ADDED
File without changes
lesson02/src/features/build_features.py ADDED
File without changes
lesson02/src/models/.gitkeep ADDED
File without changes
lesson02/src/models/__init__.py ADDED
File without changes
lesson02/src/models/predict_model.py ADDED
File without changes
lesson02/src/models/train_model.py ADDED
File without changes
lesson02/src/visualization/.gitkeep ADDED
File without changes
lesson02/src/visualization/__init__.py ADDED
File without changes
lesson02/src/visualization/visualize.py ADDED
File without changes
lesson02/test_environment.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+
3
+ REQUIRED_PYTHON = "python3"
4
+
5
+
6
+ def main():
7
+ system_major = sys.version_info.major
8
+ if REQUIRED_PYTHON == "python":
9
+ required_major = 2
10
+ elif REQUIRED_PYTHON == "python3":
11
+ required_major = 3
12
+ else:
13
+ raise ValueError(
14
+ # .format(REQUIRED_PYTHON)
15
+ f"Unrecognized python interpreter: {REQUIRED_PYTHON}"
16
+ )
17
+
18
+ if system_major != required_major:
19
+ raise TypeError(
20
+ f"This project requires Python {required_major}. Found: Python {sys.version}"
21
+ )
22
+ else:
23
+ print(">>> Development environment passes all tests!")
24
+
25
+
26
+ if __name__ == '__main__':
27
+ main()
lesson02/tox.ini ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [flake8]
2
+ max-line-length = 79
3
+ max-complexity = 10