Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions dcgan/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@


def deconv(c_in, c_out, k_size, stride=2, pad=1, bn=True):
layers = []
layers.append(nn.ConvTranspose2d(c_in, c_out, k_size, stride, pad))
layers = [nn.ConvTranspose2d(c_in, c_out, k_size, stride, pad)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function deconv refactored with the following changes:

if bn:
layers.append(nn.BatchNorm2d(c_out))
return nn.Sequential(*layers)


def conv(c_in, c_out, k_size, stride=2, pad=1, bn=True):
layers = []
layers.append(nn.Conv2d(c_in, c_out, k_size, stride, pad))
layers = [nn.Conv2d(c_in, c_out, k_size, stride, pad)]
Comment on lines -14 to +13
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function conv refactored with the following changes:

if bn:
layers.append(nn.BatchNorm2d(c_out))
return nn.Sequential(*layers)
Expand Down
7 changes: 3 additions & 4 deletions extra/charnn/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ def pick_top_n(preds, vocab_size):
p = np.squeeze(preds)
p[np.argsort(p)[:-5]] = 0
p = p / np.sum(p)
c = np.random.choice(vocab_size, 1, p=p)[0]
return c
return np.random.choice(vocab_size, 1, p=p)[0]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pick_top_n refactored with the following changes:



def sample(checkpoint):
samples = [c for c in prime]
samples = list(prime)
Comment on lines -23 to +22
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sample refactored with the following changes:

int_to_vocab, vocab_to_int, no_classes = pickle.load(
open("./saves/data.p", "rb"))

Expand All @@ -45,7 +44,7 @@ def sample(checkpoint):
samples.append(int_to_vocab[c])

# Generate new samples
for i in range(n_samples):
for _ in range(n_samples):
x[0, 0] = c
feed = {model.inputs: x, model.initial_state: new_state}
preds, new_state = sess.run(
Expand Down
11 changes: 7 additions & 4 deletions extra/charnn/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ def train():
batch_loss, new_state, _ = sess.run(
[model.loss, model.final_state, model.train_op], feed_dict=feed)
end = time.time()
print('Epoch: {} '.format(e + 1), 'Loss: {:.4f} '.format(batch_loss),
'{:.4f} sec/batch'.format((end - start)))
print(
f'Epoch: {e + 1} ',
'Loss: {:.4f} '.format(batch_loss),
'{:.4f} sec/batch'.format((end - start)),
)

if (counter % save_every_n == 0):
saver.save(sess, "saves/{}.ckpt".format(counter))
saver.save(sess, f"saves/{counter}.ckpt")

saver.save(sess, "saves/{}.ckpt".format(counter))
saver.save(sess, f"saves/{counter}.ckpt")
Comment on lines -73 to +82
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function train refactored with the following changes:



if __name__ == '__main__':
Expand Down
7 changes: 2 additions & 5 deletions resnet/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ def make_layer(self, block, out_channels, blocks, stride=1):
downsample = nn.Sequential(
conv3x3(self.in_channels, out_channels, stride=stride),
nn.BatchNorm2d(out_channels))
layers = []
layers.append(
block(self.in_channels, out_channels, stride, downsample))
layers = [block(self.in_channels, out_channels, stride, downsample)]
self.in_channels = out_channels
for i in range(1, blocks):
layers.append(block(out_channels, out_channels))
layers.extend(block(out_channels, out_channels) for _ in range(1, blocks))
Comment on lines -52 to +54
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResNet.make_layer refactored with the following changes:

return nn.Sequential(*layers)

def forward(self, x):
Expand Down