-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
68 lines (54 loc) · 1.89 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
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
58
59
60
61
62
63
64
65
66
67
68
CONDA_ROOT = $(shell conda info --base)
CONDA_ENV_NAME = mnist-pytorch
PYTHON = $(CONDA_ROOT)/envs/$(CONDA_ENV_NAME)/bin/python3
SRC_DIR = src
DATA_DIR = data
TRAIN_DIR = $(DATA_DIR)/train
TEST_DIR = $(DATA_DIR)/test
SET_DIRS = $(TRAIN_DIR) $(TEST_DIR)
DOWNLOAD_URL_PREFIX = http://yann.lecun.com/exdb/mnist
IDX_IMAGES_SUFFIX = images-idx3-ubyte
IDX_LABELS_SUFFIX = labels-idx1-ubyte
TRAINING_DATA = $(TRAIN_DIR)/train-$(IDX_IMAGES_SUFFIX) \
$(TRAIN_DIR)/train-$(IDX_LABELS_SUFFIX)
MODEL_SAVE = model.tar
.PRECIOUS: $(MODEL_SAVE)
# All the directories that need to be created.
MK_DIRECTORIES = $(SET_DIRS)
.PHONY: all
all: $(MODEL_SAVE)
# Setup the conda environment with all the required packages.
.PHONY: environment
environment:
conda env create -f environment.yml -n $(CONDA_ENV_NAME)
# Download zipped data
.PRECIOUS: $(TRAIN_DIR)/%.gz $(TEST_DIR)/%.gz
$(TRAIN_DIR)/%.gz: | $(TRAIN_DIR)
wget $(DOWNLOAD_URL_PREFIX)/$(@F) -O $@
$(TEST_DIR)/%.gz: | $(TEST_DIR)
wget $(DOWNLOAD_URL_PREFIX)/$(@F) -O $@
# Unzip downloaded data
$(TRAIN_DIR)/%: $(TRAIN_DIR)/%.gz
gzip -cdk $< > $@
$(TEST_DIR)/%: $(TEST_DIR)/%.gz
gzip -cdk $< > $@
# There is surely a way to more concisely define these rules.
# Maybe something like this ? (SET=train or SET=t10k)
# ($(DATA_DIR)/$(SET)/$(SET)-%.gz: | $(DATA_DIR)/$(SET)
# wget $(DOWNLOAD_URL_PREFIX)/$(@F) -O $@
# "Dependencies" of source code files.
#$(SRC_DIR)/CNN.py: $(SRC_DIR)/pytorch_model.py
# @touch $@
#$(SRC_DIR)/train.py: $(SRC_DIR)/data.py $(SRC_DIR)/CNN.py
# @touch $@
# Train and save model.
MODEL_SCRIPT = $(SRC_DIR)/CNN.py
TRAINING_SCRIPT = $(SRC_DIR)/train.py
TRAINING_SCRIPT_DEPS = $(SRC_DIR)/pytorch_model.py $(MODEL_SCRIPT)
$(MODEL_SAVE): $(TRAINING_SCRIPT) $(TRAINING_SCRIPT_DEPS) \
$(TRAINING_DATA)
$(PYTHON) $(TRAINING_SCRIPT) $(TRAINING_DATA) $@
#$(MODEL_SAVE): $(SRC_DIR)/train.py $(TRAINING_DATA)
# $(PYTHON) $^ $@
$(MK_DIRECTORIES):
@mkdir -p $@