Beispiel #1
0
                board_train.add_scalar('Pix2PixHD_Discriminator/loss_D3',
                                       loss_D3.item(), total_steps)
                board_train.add_scalar('Pix2PixHD_Discriminator/loss_D3_real',
                                       loss_D3_real.item(), total_steps)
                board_train.add_scalar('Pix2PixHD_Discriminator/loss_D3_fake',
                                       loss_D3_fake.item(), total_steps)

                print(
                    "total_steps={}, epoch={}, iters={}, loss_G={:.5f}, loss_feat={:.5f}, loss_vgg={:.5f}, loss_D={:.5f}"
                    .format(total_steps, epoch, iterations, loss_G, loss_feat,
                            loss_vgg, loss_D))

                visuals = [
                    [pre_image, after_image, g_fake_img],
                ]
                board_add_images(board_train, 'fake image', visuals,
                                 total_steps)

            #====================================================
            # test loss の表示
            #====================================================
            if (total_steps == 1
                    or (total_steps % args.n_display_test_step == 0)):
                model_G.eval()
                model_D.eval()

                n_test_loop = 0
                test_iterations = 0
                loss_D_total, loss_D1_total, loss_D2_total, loss_D3_total = 0, 0, 0, 0
                loss_D_real_total, loss_D1_real_total, loss_D2_real_total, loss_D3_real_total = 0, 0, 0, 0
                loss_D_fake_total, loss_D1_fake_total, loss_D2_fake_total, loss_D3_fake_total = 0, 0, 0, 0
                loss_G_total = 0
            # backward() で計算した勾配を元に、設定した optimizer に従って、重みを更新
            optimizer.step()

            #====================================================
            # 学習過程の表示
            #====================================================
            if (step == 0 or (step % args.n_display_step == 0)):
                board_train.add_scalar('Model/loss', loss.item(), iterations)
                print("epoch={}, iters={}, loss={:.5f}".format(
                    epoch, iterations, loss))

                visuals = [
                    [pre_image, after_image, output],
                ]
                board_add_images(board_train, 'images', visuals, iterations)

            #====================================================
            # test loss の表示
            #====================================================
            if (step == 0 or (step % args.n_display_test_step == 0)):
                model.eval()

                n_test_loop = 0
                test_iterations = 0
                loss_total = 0
                for test_inputs in dloader_test:
                    if test_inputs["aerial_image_tsr"].shape[
                            0] != args.batch_size_test:
                        break
Beispiel #3
0
                    board_train.add_scalar('D/loss_D_fake', loss_D_fake.item(),
                                           step)

                    print(
                        "step={}, loss_G={:.5f}, loss_l1={:.5f}, loss_vgg={:.5f}, loss_entropy={:.5f}, loss_bce={:.5f}, loss_adv={:.5f}"
                        .format(step, loss_G, loss_l1, loss_vgg, loss_entropy,
                                loss_bce, loss_adv))
                    print(
                        "step={}, loss_D={:.5f}, loss_D_real={:.5f}, loss_D_fake={:.5f}"
                        .format(step, loss_D.item(), loss_D_real.item(),
                                loss_D_fake.item()))

                    visuals = [
                        [image, mask, output],
                    ]
                    board_add_images(board_train, 'train', visuals, step + 1)

                #=====================================
                # 検証用データの処理
                #=====================================
                if (step == 0 or (step % args.n_display_valid_step == 0)):
                    loss_G_total = 0
                    loss_l1_total, loss_vgg_total = 0, 0
                    loss_entropy_total, loss_bce_total = 0, 0
                    loss_adv_total = 0
                    loss_D_total, loss_D_real_total, loss_D_fake_total = 0, 0, 0
                    n_valid_loop = 0
                    for iter, inputs in enumerate(tqdm(dloader_valid)):
                        model_G.eval()
                        model_D.eval()
Beispiel #4
0
                board_train.add_scalar('Generater/loss_l1', loss_l1.item(),
                                       iterations)
                board_train.add_scalar('Discriminator/loss_D', loss_D.item(),
                                       iterations)
                board_train.add_scalar('Discriminator/loss_D_real',
                                       loss_D_real.item(), iterations)
                board_train.add_scalar('Discriminator/loss_D_fake',
                                       loss_D_fake.item(), iterations)
                print(
                    "epoch={}, iters={}, loss_G={:.5f}, loss_D={:.5f}".format(
                        epoch, iterations, loss_G, loss_D))

                visuals = [
                    [pre_image, after_image, g_fake_img],
                ]
                board_add_images(board_train, 'fake image', visuals,
                                 iterations + 1)

            #====================================================
            # test loss の表示
            #====================================================
            if (step == 0 or (step % args.n_display_test_step == 0)):
                model_G.eval()
                model_D.eval()

                n_test_loop = 0
                test_iterations = 0
                loss_D_total = 0
                loss_D_real_total = 0
                loss_D_fake_total = 0
                loss_G_total = 0
                loss_gan_total = 0
Beispiel #5
0
                            .format(step, loss_D.item(), loss_D_real.item(),
                                    loss_D_fake.item()))
                        if (args.model_type_D == "ganimation"):
                            print("step={}, loss_G_cond_depth={:.5f}".format(
                                step,
                                loss_G_cond_depth,
                            ))
                            print("step={}, loss_D_cond_depth={:.5f}".format(
                                step,
                                loss_D_cond_depth,
                            ))

                    visuals = [
                        [image, mask, output],
                    ]
                    board_add_images(board_train, 'images', visuals, step + 1)

                step += 1
                n_print -= 1

            #====================================================
            # モデルの保存
            #====================================================
            if (epoch % args.n_save_epoches == 0):
                save_checkpoint(
                    model_G, device,
                    os.path.join(args.save_checkpoints_dir, args.exper_name,
                                 'model_ep%03d.pth' % (epoch)))
                save_checkpoint(
                    model_G, device,
                    os.path.join(args.save_checkpoints_dir, args.exper_name,