딥러닝 (1)
의도치 않게 딥러닝 3일차 과제를 하는 중에 구글의 사과를 받는 일이 발생했다. 문제의 코드 일부분은 다음과 같다. fromIPython.displayimportclear_output importmatplotlib.pyplotas plt # 1. Clear all existing plots from memory immediately plt.close( 'all' ) # 2. Setup model model = RegularizedMLP(dropout_rate= 0.3 , use_batchnorm= True ).to(device) optimizer = optim.Adam(model.parameters(), lr= 0.001 ) criterion = nn.BCELoss() # 3. Train - We add a cleanup step immediately after print ( "Training started..." ) model,reg_history = train_model( model, train_loader, val_loader, criterion, optimizer, num_epochs= 100 , patience= 20 , device=device ) # 4. THE CRITICAL FIX: Wipe all the "repeated" graphs created during training clear_output(wait= True ) # 5. Show ONLY the final result print ( "=" * 50 ) print ( "FINAL RESULT ONLY" ) print ( "=" * 50 ) plt.figure(figsize=( 10 , 5 )) plot_history(reg_history, "Regularized Model" ) plt.show()