Exemple #1
0
                    loss_val = floss(outputs_Sv.squeeze(),
                                     targets_Sv)  # Current loss
                    loss_val_mean += loss_val.item()
        loss_val_mean = loss_val_mean / ValInstances
        endtime = time.time()
        print('Test time is %f' % (endtime - starttime))
        log.write('Test time is %f\n' % (endtime - starttime))

        #Observe results
        if plot and ((epoch + 1) % plotT == 0 or epoch == 0):
            [xtr, ytr, ptr, xval, yval, pval] = conter.torch2np(
                [D[ii], S[ii], outputs_S, Dv[jj], Sv[jj], outputs_Sv],
                formlist)
            player.plotmat([
                xtr[:, :, frame], ytr[:, :, frame], ptr[:, :, frame],
                xval[:, :, frame], yval[:, :, frame], pval[:, :, frame]
            ],
                           tit=['xtr', 'ytr', 'ptr', 'xval', 'yval', 'pval'],
                           supt='Epoch{%d/%d}' % (epoch + 1, num_epochs))
            plt.pause(0.1)

        lossmean_vec[epoch] = loss_mean
        lossmean_val_vec[epoch] = loss_val_mean

        # Print loss
        if (epoch + 1) % 1 == 0:  # % 10
            print('Epoch [%d/%d], Lossmean: %.5e, Validation lossmean: %.5e'\
                  %(epoch+1,num_epochs,loss_mean,loss_val_mean))
            log.write('Epoch [%d/%d], Lossmean: %.5e, Validation lossmean: %.5e\n'\
                  %(epoch+1,num_epochs,loss_mean,loss_val_mean))

            if loss.item() > 100:
Exemple #2
0
                    log.write('saved at [iteration%d/%d,epoch%d/%d]\n'\
                          %(niter+1,int(TrainInstances/BatchSize),
                            epoch+1,num_epochs))
                    torch.save(net.state_dict(),
                               "Results/%s_%sCPU_Res3dC_Model_Tr%s_epoch%s_lr%.2e.pkl"\
                               %(ProjectName,prefix,TrainInstances,num_epochs,learning_rate))
                    minloss = min(loss_val_mean, minloss)

                #Observe results
                if plot and ((epoch + 1) % plotT == 0 or epoch == 0):
                    [xtr, ytr, ptr, xval, yval, pval] = conter.torch2np(
                        [D[ii], S[ii], outputs_S, Dv[jj], Sv[jj], outputs_Sv],
                        formlist)
                    fig=player.plotmat([xtr[:,:,frame],ytr[:,:,frame],ptr[:,:,frame],
                                    xval[:,:,frame],yval[:,:,frame],pval[:,:,frame]],
                                    tit=['xtr','ytr','ptr','xval','yval','pval'],
                                    supt='{iteration%d/%d,epoch%d/%d}'\
                                    %(niter+1,int(TrainInstances/BatchSize),epoch+1,num_epochs))
                    plt.pause(0.1)

                inst = 0
                loss_mean = 0
    """Save logs, prediction, loss figure, loss data, model and settings """
    #Graphs
    #Save the prediction figure
    plt.savefig("Results/%s_%sCPU_Res3dC_Pred_Tr%s_epoch%s_lr%.2e.png"\
                %(ProjectName,prefix,TrainInstances,
                  num_epochs,learning_rate))

    #MSE
    fig = plt.figure()
Exemple #3
0
        log.write('Test time is %f\n' % (endtime - starttime))

        #Observe results
        if plot and ((epoch + 1) % plotT == 0 or epoch == 0):
            [xtr, ystr, pstr, xval, ysval, psval] = conter.torch2np(
                [D[ii], S[ii], outputs_S, Dv[jj], Sv[jj], outputs_Sv],
                formlist)
            [yltr, pltr, ylval,
             plval] = conter.torch2np([L[ii], outputs_L, Lv[jj], outputs_Lv],
                                      formlist)
            player.plotmat([
                xtr[:, :, frame], ystr[:, :, frame], yltr[:, :, frame], None,
                pstr[:, :, frame], pltr[:, :, frame], xval[:, :, frame],
                ysval[:, :, frame], ylval[:, :, frame], None,
                psval[:, :, frame], plval[:, :, frame]
            ],
                           tit=[
                               'xtr', 'ystr', 'yltr', None, 'pstr', 'pltr',
                               'xval', 'ysval', 'ylval', None, 'psval', 'plval'
                           ],
                           supt='Epoch{%d/%d}' % (epoch + 1, num_epochs))
            plt.pause(0.1)

        lossmean_vec[epoch] = loss_mean
        lossmean_val_vec[epoch] = loss_val_mean
        exp_L, exp_S = net.getexp_LS()
        exp_vec_L[epoch, :] = exp_L
        exp_vec_S[epoch, :] = exp_S

        # Print loss
        if (epoch + 1) % 1 == 0:  # % 10
Exemple #4
0
                               %(ProjectName,prefix,ALPHA,TrainInstances,
                                 num_epochs,learning_rate))
                    minloss=min(loss_val_mean,minloss)   

                #Observe results
                if plot and ((epoch+1)%plotT==0 or epoch==0):
                    [xtr,ystr,pstr,xval,ysval,psval]=conter.torch2np([D[ii],S[ii],outputs_S,
                                                                     Dv[jj],Sv[jj],outputs_Sv],
                                                                     formlist)
                    [yltr,pltr,ylval,plval]=conter.torch2np([L[ii],outputs_L,
                                                            Lv[jj],outputs_Lv],
                                                                 formlist)
                    player.plotmat([xtr[:,:,frame],ystr[:,:,frame],yltr[:,:,frame],
                                    None          ,pstr[:,:,frame],pltr[:,:,frame],
                                   xval[:,:,frame],ysval[:,:,frame],ylval[:,:,frame],
                                    None          ,psval[:,:,frame],plval[:,:,frame]],
                                    tit=['xtr','ystr','yltr',None,'pstr','pltr',
                                         'xval','ysval','ylval',None,'psval','plval'],
                                    supt='Epoch{%d/%d,%d/%d}'\
                                    %(niter+1,int(TrainInstances/BatchSize),epoch+1,num_epochs))
                    plt.pause(0.1)
                    
                inst=0
                loss_mean=0
        
          
    """Save logs, prediction, loss figure, loss data, model and settings """
    #Graphs
    #Save the prediction figure
    plt.savefig("Results/%s_%sCPU_Unfolded_Pred_al%.2f_Tr%s_epoch%s_lr%.2e.png"\
                %(ProjectName,prefix,ALPHA,TrainInstances,
                  num_epochs,learning_rate))