Skip to content

Commit

Permalink
Update crnn_main_v2.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Sierkinhane authored Aug 6, 2019
1 parent 4faa120 commit 717aa72
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crnn_main_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def weights_init(m):


def val(net, val_loader, criterion, iteration, max_i=1000):

print('Start val')
for p in crnn.parameters():
p.requires_grad = False
Expand Down Expand Up @@ -123,10 +123,14 @@ def main(crnn, train_loader, val_loader, criterion, optimizer):
print("is best accuracy: {0}".format(accuracy > params.best_accuracy))
Iteration+=1

def backward_hook(self, grad_input, grad_output):
for g in grad_input:
g[g != g] = 0 # replace all nan/inf in gradients to zero

if __name__ == '__main__':

# args = init_args()
# manualSeed = random.randint(1, 10000) # fix seed
# manualSeed = random.randint(1, 10000) #fix seed
manualSeed=10
random.seed(manualSeed)
np.random.seed(manualSeed)
Expand Down Expand Up @@ -175,4 +179,5 @@ def main(crnn, train_loader, val_loader, criterion, optimizer):
else:
optimizer = optim.RMSprop(crnn.parameters(), lr=params.lr)

crnn.register_backward_hook(backward_hook)
main(crnn, train_loader, val_loader, criterion, optimizer)

0 comments on commit 717aa72

Please sign in to comment.