jolibrain/joliGEN

Problem using code to generate image from models

YoannRandon opened this issue · 6 comments

Hello,

I tried to generate image using the gen_single_image.py file in "/joliGAN/scripts/" but i got the following error of import on "networks" function from "model" package
import_networks_error_joligan
So i check where the "networks" function is called in the code and it seems like it should be refered as gan_networks instead.
after swapping networks by gan_networks, i got another import error .on
import_cut_sem_mask_error_joligan
I check in models and find out that cut_semantic_mask_model is more likely called re_cut_semantic_mask_model .

my current goal is to use a model loaded from the UI of joligan and use it on a sample of bdd100k images.
I would like to know if i am using the appropriate repository.

Thanks for your attention.

Hi,
Thanks for your interest in JoliGAN !
You're right, networks should now be refered as gan_networks, I will fix it in a coming PR.
The second import problem depends on your config file. Please copy your config file here, I think you are using an old one.
Moreover, I think there is a mistake in your commandline, you need to give the path to your generator weights not to your discriminator ones.
Using the UI won't solve your problem, you need to use a script. JoliGAN's documentation will be updated soon and will present how to do it.

I am using the current version of the code in github. I didn't modify anything concerning config file.
There is currently 6 config files in the models/configs/segformer/ folder
the first one look like this :

configfile

Sorry I'm talking about the training_config.json which needs to be in the same folder as your generator weights file latest_netG_A.pth. This json stores all the training parameters, some of them are needed to process inference.

The model i load from the UI Joligan contains 2 files:
t
the training_json file start with :
te

complete json file :

