-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
151 lines (114 loc) · 3.31 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# GenerativeModel-HMM implementation
#
#
SHELL=/bin/bash
PYTHON=python
SRC=src
BIN=bin
DATA_tmp=data
MODELS_tmp=models
ifndef totclasses
totclasses=61
endif
ifndef nepochs
nepochs=10
endif
ifndef nclasses
nclasses=2
endif
ifndef nfeats
nfeats=39
endif
ifndef j
j=2
endif
ifndef model
model=gaus
endif
ifndef exp_name
exp_name=default
endif
ROBUST=robust
EXP=exp/$(model)
EXP_DIR=$(EXP)/$(nfeats)feats/$(exp_name)
MODELS=models
DATA=data
LOG=log
init: MODELS=$(EXP_DIR)/models
init: LOG=$(EXP_DIR)/log
MODELS_INTERM=$(shell echo $(MODELS)/epoch{1..$(nepochs)})
TEST_INTERM=$(shell echo {1..$(nepochs)})
training_data=$(DATA)/train.$(nfeats).pkl
ifndef noise
testing_data=$(DATA)/test.$(nfeats).pkl
else
testing_data=$(DATA)/test.$(nfeats).$(noise).pkl
endif
mdl_dep=$(shell echo $(MODELS)/%_class{1..$(nclasses)}.mdlc)
acc_dep=$(shell echo $(MODELS)/%_class{1..$(nclasses)}.accc)
rbst_dep=$(shell echo $(ROBUST)/epoch$(tepoch)_class{1..$(nclasses)}.accc)
all: train
test:
echo $(mdl_dep)
echo $(acc_dep)
init:
mkdir -p $(MODELS) $(LOG)
ln -s $(realpath data) $(EXP_DIR)/data
ln -s $(realpath bin) $(EXP_DIR)/bin
ln -s $(realpath src) $(EXP_DIR)/src
cp default.json $(EXP_DIR)
sed -e 's/model=.*/model=$(model)/' -e 's/nfeats=.*/nfeats=${nfeats}/' -e 's/totclasses=.*/totclasses=$(totclasses)/' Makefile > $(EXP_DIR)/Makefile
prepare_data: $(training_data) $(testing_data)
$(PYTHON) $(BIN)/prepare_data.py "$(nclasses)/$(totclasses)" $^
train: prepare_data
echo $(DATA) $(MODELS) $(LOG)
echo $(MODELS_INTERM)
for i in $(MODELS_INTERM); do \
if [[ `echo $${i%.*}_class*.mdlc | wc -w` != $(nclasses) ]]; then rm -f $$i.{mdl,acc}; fi; \
$(MAKE) -j $(j) -s $$i.mdl; \
$(MAKE) -j $(j) -s $$i.acc; \
sleep 2;\
done
# echo "Done" > $^
$(MODELS)/%.mdl: $(mdl_dep)
$(PYTHON) $(BIN)/aggregate_models.py $@
$(MODELS)/%.acc: $(acc_dep)
$(PYTHON) $(BIN)/aggregate_accuracy.py $(training_data) $(testing_data) $^ > $@
cat $@ >> $(LOG)/class_all.log
$(MODELS)/%.mdlc:
$(eval logfile=$(LOG)/`basename $@ | sed -e 's/^.*\(class\)/\1/g' -e 's/.mdlc/.log'/g`)
echo `date` ":" $(PYTHON) $(BIN)/train_class_$(model).py $(training_data) $@ >> $(logfile)
$(PYTHON) $(BIN)/train_class_$(model).py $(training_data) $@ >> $(logfile)
$(MODELS)/%.accc: $(MODELS)/%.mdlc
$(PYTHON) $(BIN)/compute_accuracy_class.py $^ $(training_data) $(testing_data) >> $@
# testing part only
# test one checkpoint
test_one:
$(MAKE) -j $(j) -s $(ROBUST)/epoch$(tepoch).acc
# test multiple check points
test_all:
echo $(TEST_INTERM)
for i in $(TEST_INTERM); do \
$(MAKE) -j $(j) -s $(ROBUST)/epoch$$i.acc tepoch=$$i; \
sleep 2;\
done
$(ROBUST)/epoch%.acc: $(rbst_dep)
$(PYTHON) $(BIN)/aggregate_accuracy.py $(training_data) $(testing_data) $^ > $@
cat $@ >> $(LOG)/class_all.log
$(ROBUST)/%.accc:
@echo $(subst $(ROBUST),$(MODELS),$@)
# string replacement such compute_acccuracy_class can recognize
$(PYTHON) $(BIN)/compute_accuracy_class.py $(subst .accc,.mdlc,$(subst $(ROBUST),$(MODELS),$@)) $(training_data) $(testing_data) >> $@
watch:
tail -f $(LOG)/class*.log
clean:
# rm -f $(DATA)/train*_*.pkl
# rm -f $(DATA)/test*_*.pkl
# rm -f $(DATA)/class_map.json
rm -f $(MODELS)/epoch*.{mdl,acc}
rm -f $(MODELS)/epoch*_class*.{mdlc,accc}
rm -f $(LOG)/class*.log
clean-data:
rm -f $(DATA)/*_*.pkl $(DATA)/class_map.json
.SECONDARY:
.PRECIOUS: