Skip to content

Commit 998f39b

Browse files
authored
Merge pull request #16 from Ahmkel/master
Fixed typos and spacing according to PEP 8
2 parents b37db1a + ac200a5 commit 998f39b

File tree

12 files changed

+46
-42
lines changed

12 files changed

+46
-42
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ In a nutshell here's how to use this template, so **for example** assume you wan
7373
pass
7474

7575
```
76-
- In main file you create the session and create instance of the following objects "Model", "Logger", "Data_Generator", "Trainer", and config
76+
- In main file, you create the session and instances of the following objects "Model", "Logger", "Data_Generator", "Trainer", and config
7777
```python
7878
sess = tf.Session()
7979
# create instance of the model you want
@@ -91,7 +91,7 @@ In a nutshell here's how to use this template, so **for example** assume you wan
9191
trainer.train()
9292

9393
```
94-
**You will a template file and a simple example in the model and trainer folder that shows you how to try your first model simply.**
94+
**You will find a template file and a simple example in the model and trainer folder that shows you how to try your first model simply.**
9595

9696

9797
# In Details
@@ -186,7 +186,7 @@ Here's where you combine all previous part.
186186

187187

188188
# Contributing
189-
Any kind of enhancement, or contribution is welcomed.
189+
Any kind of enhancement or contribution is welcomed.
190190

191191

192192
# Acknowledgments

base/base_model.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import tensorflow as tf
2-
import os
32

43

54
class BaseModel:
@@ -10,27 +9,27 @@ def __init__(self, config):
109
# init the epoch counter
1110
self.init_cur_epoch()
1211

13-
# save function thet save the checkpoint in the path defined in configfile
12+
# save function that saves the checkpoint in the path defined in the config file
1413
def save(self, sess):
1514
print("Saving model...")
1615
self.saver.save(sess, self.config.checkpoint_dir, self.global_step_tensor)
1716
print("Model saved")
1817

19-
# load lateset checkpoint from the experiment path defined in config_file
18+
# load latest checkpoint from the experiment path defined in the config file
2019
def load(self, sess):
2120
latest_checkpoint = tf.train.latest_checkpoint(self.config.checkpoint_dir)
2221
if latest_checkpoint:
2322
print("Loading model checkpoint {} ...\n".format(latest_checkpoint))
2423
self.saver.restore(sess, latest_checkpoint)
2524
print("Model loaded")
2625

27-
# just inialize a tensorflow variable to use it as epoch counter
26+
# just initialize a tensorflow variable to use it as epoch counter
2827
def init_cur_epoch(self):
2928
with tf.variable_scope('cur_epoch'):
3029
self.cur_epoch_tensor = tf.Variable(0, trainable=False, name='cur_epoch')
3130
self.increment_cur_epoch_tensor = tf.assign(self.cur_epoch_tensor, self.cur_epoch_tensor + 1)
3231

33-
# just inialize a tensorflow variable to use it as global step counter
32+
# just initialize a tensorflow variable to use it as global step counter
3433
def init_global_step(self):
3534
# DON'T forget to add the global step tensor to the tensorflow trainer
3635
with tf.variable_scope('global_step'):

base/base_train.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import tensorflow as tf
2-
import os
3-
from tqdm import tqdm
4-
import numpy as np
52

63

74
class BaseTrain:
@@ -22,7 +19,7 @@ def train(self):
2219
def train_epoch(self):
2320
"""
2421
implement the logic of epoch:
25-
-loop ever the number of iteration in the config and call teh train step
22+
-loop over the number of iterations in the config and call the train step
2623
-add any summaries you want using the summary
2724
"""
2825
raise NotImplementedError

data_loader/data_generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import numpy as np
22

33

4-
class DataGenerator():
4+
class DataGenerator:
55
def __init__(self, config):
66
self.config = config
77
# load data here
88
self.input = np.ones((500, 784))
99
self.y = np.ones((500, 10))
10+
1011
def next_batch(self, batch_size):
1112
idx = np.random.choice(500, batch_size)
1213
yield self.input[idx], self.y[idx]

mains/example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def main():
1313
# capture the config path from the run arguments
14-
# then process the json configration file
14+
# then process the json configuration file
1515
try:
1616
args = get_args()
1717
config = process_config(args.config)
@@ -24,15 +24,15 @@ def main():
2424
create_dirs([config.summary_dir, config.checkpoint_dir])
2525
# create tensorflow session
2626
sess = tf.Session()
27-
# create instance of the model you want
27+
# create an instance of the model you want
2828
model = ExampleModel(config)
29-
#load model if exist
29+
#load model if exists
3030
model.load(sess)
3131
# create your data generator
3232
data = DataGenerator(config)
3333
# create tensorboard logger
3434
logger = Logger(sess, config)
35-
# create trainer and path all previous components to it
35+
# create trainer and pass all the previous components to it
3636
trainer = ExampleTrainer(sess, model, data, config, logger)
3737

3838
# here you train your model

models/example_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def build_model(self):
1414
self.x = tf.placeholder(tf.float32, shape=[None] + self.config.state_size)
1515
self.y = tf.placeholder(tf.float32, shape=[None, 10])
1616

17-
# network_architecture
18-
d1 = tf.layers.dense(self.x, 512, activation=tf.nn.relu, name="densee2")
19-
d2 = tf.layers.dense(d1, 10)
17+
# network architecture
18+
d1 = tf.layers.dense(self.x, 512, activation=tf.nn.relu, name="dense1")
19+
d2 = tf.layers.dense(d1, 10, name="dense2")
2020

2121
with tf.name_scope("loss"):
2222
self.cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=self.y, logits=d2))
@@ -27,6 +27,6 @@ def build_model(self):
2727

2828

2929
def init_saver(self):
30-
# here you initalize the tensorflow saver that will be used in saving the checkpoints.
30+
# here you initialize the tensorflow saver that will be used in saving the checkpoints.
3131
self.saver = tf.train.Saver(max_to_keep=self.config.max_to_keep)
3232

models/template_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def build_model(self):
1414
pass
1515

1616
def init_saver(self):
17-
#here you initalize the tensorflow saver that will be used in saving the checkpoints.
17+
# here you initialize the tensorflow saver that will be used in saving the checkpoints.
1818
# self.saver = tf.train.Saver(max_to_keep=self.config.max_to_keep)
1919

2020
pass

trainers/example_trainer.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@
22
from tqdm import tqdm
33
import numpy as np
44

5+
56
class ExampleTrainer(BaseTrain):
67
def __init__(self, sess, model, data, config,logger):
78
super(ExampleTrainer, self).__init__(sess, model, data, config,logger)
89

910
def train_epoch(self):
1011
loop = tqdm(range(self.config.num_iter_per_epoch))
11-
losses=[]
12-
accs=[]
13-
for it in loop:
12+
losses = []
13+
accs = []
14+
for _ in loop:
1415
loss, acc = self.train_step()
1516
losses.append(loss)
1617
accs.append(acc)
17-
loss=np.mean(losses)
18-
acc=np.mean(accs)
18+
loss = np.mean(losses)
19+
acc = np.mean(accs)
1920

2021
cur_it = self.model.global_step_tensor.eval(self.sess)
21-
summaries_dict = {}
22-
summaries_dict['loss'] = loss
23-
summaries_dict['acc'] = acc
22+
summaries_dict = {
23+
'loss': loss,
24+
'acc': acc,
25+
}
2426
self.logger.summarize(cur_it, summaries_dict=summaries_dict)
2527
self.model.save(self.sess)
28+
2629
def train_step(self):
2730
batch_x, batch_y = next(self.data.next_batch(self.config.batch_size))
2831
feed_dict = {self.model.x: batch_x, self.model.y: batch_y, self.model.is_training: True}

utils/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def get_config_from_json(json_file):
1919
return config, config_dict
2020

2121

22-
def process_config(jsonfile):
23-
config, _ = get_config_from_json(jsonfile)
22+
def process_config(json_file):
23+
config, _ = get_config_from_json(json_file)
2424
config.summary_dir = os.path.join("../experiments", config.exp_name, "summary/")
2525
config.checkpoint_dir = os.path.join("../experiments", config.exp_name, "checkpoint/")
26-
return config
26+
return config

utils/dirs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
3+
24
def create_dirs(dirs):
35
"""
46
dirs - a list of directories to create if these directories are not found

0 commit comments

Comments
 (0)