{
    "D": {
        "dropout": false,
        "n_layers": 3,
        "ndf": 64,
        "netDs": [
            "projected_d",
            "basic",
            "vision_aided"
        ],
        "no_antialias": false,
        "no_antialias_up": false,
        "norm": "instance",
        "proj_config_segformer": "models/configs/segformer/segformer_config_b0.py",
        "proj_interp": 512,
        "proj_network_type": "vitsmall",
        "proj_weight_segformer": "models/configs/segformer/pretrain/segformer_mit-b0.pth",
        "spectral": false,
        "temporal_every": 4,
        "temporal_frame_step": 30,
        "temporal_num_common_char": -1,
        "temporal_number_frames": 5,
        "vision_aided_backbones": "clip+dino"
    },
    "G": {
        "attn_nb_mask_attn": 10,
        "attn_nb_mask_input": 1,
        "backward_compatibility_twice_resnet_blocks": false,
        "config_segformer": "models/configs/segformer/segformer_config_b0.py",
        "dropout": false,
        "netE": "resnet_512",
        "netG": "segformer_attn_conv",
        "ngf": 64,
        "norm": "instance",
        "padding_type": "reflect",
        "spectral": false,
        "stylegan2_num_downsampling": 1
    },
    "alg": {
        "cut": {
            "flip_equivariance": false,
            "lambda_GAN": 1.0,
            "lambda_NCE": 1.0,
            "nce_T": 0.07,
            "nce_idt": true,
            "nce_includes_all_negatives_from_minibatch": false,
            "nce_layers": "0,4,8,12,16",
            "netF": "mlp_sample",
            "netF_dropout": false,
            "netF_nc": 256,
            "netF_norm": "instance",
            "num_patches": 256
        },
        "cyclegan": {},
        "re": {
            "P_lr": 0.0002,
            "adversarial_loss_p": false,
            "netP": "unet_128",
            "no_train_P_fake_images": false,
            "nuplet_size": 3,
            "projection_threshold": 1.0
        }
    },
    "data": {
        "online_creation": {
            "crop_delta_A": 64,
            "crop_delta_B": 64,
            "crop_size_A": 512,
            "crop_size_B": 512,
            "mask_delta_A": 0,
            "mask_delta_B": 0,
            "mask_square_A": false,
            "mask_square_B": false
        },
        "crop_size": 512,
        "dataset_mode": "unaligned_labeled_mask_online",
        "direction": "AtoB",
        "load_size": 512,
        "max_dataset_size": 1000000000,
        "num_threads": 4,
        "online_context_pixels": 0,
        "preprocess": "resize_and_crop",
        "relative_paths": false,
        "sanitize_paths": false,
        "serial_batches": false
    },
    "f_s": {
        "all_classes_as_one": false,
        "class_weights": [
            1,
            10,
            10,
            1,
            5,
            5,
            10,
            10,
            30,
            50,
            50
        ],
        "config_segformer": "models/configs/segformer/segformer_config_b0.py",
        "dropout": false,
        "net": "segformer",
        "nf": 64,
        "semantic_nclasses": 11,
        "semantic_threshold": 1.0,
        "weight_segformer": ""
    },
    "output": {
        "display": {
            "G_attention_masks": false,
            "diff_fake_real": false,
            "env": "bdd100k_weather_det_clear2rainy_mm1",
            "freq": 200,
            "id": 1,
            "ncols": 4,
            "networks": false,
            "port": 8097,
            "server": "http://localhost",
            "winsize": 256
        },
        "no_html": false,
        "print_freq": 200,
        "update_html_freq": 1000,
        "verbose": false
    },
    "model": {
        "init_gain": 0.02,
        "init_type": "normal",
        "input_nc": 3,
        "multimodal": true,
        "output_nc": 3
    },
    "train": {
        "sem": {
            "cls_B": false,
            "cls_pretrained": false,
            "cls_template": "basic",
            "idt": true,
            "l1_regression": false,
            "lambda": 1.0,
            "lr_f_s": 0.0002,
            "net_output": false,
            "regression": false,
            "use_label_B": true
        },
        "mask": {
            "charbonnier_eps": 1e-06,
            "disjoint_f_s": false,
            "f_s_B": true,
            "for_removal": false,
            "lambda_out_mask": 10.0,
            "loss_out_mask": "L1",
            "no_train_f_s_A": false,
            "out_mask": false
        },
        "D_accuracy_every": 1000,
        "D_lr": 0.0001,
        "G_ema": true,
        "G_ema_beta": 0.999,
        "G_lr": 0.0002,
        "batch_size": 2,
        "beta1": 0.9,
        "beta2": 0.999,
        "compute_D_accuracy": false,
        "compute_fid": false,
        "compute_fid_val": false,
        "continue": false,
        "epoch": "latest",
        "epoch_count": 1,
        "fid_every": 1000,
        "gan_mode": "lsgan",
        "iter_size": 4,
        "load_iter": 0,
        "lr_decay_iters": 50,
        "lr_policy": "linear",
        "mm_lambda_z": 0.5,
        "mm_nz": 16,
        "n_epochs": 100,
        "n_epochs_decay": 100,
        "nb_img_max_fid": 1000000000,
        "optim": "adam",
        "pool_size": 50,
        "save_by_iter": false,
        "save_epoch_freq": 1,
        "save_latest_freq": 5000,
        "use_contrastive_loss_D": false
    },
    "dataaug": {
        "APA": false,
        "APA_every": 4,
        "APA_nimg": 50,
        "APA_p": 0,
        "APA_target": 0.6,
        "D_label_smooth": false,
        "D_noise": 0.01,
        "affine": 0.0,
        "affine_scale_max": 1.2,
        "affine_scale_min": 0.8,
        "affine_shear": 45,
        "affine_translate": 0.2,
        "diff_aug_policy": "",
        "diff_aug_proba": 0.5,
        "imgaug": false,
        "no_flip": false,
        "no_rotate": true
    },
    "checkpoints_dir": "/data1/confiance_platform/checkpoints/",
    "dataroot": "/data1/confiance/datasets/bdd100k_weather_det_clear2rainy/",
    "ddp_port": "13456",
    "gpu_ids": "1",
    "model_type": "cut_semantic_mask",
    "name": "bdd100k_weather_det_clear2rainy_mm1",
    "phase": "train",
    "suffix": "",
    "warning_mode": false
}
beniz commented

Hi @YoannRandon
Initial issue is fixed by #289 now merged into master, thanks for the report.

The codebase is moving fast and the train_config.json needs a fix.

Change "model_type":"cut_semantic_mask" with "model_type":"cut" in the train_config.json. From there it works for me, image below.

9aba8323-6f62a91a_rainy