@@ -277,18 +277,17 @@ def train_one_epoch(epoch_index, tb_writer):
277277# Initializing in a separate cell so we can easily add more epochs to the same run
278278timestamp = datetime .now ().strftime ('%Y%m%d_%H%M%S' )
279279writer = SummaryWriter ('runs/fashion_trainer_{}' .format (timestamp ))
280- epoch_number = 0
281280
282281EPOCHS = 5
283282
284283best_vloss = 1_000_000.
285284
286285for epoch in range (EPOCHS ):
287- print ('EPOCH {}:' .format (epoch_number + 1 ))
286+ print ('EPOCH {}:' .format (epoch + 1 ))
288287
289288 # Make sure gradient tracking is on, and do a pass over the data
290289 model .train (True )
291- avg_loss = train_one_epoch (epoch_number , writer )
290+ avg_loss = train_one_epoch (epoch , writer )
292291
293292
294293 running_vloss = 0.0
@@ -311,16 +310,14 @@ def train_one_epoch(epoch_index, tb_writer):
311310 # for both training and validation
312311 writer .add_scalars ('Training vs. Validation Loss' ,
313312 { 'Training' : avg_loss , 'Validation' : avg_vloss },
314- epoch_number + 1 )
313+ epoch + 1 )
315314 writer .flush ()
316315
317316 # Track best performance, and save the model's state
318317 if avg_vloss < best_vloss :
319318 best_vloss = avg_vloss
320- model_path = 'model_{}_{}' .format (timestamp , epoch_number )
319+ model_path = 'model_{}_{}' .format (timestamp , epoch )
321320 torch .save (model .state_dict (), model_path )
322-
323- epoch_number += 1
324321
325322
326323#########################################################################
0 commit comments