Spaces:
Runtime error
Runtime error
Commit
·
6216ecd
1
Parent(s):
922c280
totally changed the project structure
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitignore +2 -0
- Makefile +0 -2
- README.md +65 -48
- command.py +0 -40
- config.yaml → configs/experiment1.yaml +9 -8
- constants.yaml +3 -0
- docs/Makefile +0 -153
- docs/commands.rst +0 -10
- docs/conf.py +0 -244
- docs/getting-started.rst +0 -6
- docs/index.rst +0 -24
- docs/make.bat +0 -190
- references/.gitkeep +0 -0
- reports/.gitkeep +0 -0
- reports/figures/.gitkeep +0 -0
- requirements.txt +2 -1
- setup.py +1 -1
- src/__init__.py +0 -9
- src/data/.gitkeep +0 -0
- src/data/__init__.py +0 -0
- src/data/make_dataset.py +0 -128
- src/data/visualize_dataset.py +0 -52
- src/features/.gitkeep +0 -0
- src/features/__init__.py +0 -0
- src/features/build_features.py +0 -0
- src/models/.gitkeep +0 -0
- src/models/__init__.py +0 -0
- src/models/predict_model.py +0 -0
- src/models/train_model.py +0 -0
- src/scripts/create_sub_task.py +274 -0
- src/scripts/prepare_dataset.py +31 -0
- src/scripts/visualize_dataset.py +29 -0
- src/simple_regression_colorization/data/datasets/forests.py +79 -0
- src/simple_regression_colorization/data/register_datasets.py +4 -0
- src/simple_regression_colorization/data/visualize_dataset.py +21 -0
- src/simple_regression_colorization/model/base_model_interface.py +14 -0
- src/simple_regression_colorization/model/callbacks.py +1 -0
- src/{data/load_dataset.py → simple_regression_colorization/model/dataloaders.py} +10 -22
- src/simple_regression_colorization/model/losses.py +1 -0
- src/simple_regression_colorization/model/metrics.py +1 -0
- src/simple_regression_colorization/model/models/model_v1.py +30 -0
- src/simple_regression_colorization/model/register_models.py +2 -0
- src/simple_regression_colorization/scripts/create_dataset.py +67 -0
- src/simple_regression_colorization/scripts/create_model.py +46 -0
- src/simple_regression_colorization/validate_config.py +22 -0
- src/utils.py +0 -39
- src/utils/config_loader.py +23 -0
- src/utils/data_utils.py +77 -0
- src/utils/script_utils.py +47 -0
- src/visualization/.gitkeep +0 -0
.gitignore
CHANGED
|
@@ -87,3 +87,5 @@ target/
|
|
| 87 |
|
| 88 |
# Mypy cache
|
| 89 |
.mypy_cache/
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# Mypy cache
|
| 89 |
.mypy_cache/
|
| 90 |
+
|
| 91 |
+
/models
|
Makefile
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
.PHONY: clean data lint requirements sync_data_to_s3 sync_data_from_s3
|
| 2 |
-
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -1,59 +1,76 @@
|
|
| 1 |
-
Image Colorization
|
| 2 |
==============================
|
| 3 |
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 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 |
-
│
|
| 14 |
-
│
|
| 15 |
-
│
|
| 16 |
-
│
|
| 17 |
-
|
| 18 |
-
├──
|
| 19 |
-
|
| 20 |
-
├──
|
| 21 |
-
│
|
| 22 |
-
├──
|
| 23 |
-
│
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 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>
|
| 58 |
|
| 59 |
|
|
|
|
| 1 |
+
## Image Colorization
|
| 2 |
==============================
|
| 3 |
|
| 4 |
+
An deep learning based Image Colorization project.
|
| 5 |
|
| 6 |
+
## FINDINGS
|
| 7 |
+
- the task we want to learn is `image-colorization` but we can accompolish that by doing different types of tasks, I call these **sub-task**, in our content they could be like `regression based image colorization`, `classification(by binning) based colorization`, `GAN based colorization`, `image colorization + scene classication(Let there be colors research paper did this)`.
|
| 8 |
+
- based on analysis and while I was trying to come up with a project file structure I came to know that the data, model, loss, metrics, dataloader all these are very coupled while dealing with a particular task(`image-colorization`) but when we talk about a **sub-task** we have much more freedom.
|
| 9 |
+
- within a sub-task(e.g., regression-unet-learner) we already made a set of rules and now we can use different models without changing the data, or we can change different datasets while using the same model, **so it is important to fix the sub-task we want to do first.**
|
| 10 |
+
- so making a folder for each sub-task seems right as a sub-task has high cohesion and no coupling with any other sub-task.
|
| 11 |
+
|
| 12 |
+
## RULES
|
| 13 |
+
- use **lower_snake_case** for **functions**
|
| 14 |
+
- use **lower_snake_case** for **file_name & folder names**
|
| 15 |
+
- use **UpperCamelCase** for **class names**
|
| 16 |
+
- **sub-task** name should be in **lower-kebab-case**
|
| 17 |
|
| 18 |
+
## Project File Structure
|
| 19 |
+
------------
|
| 20 |
+
.
|
| 21 |
├── LICENSE
|
|
|
|
| 22 |
├── README.md <- The top-level README for developers using this project.
|
| 23 |
+
├── data/
|
| 24 |
+
│ ├── external <- Data from third party sources.
|
| 25 |
+
│ ├── interim <- Intermediate data that has been transformed.
|
| 26 |
+
│ ├── processed <- The final, canonical data sets for modeling.
|
| 27 |
+
│ └── raw <- The original, immutable data dump.
|
| 28 |
+
├── models/ <- Trained models
|
| 29 |
+
├── notebooks/ <- Jupyter notebooks
|
| 30 |
+
├── configs/
|
| 31 |
+
│ ├── experiment1.yaml
|
| 32 |
+
│ ├── experiment2.yaml
|
| 33 |
+
│ ├── experiment3.yaml
|
| 34 |
+
│ └── ...
|
| 35 |
+
└── src/
|
| 36 |
+
├── sub_task_1/
|
| 37 |
+
│ ├── validate_config.py
|
| 38 |
+
│ ├── data/
|
| 39 |
+
│ │ ├── register_datasets.py
|
| 40 |
+
│ │ ├── datasets/
|
| 41 |
+
│ │ │ ├── dataset1.py
|
| 42 |
+
│ │ │ └─��� dataset2.py
|
| 43 |
+
│ ├── model/
|
| 44 |
+
│ │ ├── base_model_interface.py
|
| 45 |
+
│ │ ├── register_models.py
|
| 46 |
+
│ │ ├── models/
|
| 47 |
+
│ │ │ ├── simple_model.py
|
| 48 |
+
│ │ │ └── complex_model.py
|
| 49 |
+
│ │ ├── losses.py
|
| 50 |
+
│ │ ├── metrics.py
|
| 51 |
+
│ │ ├── callbacks.py
|
| 52 |
+
│ │ └── dataloader.py
|
| 53 |
+
│ └── scripts/
|
| 54 |
+
│ ├── create_dataset.py
|
| 55 |
+
│ └── create_model.py
|
| 56 |
+
├── sub_task_2/
|
| 57 |
+
│ └── ...
|
| 58 |
+
├── sub_task_3/
|
| 59 |
+
│ └── ...
|
| 60 |
+
├── scripts/
|
| 61 |
+
│ ├── create_sub_task.py
|
| 62 |
+
│ ├── prepare_dataset.py
|
| 63 |
+
│ ├── visualize_dataset.py
|
| 64 |
+
│ ├── visualize_results.py
|
| 65 |
+
│ ├── train.py
|
| 66 |
+
│ ├── evaluate.py
|
| 67 |
+
│ └── inference.py
|
| 68 |
+
└── utils/
|
| 69 |
+
├── data_utils.py
|
| 70 |
+
└── model_utils.py
|
| 71 |
--------
|
| 72 |
|
| 73 |
+
|
| 74 |
<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>
|
| 75 |
|
| 76 |
|
command.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
import argparse
|
| 2 |
-
import sys
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
# parser = argparse.ArgumentParser()
|
| 6 |
-
# parser.add_argument("category")
|
| 7 |
-
# parser.add_argument("subcommand-args")
|
| 8 |
-
# args = parser.parse_args()
|
| 9 |
-
args = sys.argv
|
| 10 |
-
|
| 11 |
-
# remove "command.py"
|
| 12 |
-
args = args[1:]
|
| 13 |
-
|
| 14 |
-
# print(args)
|
| 15 |
-
subcommand = args[0].lower()
|
| 16 |
-
|
| 17 |
-
subcommand_args = " ".join(args[1:])
|
| 18 |
-
if subcommand=="data":
|
| 19 |
-
command = "py src/data/make_dataset.py "+subcommand_args
|
| 20 |
-
# print(command)
|
| 21 |
-
os.system(command)
|
| 22 |
-
else:
|
| 23 |
-
print("subcommand not supported.")
|
| 24 |
-
|
| 25 |
-
# os.system("py src/__init__.py")
|
| 26 |
-
"""
|
| 27 |
-
download the dataset: data download
|
| 28 |
-
preprocess dataset: data prepare
|
| 29 |
-
visualize dataset: data show
|
| 30 |
-
delete raw & interim dataset dir: data delete --cache
|
| 31 |
-
delete all dataset dir: data delete --all
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
train model: model train
|
| 35 |
-
evaluate model: model evaluate
|
| 36 |
-
inference with model: model predict --image test.jpg --folder images/ -d results/
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.yaml → configs/experiment1.yaml
RENAMED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
processed_dataset_dir: data/processed/
|
| 4 |
-
|
| 5 |
-
# forests or pascal-voc
|
| 6 |
dataset: forests
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
train_size: 0.8
|
|
|
|
| 10 |
shuffle: False
|
| 11 |
-
batch_size: 16
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# mandatory
|
| 2 |
+
task: simple_regression_colorization
|
|
|
|
|
|
|
|
|
|
| 3 |
dataset: forests
|
| 4 |
+
model: model_v1
|
| 5 |
|
| 6 |
+
# common parameters
|
| 7 |
+
seed: 324
|
| 8 |
train_size: 0.8
|
| 9 |
+
image_size: 224
|
| 10 |
shuffle: False
|
|
|
|
| 11 |
|
| 12 |
+
# training related
|
| 13 |
+
batch_size: 16
|
| 14 |
+
epochs: 10
|
constants.yaml
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
RAW_DATASET_DIR: data/raw/
|
| 2 |
+
INTERIM_DATASET_DIR: data/interim/
|
| 3 |
+
PROCESSED_DATASET_DIR: data/processed/
|
docs/Makefile
DELETED
|
@@ -1,153 +0,0 @@
|
|
| 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/project_name.qhcp"
|
| 81 |
-
@echo "To view the help file:"
|
| 82 |
-
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/project_name.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/project_name"
|
| 90 |
-
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/project_name"
|
| 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."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/commands.rst
DELETED
|
@@ -1,10 +0,0 @@
|
|
| 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/`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/conf.py
DELETED
|
@@ -1,244 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#
|
| 3 |
-
# project_name 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'project_name'
|
| 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 = 'project_namedoc'
|
| 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 |
-
'project_name.tex',
|
| 188 |
-
u'project_name Documentation',
|
| 189 |
-
u"Your name (or your organization/company/team)", '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', 'project_name', u'project_name Documentation',
|
| 219 |
-
[u"Your name (or your organization/company/team)"], 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', 'project_name', u'project_name Documentation',
|
| 233 |
-
u"Your name (or your organization/company/team)", 'project_name',
|
| 234 |
-
'A short description of the project.', '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'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/getting-started.rst
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/index.rst
DELETED
|
@@ -1,24 +0,0 @@
|
|
| 1 |
-
.. project_name 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 |
-
project_name 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`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/make.bat
DELETED
|
@@ -1,190 +0,0 @@
|
|
| 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\project_name.qhcp
|
| 103 |
-
echo.To view the help file:
|
| 104 |
-
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\project_name.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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
references/.gitkeep
DELETED
|
File without changes
|
reports/.gitkeep
DELETED
|
File without changes
|
reports/figures/.gitkeep
DELETED
|
File without changes
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
huggingface_hub
|
| 2 |
comet_ml
|
| 3 |
-
scikit-image
|
|
|
|
|
|
| 1 |
huggingface_hub
|
| 2 |
comet_ml
|
| 3 |
+
scikit-image
|
| 4 |
+
cerberus
|
setup.py
CHANGED
|
@@ -7,4 +7,4 @@ setup(
|
|
| 7 |
description='A short description of the project.',
|
| 8 |
author='Your name (or your organization/company/team)',
|
| 9 |
license='MIT',
|
| 10 |
-
)
|
|
|
|
| 7 |
description='A short description of the project.',
|
| 8 |
author='Your name (or your organization/company/team)',
|
| 9 |
license='MIT',
|
| 10 |
+
)
|
src/__init__.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
from src.utils import Config
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
|
| 4 |
-
config = Config("config.yaml")
|
| 5 |
-
# config.raw_dataset_dir = Path(config.raw_dataset_dir)
|
| 6 |
-
# config.interim_dataset_dir = Path(config.interim_dataset_dir)
|
| 7 |
-
# config.processed_dataset_dir = Path(config.processed_dataset_dir)
|
| 8 |
-
|
| 9 |
-
# print(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/data/.gitkeep
DELETED
|
File without changes
|
src/data/__init__.py
DELETED
|
File without changes
|
src/data/make_dataset.py
DELETED
|
@@ -1,128 +0,0 @@
|
|
| 1 |
-
from huggingface_hub import snapshot_download
|
| 2 |
-
import os,sys;sys.path.append(os.getcwd())
|
| 3 |
-
from src import config
|
| 4 |
-
from src.utils import *
|
| 5 |
-
import argparse
|
| 6 |
-
from pathlib import Path
|
| 7 |
-
from zipfile import ZipFile
|
| 8 |
-
from glob import glob
|
| 9 |
-
import cv2
|
| 10 |
-
import numpy as np
|
| 11 |
-
import matplotlib.pyplot as plt
|
| 12 |
-
from tqdm import tqdm
|
| 13 |
-
import shutil
|
| 14 |
-
from src.data.visualize_dataset import visualize_dataset
|
| 15 |
-
|
| 16 |
-
def download_dataset():
|
| 17 |
-
"""Used to download dataset from hugging face
|
| 18 |
-
"""
|
| 19 |
-
print_title(f"Downloading {config.dataset} dataset from hugging face")
|
| 20 |
-
snapshot_download(repo_id="Anuj-Panthri/Image-Colorization-Datasets",
|
| 21 |
-
repo_type="dataset",
|
| 22 |
-
local_dir=config.raw_dataset_dir,
|
| 23 |
-
allow_patterns=f"{config.dataset}/*")
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
def unzip_dataset():
|
| 27 |
-
print_title(f"Unzipping dataset")
|
| 28 |
-
print("Extracting to :",Path(config.interim_dataset_dir)/Path("trainval/"))
|
| 29 |
-
with ZipFile(Path(config.raw_dataset_dir)/Path(f"{config.dataset}/trainval.zip"),"r") as zip:
|
| 30 |
-
zip.extractall(Path(config.interim_dataset_dir)/Path("trainval/"))
|
| 31 |
-
|
| 32 |
-
print("Extracting to :",Path(config.interim_dataset_dir)/Path("test/"))
|
| 33 |
-
with ZipFile(Path(config.raw_dataset_dir)/Path(f"{config.dataset}/test.zip"),"r") as zip:
|
| 34 |
-
zip.extractall(Path(config.interim_dataset_dir)/Path("test/"))
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
def clean_dataset():
|
| 38 |
-
print_title("CLEANING DATASET")
|
| 39 |
-
trainval_dir = Path(config.interim_dataset_dir) / Path("trainval/")
|
| 40 |
-
test_dir = Path(config.interim_dataset_dir) / Path("test/")
|
| 41 |
-
|
| 42 |
-
trainval_paths = glob(str(trainval_dir/Path("*")))
|
| 43 |
-
test_paths = glob(str(test_dir/Path("*")))
|
| 44 |
-
|
| 45 |
-
print("train,test: ",len(trainval_paths),",",len(test_paths),sep="")
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
def clean(image_paths,destination_dir):
|
| 49 |
-
if os.path.exists(destination_dir): shutil.rmtree(destination_dir)
|
| 50 |
-
os.makedirs(destination_dir)
|
| 51 |
-
for i in tqdm(range(len(image_paths))):
|
| 52 |
-
img = cv2.imread(image_paths[i])
|
| 53 |
-
img = cv2.resize(img,[128,128])
|
| 54 |
-
if not is_bw(img):
|
| 55 |
-
shutil.copy(trainval_paths[i],
|
| 56 |
-
destination_dir)
|
| 57 |
-
print("saved to:",destination_dir)
|
| 58 |
-
|
| 59 |
-
destination_dir = Path(config.processed_dataset_dir)/Path("trainval/")
|
| 60 |
-
clean(trainval_paths,destination_dir)
|
| 61 |
-
|
| 62 |
-
destination_dir = Path(config.processed_dataset_dir)/Path("test/")
|
| 63 |
-
clean(test_paths,destination_dir)
|
| 64 |
-
|
| 65 |
-
trainval_dir = Path(config.processed_dataset_dir) / Path("trainval/")
|
| 66 |
-
test_dir = Path(config.processed_dataset_dir) / Path("test/")
|
| 67 |
-
|
| 68 |
-
trainval_paths = glob(str(trainval_dir/Path("*")))
|
| 69 |
-
test_paths = glob(str(test_dir/Path("*")))
|
| 70 |
-
|
| 71 |
-
print("after cleaning train,test: ",len(trainval_paths),",",len(test_paths),sep="")
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
def prepare_dataset():
|
| 75 |
-
print_title(f"Preparing dataset")
|
| 76 |
-
download_dataset()
|
| 77 |
-
unzip_dataset()
|
| 78 |
-
clean_dataset()
|
| 79 |
-
|
| 80 |
-
def delete_cache():
|
| 81 |
-
## clean old interim and raw datasets
|
| 82 |
-
print_title("deleting unused raw and interim dataset dirs")
|
| 83 |
-
if os.path.exists(config.raw_dataset_dir):
|
| 84 |
-
shutil.rmtree(config.raw_dataset_dir)
|
| 85 |
-
if os.path.exists(config.interim_dataset_dir):
|
| 86 |
-
shutil.rmtree(config.interim_dataset_dir)
|
| 87 |
-
|
| 88 |
-
def delete_all():
|
| 89 |
-
## clean all datasets
|
| 90 |
-
print_title("deleting all dataset dirs")
|
| 91 |
-
if os.path.exists(config.raw_dataset_dir):
|
| 92 |
-
shutil.rmtree(config.raw_dataset_dir)
|
| 93 |
-
if os.path.exists(config.interim_dataset_dir):
|
| 94 |
-
shutil.rmtree(config.interim_dataset_dir)
|
| 95 |
-
if os.path.exists(config.processed_dataset_dir):
|
| 96 |
-
shutil.rmtree(config.processed_dataset_dir)
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
if __name__=="__main__":
|
| 100 |
-
parser = argparse.ArgumentParser()
|
| 101 |
-
parser.add_argument("command")
|
| 102 |
-
parser.add_argument("-d","--dataset",default="forests")
|
| 103 |
-
parser.add_argument("--cache",action="store_true",default=True)
|
| 104 |
-
parser.add_argument("--all",action="store_true")
|
| 105 |
-
|
| 106 |
-
"""
|
| 107 |
-
prepare dataset: data prepare
|
| 108 |
-
visualize dataset: data show
|
| 109 |
-
delete raw & interim dataset dir: data delete --cache
|
| 110 |
-
delete all dataset dir: data delete --all
|
| 111 |
-
"""
|
| 112 |
-
|
| 113 |
-
args = parser.parse_args()
|
| 114 |
-
# print(args)
|
| 115 |
-
|
| 116 |
-
if args.command=="prepare":
|
| 117 |
-
prepare_dataset()
|
| 118 |
-
|
| 119 |
-
elif args.command=="show":
|
| 120 |
-
visualize_dataset()
|
| 121 |
-
|
| 122 |
-
elif args.command=="delete":
|
| 123 |
-
if(args.all): delete_all()
|
| 124 |
-
elif(args.cache): delete_cache()
|
| 125 |
-
|
| 126 |
-
else:
|
| 127 |
-
print("unsupported")
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/data/visualize_dataset.py
DELETED
|
@@ -1,52 +0,0 @@
|
|
| 1 |
-
import os,sys;sys.path.append(os.getcwd())
|
| 2 |
-
from src.data.load_dataset import get_ds,get_datasets
|
| 3 |
-
from src import config
|
| 4 |
-
from src.utils import *
|
| 5 |
-
import matplotlib.pyplot as plt
|
| 6 |
-
import cv2
|
| 7 |
-
import math
|
| 8 |
-
|
| 9 |
-
def see_batch(L_batch,AB_batch,show_L=False,cols=4,row_size=5,col_size=5,title=None):
|
| 10 |
-
n = L_batch.shape[0]
|
| 11 |
-
rows = math.ceil(n/cols)
|
| 12 |
-
fig = plt.figure(figsize=(col_size*cols,row_size*rows))
|
| 13 |
-
if title:
|
| 14 |
-
plt.title(title)
|
| 15 |
-
plt.axis("off")
|
| 16 |
-
|
| 17 |
-
for i in range(n):
|
| 18 |
-
fig.add_subplot(rows,cols,i+1)
|
| 19 |
-
L,AB = L_batch[i],AB_batch[i]
|
| 20 |
-
L,AB = rescale_L(L), rescale_AB(AB)
|
| 21 |
-
# print(L.shape,AB.shape)
|
| 22 |
-
img = np.concatenate([L,AB],axis=-1)
|
| 23 |
-
img = cv2.cvtColor(img,cv2.COLOR_LAB2RGB)*255
|
| 24 |
-
# print(img.min(),img.max())
|
| 25 |
-
if show_L:
|
| 26 |
-
L = np.tile(L,(1,1,3))/100*255
|
| 27 |
-
img = np.concatenate([L,img],axis=1)
|
| 28 |
-
plt.imshow(img.astype("uint8"))
|
| 29 |
-
plt.show()
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
def visualize_dataset():
|
| 33 |
-
train_ds,val_ds,test_ds = get_datasets()
|
| 34 |
-
L_batch,AB_batch = next(iter(train_ds))
|
| 35 |
-
L_batch,AB_batch = L_batch.numpy(), AB_batch.numpy()
|
| 36 |
-
see_batch(L_batch,
|
| 37 |
-
AB_batch,
|
| 38 |
-
title="training dataset")
|
| 39 |
-
|
| 40 |
-
L_batch,AB_batch = next(iter(val_ds))
|
| 41 |
-
L_batch,AB_batch = L_batch.numpy(), AB_batch.numpy()
|
| 42 |
-
see_batch(L_batch,
|
| 43 |
-
AB_batch,
|
| 44 |
-
title="validation dataset")
|
| 45 |
-
|
| 46 |
-
L_batch,AB_batch = next(iter(test_ds))
|
| 47 |
-
L_batch,AB_batch = L_batch.numpy(), AB_batch.numpy()
|
| 48 |
-
see_batch(L_batch,
|
| 49 |
-
AB_batch,
|
| 50 |
-
title="testing dataset")
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/features/.gitkeep
DELETED
|
File without changes
|
src/features/__init__.py
DELETED
|
File without changes
|
src/features/build_features.py
DELETED
|
File without changes
|
src/models/.gitkeep
DELETED
|
File without changes
|
src/models/__init__.py
DELETED
|
File without changes
|
src/models/predict_model.py
DELETED
|
File without changes
|
src/models/train_model.py
DELETED
|
File without changes
|
src/scripts/create_sub_task.py
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os,shutil
|
| 2 |
+
import argparse
|
| 3 |
+
|
| 4 |
+
def create_file(file_path,file_content):
|
| 5 |
+
with open(file_path,"w") as f:
|
| 6 |
+
f.write(file_content)
|
| 7 |
+
|
| 8 |
+
def create_data(data_dir,dataset_name,sub_task_dir):
|
| 9 |
+
# call src/sub_task/scripts/create_dataset.py dataset_name
|
| 10 |
+
os.system(f"python {sub_task_dir}/scripts/create_dataset.py {dataset_name}")
|
| 11 |
+
|
| 12 |
+
register_datasets_file_path = os.path.join(data_dir,"register_datasets.py")
|
| 13 |
+
create_file(register_datasets_file_path,
|
| 14 |
+
f"""# register your datasets here
|
| 15 |
+
|
| 16 |
+
datasets = ["{dataset_name}"]
|
| 17 |
+
|
| 18 |
+
""")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def create_model(model_dir:str, model_name:str, sub_task_dir:str):
|
| 23 |
+
base_model_interface_path = os.path.join(model_dir,"base_model_interface.py")
|
| 24 |
+
|
| 25 |
+
create_file(base_model_interface_path,
|
| 26 |
+
"""import numpy as np
|
| 27 |
+
from abc import ABC, abstractmethod
|
| 28 |
+
|
| 29 |
+
# BaseModel Abstract class
|
| 30 |
+
# all the models within this sub_task must inherit this class
|
| 31 |
+
|
| 32 |
+
class BaseModel(ABC):
|
| 33 |
+
@abstractmethod
|
| 34 |
+
def train(self):
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
@abstractmethod
|
| 38 |
+
def predict(self,inputs):
|
| 39 |
+
pass
|
| 40 |
+
""")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# call src/sub_task/scripts/create_model.py model_name
|
| 44 |
+
os.system(f"python {sub_task_dir}/scripts/create_model.py {model_name}")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
register_models_path = os.path.join(model_dir,"register_models.py")
|
| 48 |
+
create_file(register_models_path,
|
| 49 |
+
f"""# register models of this sub_task here
|
| 50 |
+
models = ["{model_name}"]
|
| 51 |
+
""")
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
losses_path = os.path.join(model_dir,"losses.py")
|
| 56 |
+
create_file(losses_path,
|
| 57 |
+
"""# define loss functions here
|
| 58 |
+
""")
|
| 59 |
+
|
| 60 |
+
metrics_path = os.path.join(model_dir,"metrics.py")
|
| 61 |
+
create_file(metrics_path,
|
| 62 |
+
"""# define metrics here
|
| 63 |
+
""")
|
| 64 |
+
|
| 65 |
+
callbacks_path = os.path.join(model_dir,"callbacks.py")
|
| 66 |
+
create_file(callbacks_path,
|
| 67 |
+
"""# define callbacks here
|
| 68 |
+
""")
|
| 69 |
+
|
| 70 |
+
dataloaders_path = os.path.join(model_dir,"dataloaders.py")
|
| 71 |
+
create_file(dataloaders_path,
|
| 72 |
+
"""# define dataloaders here
|
| 73 |
+
""")
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def create_scripts(scripts_dir,sub_task):
|
| 77 |
+
create_dataset_path = os.path.join(scripts_dir,"create_dataset.py")
|
| 78 |
+
create_file(create_dataset_path,
|
| 79 |
+
f"""import os,shutil
|
| 80 |
+
import argparse
|
| 81 |
+
|
| 82 |
+
def create_file(file_path,file_content):
|
| 83 |
+
with open(file_path,"w") as f:
|
| 84 |
+
f.write(file_content)
|
| 85 |
+
|
| 86 |
+
def create_dataset(args):
|
| 87 |
+
dataset_name = args.name
|
| 88 |
+
force_flag = args.force
|
| 89 |
+
datasets_dir = os.path.join('src','{sub_task}','data','datasets')
|
| 90 |
+
|
| 91 |
+
os.makedirs(datasets_dir,exist_ok=True)
|
| 92 |
+
dataset_path = os.path.join(datasets_dir,dataset_name+".py")
|
| 93 |
+
|
| 94 |
+
# deleted old dataset if force flag exists and dataset already exists
|
| 95 |
+
if os.path.exists(dataset_path):
|
| 96 |
+
if force_flag:
|
| 97 |
+
print("Replacing existing dataset:",dataset_name)
|
| 98 |
+
shutil.remove(dataset_path)
|
| 99 |
+
else:
|
| 100 |
+
print(f"{{dataset_name}} already exists, use --force flag if you want to reset it to default")
|
| 101 |
+
exit()
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
create_file(dataset_path,
|
| 105 |
+
\"\"\"# write dataset downloading preparation code in this file
|
| 106 |
+
# Note: download_prepare() this is specially choosen name so don't change this function's name
|
| 107 |
+
# you can add, remove and change any other function from this file
|
| 108 |
+
|
| 109 |
+
def download_prepare():
|
| 110 |
+
\\"\\"\\" function used to download dataset and apply
|
| 111 |
+
all type of data preprocessing required to prepare the dataset
|
| 112 |
+
\\"\\"\\"
|
| 113 |
+
download_dataset()
|
| 114 |
+
unzip_dataset()
|
| 115 |
+
clean_dataset()
|
| 116 |
+
move_dataset()
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def download_dataset():
|
| 120 |
+
\\"\\"\\"download dataset\\"\\"\\"
|
| 121 |
+
pass
|
| 122 |
+
|
| 123 |
+
def unzip_dataset():
|
| 124 |
+
\\"\\"\\"unzip dataset(if required)\\"\\"\\"
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
def clean_dataset():
|
| 128 |
+
\\"\\"\\"clean dataset(if required)\\"\\"\\"
|
| 129 |
+
pass
|
| 130 |
+
|
| 131 |
+
def move_dataset():
|
| 132 |
+
\\"\\"\\"move dataset to processed folder\\"\\"\\"
|
| 133 |
+
pass
|
| 134 |
+
\"\"\")
|
| 135 |
+
|
| 136 |
+
def main():
|
| 137 |
+
parser = argparse.ArgumentParser(description="Create blueprint dataset")
|
| 138 |
+
parser.add_argument('name',type=str,help="name of dataset (e.g., pascal-voc)")
|
| 139 |
+
parser.add_argument("--force",action="store_true",help="forcefully replace old existing dataset to default",default=False)
|
| 140 |
+
args = parser.parse_args()
|
| 141 |
+
create_dataset(args)
|
| 142 |
+
|
| 143 |
+
if __name__=="__main__":
|
| 144 |
+
main()
|
| 145 |
+
|
| 146 |
+
""")
|
| 147 |
+
|
| 148 |
+
create_model_path = os.path.join(scripts_dir,"create_model.py")
|
| 149 |
+
create_file(create_model_path,
|
| 150 |
+
f"""import os,shutil
|
| 151 |
+
import argparse
|
| 152 |
+
|
| 153 |
+
def create_file(file_path,file_content):
|
| 154 |
+
with open(file_path,"w") as f:
|
| 155 |
+
f.write(file_content)
|
| 156 |
+
|
| 157 |
+
def create_model(args):
|
| 158 |
+
model_name = args.name
|
| 159 |
+
force_flag = args.force
|
| 160 |
+
models_dir = os.path.join('src','{sub_task}','model',"models")
|
| 161 |
+
os.makedirs(models_dir,exist_ok=True)
|
| 162 |
+
model_path = os.path.join(models_dir,model_name+".py")
|
| 163 |
+
|
| 164 |
+
# deleted old model if force flag exists and model already exists
|
| 165 |
+
if os.path.exists(model_path):
|
| 166 |
+
if force_flag:
|
| 167 |
+
print("Replacing existing model:",model_name)
|
| 168 |
+
shutil.remove(model_path)
|
| 169 |
+
else:
|
| 170 |
+
print(f"{{model_name}} already exists, use --force flag if you want to reset it to default")
|
| 171 |
+
exit()
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
model_name_camel_case = "".join([part.capitalize() for part in model_name.split("_")])
|
| 175 |
+
create_file(model_path,
|
| 176 |
+
f\"\"\"from src.{sub_task}.model.base_model_interface import BaseModel
|
| 177 |
+
|
| 178 |
+
class Model(BaseModel):
|
| 179 |
+
def train(self):
|
| 180 |
+
pass
|
| 181 |
+
|
| 182 |
+
def predict(self,inputs):
|
| 183 |
+
pass
|
| 184 |
+
\"\"\")
|
| 185 |
+
|
| 186 |
+
def main():
|
| 187 |
+
parser = argparse.ArgumentParser(description="Create blueprint model")
|
| 188 |
+
parser.add_argument('name',type=str,help="name of model (e.g., model_v2)")
|
| 189 |
+
parser.add_argument("--force",action="store_true",help="forcefully replace old existing model to default",default=False)
|
| 190 |
+
args = parser.parse_args()
|
| 191 |
+
create_model(args)
|
| 192 |
+
|
| 193 |
+
if __name__=="__main__":
|
| 194 |
+
main()
|
| 195 |
+
|
| 196 |
+
""")
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def create_sub_task(args):
|
| 201 |
+
"""Used to create sub_task within our main task"""
|
| 202 |
+
sub_task = args.sub_task
|
| 203 |
+
force_flag = args.force
|
| 204 |
+
dataset_name = "dataset1"
|
| 205 |
+
model_name = "model1"
|
| 206 |
+
|
| 207 |
+
sub_task_dir = os.path.join('src',sub_task)
|
| 208 |
+
data_dir = os.path.join(sub_task_dir,'data')
|
| 209 |
+
model_dir = os.path.join(sub_task_dir,'model')
|
| 210 |
+
scripts_dir = os.path.join(sub_task_dir,"scripts")
|
| 211 |
+
# print(scripts_dir)
|
| 212 |
+
# deleted old sub_task if force flag exists and sub_task already exists
|
| 213 |
+
if os.path.exists(sub_task_dir):
|
| 214 |
+
if force_flag:
|
| 215 |
+
print("Replacing existing sub_task:",sub_task)
|
| 216 |
+
shutil.rmtree(sub_task_dir)
|
| 217 |
+
else:
|
| 218 |
+
print(f"{sub_task} already exists, use --force flag if you want to reset it to default")
|
| 219 |
+
exit()
|
| 220 |
+
|
| 221 |
+
# create empty folders
|
| 222 |
+
os.makedirs(sub_task_dir,exist_ok=True)
|
| 223 |
+
os.makedirs(data_dir,exist_ok=True)
|
| 224 |
+
os.makedirs(model_dir,exist_ok=True)
|
| 225 |
+
os.makedirs(scripts_dir,exist_ok=True)
|
| 226 |
+
|
| 227 |
+
# make config validator file
|
| 228 |
+
validate_config_file_path = os.path.join(sub_task_dir,"validate_config.py")
|
| 229 |
+
create_file(validate_config_file_path,
|
| 230 |
+
'''# from cerberus import Validator
|
| 231 |
+
|
| 232 |
+
# write config file schema here
|
| 233 |
+
# based on cerberus Validator
|
| 234 |
+
|
| 235 |
+
schema = {
|
| 236 |
+
"seed": {
|
| 237 |
+
"type": "integer",
|
| 238 |
+
},
|
| 239 |
+
"image_size": {"type": "integer", "required": True},
|
| 240 |
+
"train_size": {"type": "float", "required": True},
|
| 241 |
+
"shuffle": {"type": "boolean", "required": True},
|
| 242 |
+
"batch_size": {
|
| 243 |
+
"type": "integer",
|
| 244 |
+
"required": True,
|
| 245 |
+
},
|
| 246 |
+
"epochs": {
|
| 247 |
+
"type": "integer",
|
| 248 |
+
"required": True,
|
| 249 |
+
},
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
''')
|
| 253 |
+
|
| 254 |
+
# make scripts files
|
| 255 |
+
create_scripts(scripts_dir,sub_task)
|
| 256 |
+
|
| 257 |
+
# make data files
|
| 258 |
+
create_data(data_dir,dataset_name,sub_task_dir)
|
| 259 |
+
|
| 260 |
+
# make model files
|
| 261 |
+
create_model(model_dir,model_name,sub_task_dir)
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def main():
|
| 265 |
+
parser = argparse.ArgumentParser(description="Create blueprint sub_task")
|
| 266 |
+
parser.add_argument('sub_task',type=str,help="sub_task of project (e.g., simple_regression_colorization)")
|
| 267 |
+
parser.add_argument("--force",action="store_true",help="forcefully replace old existing sub_task to default",default=False)
|
| 268 |
+
args = parser.parse_args()
|
| 269 |
+
|
| 270 |
+
create_sub_task(args)
|
| 271 |
+
|
| 272 |
+
if __name__=="__main__":
|
| 273 |
+
main()
|
| 274 |
+
|
src/scripts/prepare_dataset.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from src.utils.config_loader import Config
|
| 3 |
+
from src.utils import config_loader
|
| 4 |
+
from src.utils.script_utils import validate_config
|
| 5 |
+
import importlib
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def prepare_dataset(args):
|
| 9 |
+
config_file_path = args.config_file
|
| 10 |
+
config = Config(config_file_path)
|
| 11 |
+
|
| 12 |
+
# validate config
|
| 13 |
+
validate_config(config)
|
| 14 |
+
|
| 15 |
+
# set config globally
|
| 16 |
+
config_loader.config = config
|
| 17 |
+
|
| 18 |
+
# now prepare the dataset
|
| 19 |
+
download_prepare = importlib.import_module(f"src.{config.task}.data.datasets.{config.dataset}").download_prepare
|
| 20 |
+
print("Preparing dataset")
|
| 21 |
+
download_prepare()
|
| 22 |
+
print("Prepared dataset")
|
| 23 |
+
|
| 24 |
+
def main():
|
| 25 |
+
parser = argparse.ArgumentParser(description="Prepare dataset based on config yaml file")
|
| 26 |
+
parser.add_argument("config_file",type=str)
|
| 27 |
+
args = parser.parse_args()
|
| 28 |
+
prepare_dataset(args)
|
| 29 |
+
|
| 30 |
+
if __name__=="__main__":
|
| 31 |
+
main()
|
src/scripts/visualize_dataset.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from src.utils.config_loader import Config
|
| 3 |
+
from src.utils import config_loader
|
| 4 |
+
from src.utils.script_utils import validate_config
|
| 5 |
+
import importlib
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def visualize_dataset(args):
|
| 9 |
+
config_file_path = args.config_file
|
| 10 |
+
config = Config(config_file_path)
|
| 11 |
+
|
| 12 |
+
# validate config
|
| 13 |
+
validate_config(config)
|
| 14 |
+
|
| 15 |
+
# set config globally
|
| 16 |
+
config_loader.config = config
|
| 17 |
+
|
| 18 |
+
# now visualize the dataset
|
| 19 |
+
visualize_fn = importlib.import_module(f"src.{config.task}.data.visualize_dataset").visualize
|
| 20 |
+
visualize_fn()
|
| 21 |
+
|
| 22 |
+
def main():
|
| 23 |
+
parser = argparse.ArgumentParser(description="Prepare dataset based on config yaml file")
|
| 24 |
+
parser.add_argument("config_file",type=str)
|
| 25 |
+
args = parser.parse_args()
|
| 26 |
+
visualize_dataset(args)
|
| 27 |
+
|
| 28 |
+
if __name__=="__main__":
|
| 29 |
+
main()
|
src/simple_regression_colorization/data/datasets/forests.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.utils.data_utils import download_personal_hf_dataset,unzip_file,is_bw,print_title
|
| 2 |
+
from zipfile import ZipFile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from src.utils.config_loader import constants
|
| 5 |
+
from glob import glob
|
| 6 |
+
import shutil,os
|
| 7 |
+
from tqdm import tqdm
|
| 8 |
+
import cv2
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# write dataset downloading preparation code in this file
|
| 13 |
+
# Note: download_prepare() this is specially choosen name so don't change this function's name
|
| 14 |
+
# you can add, remove and change any other function from this file
|
| 15 |
+
|
| 16 |
+
def download_prepare():
|
| 17 |
+
""" function used to download dataset and apply
|
| 18 |
+
all type of data preprocessing required to prepare the dataset
|
| 19 |
+
"""
|
| 20 |
+
download_dataset()
|
| 21 |
+
unzip_dataset()
|
| 22 |
+
clean_dataset()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def download_dataset():
|
| 26 |
+
"""Used to download dataset from hugging face"""
|
| 27 |
+
print_title(f"Downloading forests dataset from hugging face")
|
| 28 |
+
# download_hf_dataset("")
|
| 29 |
+
download_personal_hf_dataset("forests")
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def unzip_dataset():
|
| 34 |
+
print_title(f"Unzipping dataset")
|
| 35 |
+
|
| 36 |
+
unzip_file(constants.RAW_DATASET_DIR/Path("forests/trainval.zip"),
|
| 37 |
+
constants.INTERIM_DATASET_DIR/Path("trainval/"))
|
| 38 |
+
|
| 39 |
+
unzip_file(constants.RAW_DATASET_DIR/Path("forests/test.zip"),
|
| 40 |
+
constants.INTERIM_DATASET_DIR/Path("test/"))
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def clean_dataset():
|
| 45 |
+
print_title("CLEANING DATASET")
|
| 46 |
+
trainval_dir = constants.INTERIM_DATASET_DIR / Path("trainval/")
|
| 47 |
+
test_dir = constants.INTERIM_DATASET_DIR / Path("test/")
|
| 48 |
+
|
| 49 |
+
trainval_paths = glob(str(trainval_dir/Path("*")))
|
| 50 |
+
test_paths = glob(str(test_dir/Path("*")))
|
| 51 |
+
|
| 52 |
+
print("train,test: ",len(trainval_paths),",",len(test_paths),sep="")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def clean(image_paths,destination_dir):
|
| 56 |
+
if os.path.exists(destination_dir): shutil.rmtree(destination_dir)
|
| 57 |
+
os.makedirs(destination_dir)
|
| 58 |
+
for i in tqdm(range(len(image_paths))):
|
| 59 |
+
img = cv2.imread(image_paths[i])
|
| 60 |
+
img = cv2.resize(img,[128,128])
|
| 61 |
+
if not is_bw(img):
|
| 62 |
+
shutil.copy(trainval_paths[i],
|
| 63 |
+
destination_dir)
|
| 64 |
+
print("saved to:",destination_dir)
|
| 65 |
+
|
| 66 |
+
destination_dir = constants.PROCESSED_DATASET_DIR/Path("trainval/")
|
| 67 |
+
clean(trainval_paths,destination_dir)
|
| 68 |
+
|
| 69 |
+
destination_dir = constants.PROCESSED_DATASET_DIR/Path("test/")
|
| 70 |
+
clean(test_paths,destination_dir)
|
| 71 |
+
|
| 72 |
+
trainval_dir = constants.PROCESSED_DATASET_DIR / Path("trainval/")
|
| 73 |
+
test_dir = constants.PROCESSED_DATASET_DIR / Path("test/")
|
| 74 |
+
|
| 75 |
+
trainval_paths = glob(str(trainval_dir/Path("*")))
|
| 76 |
+
test_paths = glob(str(test_dir/Path("*")))
|
| 77 |
+
|
| 78 |
+
print("after cleaning train,test: ",len(trainval_paths),",",len(test_paths),sep="")
|
| 79 |
+
|
src/simple_regression_colorization/data/register_datasets.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# register your datasets here
|
| 2 |
+
|
| 3 |
+
datasets = ["forests"]
|
| 4 |
+
|
src/simple_regression_colorization/data/visualize_dataset.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.utils.data_utils import show_images_from_paths
|
| 2 |
+
from src.utils.config_loader import constants,config
|
| 3 |
+
from glob import glob
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# the data is at constants.PROCESSED_DATASET_DIR/trainval
|
| 7 |
+
# constants.PROCESSED_DATASET_DIR/test
|
| 8 |
+
|
| 9 |
+
def visualize():
|
| 10 |
+
n = 16
|
| 11 |
+
image_paths = glob(f"{constants.PROCESSED_DATASET_DIR}/trainval/*")
|
| 12 |
+
choosen_paths = np.random.choice(image_paths,n)
|
| 13 |
+
show_images_from_paths(choosen_paths,
|
| 14 |
+
title="sample of train_val dataset",
|
| 15 |
+
image_size=config.image_size)
|
| 16 |
+
|
| 17 |
+
image_paths = glob(f"{constants.PROCESSED_DATASET_DIR}/test/*")
|
| 18 |
+
choosen_paths = np.random.choice(image_paths,n)
|
| 19 |
+
show_images_from_paths(choosen_paths,
|
| 20 |
+
title="sample of test dataset",
|
| 21 |
+
image_size=config.image_size)
|
src/simple_regression_colorization/model/base_model_interface.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from abc import ABC, abstractmethod
|
| 3 |
+
|
| 4 |
+
# BaseModel Abstract class
|
| 5 |
+
# all the models within this sub_task must inherit this class
|
| 6 |
+
|
| 7 |
+
class BaseModel(ABC):
|
| 8 |
+
@abstractmethod
|
| 9 |
+
def train(self):
|
| 10 |
+
pass
|
| 11 |
+
|
| 12 |
+
@abstractmethod
|
| 13 |
+
def predict(self,inputs):
|
| 14 |
+
pass
|
src/simple_regression_colorization/model/callbacks.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# define callbacks here
|
src/{data/load_dataset.py → simple_regression_colorization/model/dataloaders.py}
RENAMED
|
@@ -1,15 +1,14 @@
|
|
| 1 |
-
import os,sys;sys.path.append(os.getcwd())
|
| 2 |
import tensorflow as tf
|
| 3 |
-
from src import
|
| 4 |
-
from src.utils import
|
| 5 |
from pathlib import Path
|
| 6 |
from glob import glob
|
| 7 |
import sklearn.model_selection
|
| 8 |
from skimage.color import rgb2lab, lab2rgb
|
| 9 |
|
| 10 |
def get_datasets():
|
| 11 |
-
trainval_dir =
|
| 12 |
-
test_dir =
|
| 13 |
|
| 14 |
trainval_paths = glob(str(trainval_dir/Path("*")))
|
| 15 |
test_paths = glob(str(test_dir/Path("*")))
|
|
@@ -22,26 +21,15 @@ def get_datasets():
|
|
| 22 |
train_size=0.8,
|
| 23 |
random_state=324)
|
| 24 |
|
| 25 |
-
print("train|val
|
| 26 |
-
|
| 27 |
-
train_ds =
|
| 28 |
-
val_ds =
|
| 29 |
-
test_ds =
|
| 30 |
|
| 31 |
return train_ds,val_ds,test_ds
|
| 32 |
|
| 33 |
|
| 34 |
-
# def test_dataset():
|
| 35 |
-
# train_ds = get_ds(train_paths,shuffle=False)
|
| 36 |
-
# L_batch,AB_batch = next(iter(train_ds))
|
| 37 |
-
# L_batch = L_batch.numpy()
|
| 38 |
-
# AB_batch = AB_batch.numpy()
|
| 39 |
-
# print("L:",L_batch.min(),L_batch.max())
|
| 40 |
-
# print("A:",AB_batch[:,:,:,0].min(),AB_batch[:,:,:,0].max())
|
| 41 |
-
# print("B:",AB_batch[:,:,:,1].min(),AB_batch[:,:,:,1].max())
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
def tf_RGB_TO_LAB(image):
|
| 46 |
def f(image):
|
| 47 |
image = rgb2lab(image)
|
|
@@ -63,7 +51,7 @@ def load_img(img_path):
|
|
| 63 |
L,AB = scale_L(L),scale_AB(AB)
|
| 64 |
return L,AB
|
| 65 |
|
| 66 |
-
def
|
| 67 |
ds = tf.data.Dataset.from_tensor_slices(image_paths)
|
| 68 |
if shuffle: ds = ds.shuffle(len(image_paths))
|
| 69 |
ds = ds.map(load_img,num_parallel_calls=tf.data.AUTOTUNE)
|
|
|
|
|
|
|
| 1 |
import tensorflow as tf
|
| 2 |
+
from src.utils.data_utils import scale_L,scale_AB,rescale_AB,rescale_L
|
| 3 |
+
from src.utils.config_loader import config
|
| 4 |
from pathlib import Path
|
| 5 |
from glob import glob
|
| 6 |
import sklearn.model_selection
|
| 7 |
from skimage.color import rgb2lab, lab2rgb
|
| 8 |
|
| 9 |
def get_datasets():
|
| 10 |
+
trainval_dir = config.PROCESSED_DATASET_DIR / Path("trainval/")
|
| 11 |
+
test_dir = config.PROCESSED_DATASET_DIR / Path("test/")
|
| 12 |
|
| 13 |
trainval_paths = glob(str(trainval_dir/Path("*")))
|
| 14 |
test_paths = glob(str(test_dir/Path("*")))
|
|
|
|
| 21 |
train_size=0.8,
|
| 22 |
random_state=324)
|
| 23 |
|
| 24 |
+
print("train|val|test:",len(train_paths),"|",len(val_paths),"|",len(test_paths))
|
| 25 |
+
|
| 26 |
+
train_ds = get_tf_ds(train_paths,bs=config.batch_size,shuffle=config.shuffle)
|
| 27 |
+
val_ds = get_tf_ds(val_paths,bs=config.batch_size,shuffle=False,is_val=True)
|
| 28 |
+
test_ds = get_tf_ds(test_paths,bs=config.batch_size,shuffle=False,is_val=True)
|
| 29 |
|
| 30 |
return train_ds,val_ds,test_ds
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def tf_RGB_TO_LAB(image):
|
| 34 |
def f(image):
|
| 35 |
image = rgb2lab(image)
|
|
|
|
| 51 |
L,AB = scale_L(L),scale_AB(AB)
|
| 52 |
return L,AB
|
| 53 |
|
| 54 |
+
def get_tf_ds(image_paths,bs=8,shuffle=False,is_val=False):
|
| 55 |
ds = tf.data.Dataset.from_tensor_slices(image_paths)
|
| 56 |
if shuffle: ds = ds.shuffle(len(image_paths))
|
| 57 |
ds = ds.map(load_img,num_parallel_calls=tf.data.AUTOTUNE)
|
src/simple_regression_colorization/model/losses.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# define loss functions here
|
src/simple_regression_colorization/model/metrics.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# define metrics here
|
src/simple_regression_colorization/model/models/model_v1.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.simple_regression_colorization.model.base_model_interface import BaseModel
|
| 2 |
+
from src.simple_regression_colorization.model.dataloaders import get_datasets
|
| 3 |
+
|
| 4 |
+
class Model(BaseModel):
|
| 5 |
+
|
| 6 |
+
def __init__(self):
|
| 7 |
+
# make model architecture
|
| 8 |
+
# load weights (optional)
|
| 9 |
+
# create dataset loaders
|
| 10 |
+
# train
|
| 11 |
+
# predict
|
| 12 |
+
self.init_model()
|
| 13 |
+
self.load_weights()
|
| 14 |
+
self.prepare_data()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def init_model(self):
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
def load_weights(self,path=None):
|
| 21 |
+
pass
|
| 22 |
+
|
| 23 |
+
def prepare_data(self):
|
| 24 |
+
self.train_ds,self.val_ds,self.test_ds = get_datasets()
|
| 25 |
+
|
| 26 |
+
def train(self):
|
| 27 |
+
pass
|
| 28 |
+
|
| 29 |
+
def predict(self,inputs):
|
| 30 |
+
pass
|
src/simple_regression_colorization/model/register_models.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# register models of this sub_task here
|
| 2 |
+
models = ["model_v1"]
|
src/simple_regression_colorization/scripts/create_dataset.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os,shutil
|
| 2 |
+
import argparse
|
| 3 |
+
|
| 4 |
+
def create_file(file_path,file_content):
|
| 5 |
+
with open(file_path,"w") as f:
|
| 6 |
+
f.write(file_content)
|
| 7 |
+
|
| 8 |
+
def create_dataset(args):
|
| 9 |
+
dataset_name = args.name
|
| 10 |
+
force_flag = args.force
|
| 11 |
+
datasets_dir = os.path.join('src','simple_regression_colorization','data','datasets')
|
| 12 |
+
|
| 13 |
+
os.makedirs(datasets_dir,exist_ok=True)
|
| 14 |
+
dataset_path = os.path.join(datasets_dir,dataset_name+".py")
|
| 15 |
+
|
| 16 |
+
# deleted old dataset if force flag exists and dataset already exists
|
| 17 |
+
if os.path.exists(dataset_path):
|
| 18 |
+
if force_flag:
|
| 19 |
+
print("Replacing existing dataset:",dataset_name)
|
| 20 |
+
shutil.remove(dataset_path)
|
| 21 |
+
else:
|
| 22 |
+
print(f"{dataset_name} already exists, use --force flag if you want to reset it to default")
|
| 23 |
+
exit()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
create_file(dataset_path,
|
| 27 |
+
"""# write dataset downloading preparation code in this file
|
| 28 |
+
# Note: download_prepare() this is specially choosen name so don't change this function's name
|
| 29 |
+
# you can add, remove and change any other function from this file
|
| 30 |
+
|
| 31 |
+
def download_prepare():
|
| 32 |
+
\"\"\" function used to download dataset and apply
|
| 33 |
+
all type of data preprocessing required to prepare the dataset
|
| 34 |
+
\"\"\"
|
| 35 |
+
download_dataset()
|
| 36 |
+
unzip_dataset()
|
| 37 |
+
clean_dataset()
|
| 38 |
+
move_dataset()
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def download_dataset():
|
| 42 |
+
\"\"\"download dataset\"\"\"
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
+
def unzip_dataset():
|
| 46 |
+
\"\"\"unzip dataset(if required)\"\"\"
|
| 47 |
+
pass
|
| 48 |
+
|
| 49 |
+
def clean_dataset():
|
| 50 |
+
\"\"\"clean dataset(if required)\"\"\"
|
| 51 |
+
pass
|
| 52 |
+
|
| 53 |
+
def move_dataset():
|
| 54 |
+
\"\"\"move dataset to processed folder\"\"\"
|
| 55 |
+
pass
|
| 56 |
+
""")
|
| 57 |
+
|
| 58 |
+
def main():
|
| 59 |
+
parser = argparse.ArgumentParser(description="Create blueprint dataset")
|
| 60 |
+
parser.add_argument('name',type=str,help="name of dataset (e.g., pascal-voc)")
|
| 61 |
+
parser.add_argument("--force",action="store_true",help="forcefully replace old existing dataset to default",default=False)
|
| 62 |
+
args = parser.parse_args()
|
| 63 |
+
create_dataset(args)
|
| 64 |
+
|
| 65 |
+
if __name__=="__main__":
|
| 66 |
+
main()
|
| 67 |
+
|
src/simple_regression_colorization/scripts/create_model.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os,shutil
|
| 2 |
+
import argparse
|
| 3 |
+
|
| 4 |
+
def create_file(file_path,file_content):
|
| 5 |
+
with open(file_path,"w") as f:
|
| 6 |
+
f.write(file_content)
|
| 7 |
+
|
| 8 |
+
def create_model(args):
|
| 9 |
+
model_name = args.name
|
| 10 |
+
force_flag = args.force
|
| 11 |
+
models_dir = os.path.join('src','simple_regression_colorization','model',"models")
|
| 12 |
+
os.makedirs(models_dir,exist_ok=True)
|
| 13 |
+
model_path = os.path.join(models_dir,model_name+".py")
|
| 14 |
+
|
| 15 |
+
# deleted old model if force flag exists and model already exists
|
| 16 |
+
if os.path.exists(model_path):
|
| 17 |
+
if force_flag:
|
| 18 |
+
print("Replacing existing model:",model_name)
|
| 19 |
+
shutil.remove(model_path)
|
| 20 |
+
else:
|
| 21 |
+
print(f"{model_name} already exists, use --force flag if you want to reset it to default")
|
| 22 |
+
exit()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
model_name_camel_case = "".join([part.capitalize() for part in model_name.split("_")])
|
| 26 |
+
create_file(model_path,
|
| 27 |
+
f"""from src.simple_regression_colorization.model.base_model_interface import BaseModel
|
| 28 |
+
|
| 29 |
+
class Model(BaseModel):
|
| 30 |
+
def train(self):
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
def predict(self,inputs):
|
| 34 |
+
pass
|
| 35 |
+
""")
|
| 36 |
+
|
| 37 |
+
def main():
|
| 38 |
+
parser = argparse.ArgumentParser(description="Create blueprint model")
|
| 39 |
+
parser.add_argument('name',type=str,help="name of model (e.g., model_v2)")
|
| 40 |
+
parser.add_argument("--force",action="store_true",help="forcefully replace old existing model to default",default=False)
|
| 41 |
+
args = parser.parse_args()
|
| 42 |
+
create_model(args)
|
| 43 |
+
|
| 44 |
+
if __name__=="__main__":
|
| 45 |
+
main()
|
| 46 |
+
|
src/simple_regression_colorization/validate_config.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# from cerberus import Validator
|
| 2 |
+
|
| 3 |
+
# write config file schema here
|
| 4 |
+
# based on cerberus Validator
|
| 5 |
+
|
| 6 |
+
schema = {
|
| 7 |
+
"seed": {
|
| 8 |
+
"type": "integer",
|
| 9 |
+
},
|
| 10 |
+
"image_size": {"type": "integer", "required": True},
|
| 11 |
+
"train_size": {"type": "float", "required": True},
|
| 12 |
+
"shuffle": {"type": "boolean", "required": True},
|
| 13 |
+
"batch_size": {
|
| 14 |
+
"type": "integer",
|
| 15 |
+
"required": True,
|
| 16 |
+
},
|
| 17 |
+
"epochs": {
|
| 18 |
+
"type": "integer",
|
| 19 |
+
"required": True,
|
| 20 |
+
},
|
| 21 |
+
}
|
| 22 |
+
|
src/utils.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
import yaml
|
| 2 |
-
import numpy as np
|
| 3 |
-
|
| 4 |
-
class Config:
|
| 5 |
-
def __init__(self,path="config.yaml"):
|
| 6 |
-
with open(path,'r') as f:
|
| 7 |
-
self.config = yaml.safe_load(f)
|
| 8 |
-
|
| 9 |
-
def __str__(self):
|
| 10 |
-
return str(self.config)
|
| 11 |
-
|
| 12 |
-
def __getattr__(self, name: str):
|
| 13 |
-
return self.config.get(name)
|
| 14 |
-
|
| 15 |
-
# def __setattr__(self, name: str, value: any):
|
| 16 |
-
# self.config[name]=value
|
| 17 |
-
|
| 18 |
-
def is_bw(img):
|
| 19 |
-
rg,gb,rb = img[:,:,0]-img[:,:,1] , img[:,:,1]-img[:,:,2] , img[:,:,0]-img[:,:,2]
|
| 20 |
-
rg,gb,rb = np.abs(rg).sum(),np.abs(gb).sum(),np.abs(rb).sum()
|
| 21 |
-
avg = np.mean([rg,gb,rb])
|
| 22 |
-
# print(rg,gb,rb)
|
| 23 |
-
|
| 24 |
-
return avg<10
|
| 25 |
-
|
| 26 |
-
def print_title(msg:str,n=30):
|
| 27 |
-
print("="*n,msg.upper(),"="*n,sep="")
|
| 28 |
-
|
| 29 |
-
def scale_L(L):
|
| 30 |
-
return L/100
|
| 31 |
-
def rescale_L(L):
|
| 32 |
-
return L*100
|
| 33 |
-
|
| 34 |
-
def scale_AB(AB):
|
| 35 |
-
return AB/128
|
| 36 |
-
|
| 37 |
-
def rescale_AB(AB):
|
| 38 |
-
return AB*128
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/utils/config_loader.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import yaml
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
class Config:
|
| 5 |
+
def __init__(self,config_file_path:str):
|
| 6 |
+
"""loads config from config_file_path"""
|
| 7 |
+
with open(config_file_path,"r") as f:
|
| 8 |
+
self.config_dict = yaml.safe_load(f)
|
| 9 |
+
|
| 10 |
+
def __str__(self):
|
| 11 |
+
return str(self.config_dict)
|
| 12 |
+
|
| 13 |
+
def __getattr__(self,name):
|
| 14 |
+
return self.config_dict.get(name)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# exports constants
|
| 18 |
+
constants = Config("constants.yaml")
|
| 19 |
+
constants.config_dict['RAW_DATASET_DIR'] = Path(constants.config_dict['RAW_DATASET_DIR'])
|
| 20 |
+
constants.config_dict['INTERIM_DATASET_DIR'] = Path(constants.config_dict['INTERIM_DATASET_DIR'])
|
| 21 |
+
constants.config_dict['PROCESSED_DATASET_DIR'] = Path(constants.config_dict['PROCESSED_DATASET_DIR'])
|
| 22 |
+
|
| 23 |
+
config = None
|
src/utils/data_utils.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from src.utils.config_loader import constants
|
| 2 |
+
from huggingface_hub import snapshot_download
|
| 3 |
+
from zipfile import ZipFile
|
| 4 |
+
import numpy as np
|
| 5 |
+
import shutil
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
import cv2
|
| 8 |
+
import math
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def download_hf_dataset(repo_id,allow_patterns=None):
|
| 12 |
+
"""Used to download dataset from any public hugging face dataset"""
|
| 13 |
+
snapshot_download(repo_id=repo_id,
|
| 14 |
+
repo_type="dataset",
|
| 15 |
+
local_dir=constants.RAW_DATASET_DIR,
|
| 16 |
+
allow_patterns=allow_patterns)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def download_personal_hf_dataset(name):
|
| 20 |
+
"""Used to download dataset from a specific hugging face dataset"""
|
| 21 |
+
download_hf_dataset(repo_id="Anuj-Panthri/Image-Colorization-Datasets",
|
| 22 |
+
allow_patterns=f"{name}/*")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def unzip_file(file_path,destination_dir):
|
| 26 |
+
"""unzips file to destination_dir"""
|
| 27 |
+
shutil.rmtree(destination_dir)
|
| 28 |
+
with ZipFile(file_path,"r") as zip:
|
| 29 |
+
zip.extractall(destination_dir)
|
| 30 |
+
|
| 31 |
+
def is_bw(img:np.ndarray):
|
| 32 |
+
"""checks if RGB image is black and white"""
|
| 33 |
+
rg,gb,rb = img[:,:,0]-img[:,:,1] , img[:,:,1]-img[:,:,2] , img[:,:,0]-img[:,:,2]
|
| 34 |
+
rg,gb,rb = np.abs(rg).sum(),np.abs(gb).sum(),np.abs(rb).sum()
|
| 35 |
+
avg = np.mean([rg,gb,rb])
|
| 36 |
+
|
| 37 |
+
return avg<10
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def print_title(msg:str,max_chars=105):
|
| 41 |
+
n = (max_chars-len(msg))//2
|
| 42 |
+
print("="*n,msg.upper(),"="*n,sep="")
|
| 43 |
+
|
| 44 |
+
def scale_L(L):
|
| 45 |
+
return L/100
|
| 46 |
+
|
| 47 |
+
def rescale_L(L):
|
| 48 |
+
return L*100
|
| 49 |
+
|
| 50 |
+
def scale_AB(AB):
|
| 51 |
+
return AB/128
|
| 52 |
+
|
| 53 |
+
def rescale_AB(AB):
|
| 54 |
+
return AB*128
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def show_images_from_paths(image_paths:list[str],image_size=64,cols=4,row_size=5,col_size=5,show_BW=False,title=None):
|
| 59 |
+
n = len(image_paths)
|
| 60 |
+
rows = math.ceil(n/cols)
|
| 61 |
+
fig = plt.figure(figsize=(col_size*cols,row_size*rows))
|
| 62 |
+
if title:
|
| 63 |
+
plt.title(title)
|
| 64 |
+
plt.axis("off")
|
| 65 |
+
|
| 66 |
+
for i in range(n):
|
| 67 |
+
fig.add_subplot(rows,cols,i+1)
|
| 68 |
+
|
| 69 |
+
img = cv2.imread(image_paths[i])[:,:,::-1]
|
| 70 |
+
img = cv2.resize(img,[image_size,image_size])
|
| 71 |
+
|
| 72 |
+
if show_BW:
|
| 73 |
+
BW = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
|
| 74 |
+
BW = np.tile(BW,(1,1,3))
|
| 75 |
+
img = np.concatenate([BW,img],axis=1)
|
| 76 |
+
plt.imshow(img.astype("uint8"))
|
| 77 |
+
plt.show()
|
src/utils/script_utils.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from cerberus import Validator
|
| 2 |
+
import importlib
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def validate_config(config):
|
| 6 |
+
basic_schema = {
|
| 7 |
+
"task": {
|
| 8 |
+
"type":"string",
|
| 9 |
+
"required":True
|
| 10 |
+
},
|
| 11 |
+
"dataset": {
|
| 12 |
+
"type":"string",
|
| 13 |
+
"required":True
|
| 14 |
+
},
|
| 15 |
+
"model": {
|
| 16 |
+
"type":"string",
|
| 17 |
+
"required":True
|
| 18 |
+
},
|
| 19 |
+
}
|
| 20 |
+
basic_v = Validator(basic_schema,allow_unknown=True)
|
| 21 |
+
|
| 22 |
+
if not basic_v.validate(config.config_dict):
|
| 23 |
+
raise Exception(f"Invalid config file:",basic_v.errors)
|
| 24 |
+
|
| 25 |
+
# check if such task exists
|
| 26 |
+
if not os.path.exists(os.path.join("src",config.task)):
|
| 27 |
+
raise Exception("Invalid config file:",f"no such task {config.task}")
|
| 28 |
+
|
| 29 |
+
# check if valid dataset
|
| 30 |
+
all_datasets = importlib.import_module(f"src.{config.task}.data.register_datasets").datasets
|
| 31 |
+
if config.dataset not in all_datasets:
|
| 32 |
+
raise Exception("Invalid config file:",f"no {config.dataset} dataset found in registered datasets: {all_datasets}")
|
| 33 |
+
|
| 34 |
+
# check if valid model
|
| 35 |
+
all_models = importlib.import_module(f"src.{config.task}.model.register_models").models
|
| 36 |
+
if config.model not in all_models:
|
| 37 |
+
raise Exception("Invalid config file:",f"no {config.model} model found in registered models: {all_models}")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# check the sub_task's validate_config schema
|
| 42 |
+
task_schema = importlib.import_module(f"src.{config.task}.validate_config").schema
|
| 43 |
+
sub_task_v = Validator(task_schema,allow_unknown=True)
|
| 44 |
+
|
| 45 |
+
if not sub_task_v.validate(config.config_dict):
|
| 46 |
+
raise Exception(f"Invalid config file:",sub_task_v.errors)
|
| 47 |
+
|
src/visualization/.gitkeep
DELETED
|
File without changes
|