vojirt / JSRNet

Pytorch implementation of our ICCV 2021 paper "Road Anomaly Detection by Partial Image Reconstruction with Segmentation Coupling"
18 stars 5 forks source link

KeyError: 'Non-existent config key: MODEL.RECONSTRUCTION.SEGM_MODEL_NCLASS' #6

Closed bieyl closed 5 months ago

bieyl commented 5 months ago

Hello! I try to run test part.

联想截图_20240402172639
vojirt commented 5 months ago

Hi, I would need to know more details. What command are you running exactly (what are the arguments you are parsing)? Did you set correct path in ReconAnom.py (line 7)? Also use absolute path everywhere, some people have trouble using relative paths (e.g. for checkpoint file). I have tested the code only in Ubuntu, so this may be some windows/mac related thing with python paths not being included and not loading proper configurations.

Also, I have published follow up method that performs significantly better at https://github.com/vojirt/DaCUP so you can try that as well.

bieyl commented 5 months ago

Thanks for your reversion! Bellow are my setups: running: python ReconAnom.py in ReconAnom.py (line 7): sys.path.append("F:/下载/JSRNet-main/code/config/") from config.defaults import get_cfg_defaults in defaults.py: _C.MODEL.RECONSTRUCTION.SEGM_MODEL = "F:/下载/JSRNet-main/code/config/checkpoint-segmentation.pth" in parameters.yaml: MODEL: BACKBONE: resnet FREEZE_BN: false NET: DeepLabReconFuseSimpleTrain OUT_STRIDE: 16 RECONSTRUCTION: LATENT_DIM: 4 SEGM_MODEL: F:/下载/JSRNet-main/code/config/checkpoint-segmentation.pth SEGM_MODEL_NCLASS: 19 SKIP_CONN: false SKIP_CONN_DIM: 32

vojirt commented 5 months ago

did you also set params = {"exp_dir": on line 104 of ReconAnom.py to "F:/下载/JSRNet-main/"?

otherwise everything seems fine and should work. This seems to be an issue with merging default configs (from code/config/defaults.py) with the saved experiment parameters from file parameters.yaml.

bieyl commented 5 months ago

Hello! About two .pth files:_C.MODEL.RECONSTRUCTION.SEGM_MODEL = "F:/下载/JSRNet-main/code/config/checkpoint-segmentation.pth" (default.py) SEGM_MODEL: F:/下载/JSRNet-main/code/config/checkpoint-best.pth (parameters.yaml)

KeyError: 'Non-existent config key: MODEL.RECONSTRUCTION.SEGM_MODEL_CLASS'

Please make sure the directory about two files and in default.py _C.MODEL.RECONSTRUCTION.SEGM_MODEL = "F:/下载/JSRNet-main/code/config/checkpoint-segmentation.pth" , there is not exiting MODEL.RECONSTRUCTION.SEGM_MODEL_CLASS

bieyl commented 5 months ago

AssertionError: Experiment dir does not contain best checkpoint, or no checkpoint specified or specified checkpoint does not exist: None

bieyl commented 5 months ago

.defaults.py: from yacs.config import CfgNode as CN

_C = CN()

_C.SYSTEM = CN() _C.SYSTEM.NUM_CPU = 4
_C.SYSTEM.USE_GPU = True _C.SYSTEM.GPU_IDS = [0] # which gpus to use for training - list of int, e.g. [0, 1] _C.SYSTEM.RNG_SEED = 42

_C.MODEL = CN()

_C.MODEL.NET = "DeepLabRecon" # available networks from net.models.py file

_C.MODEL.NET = "DeepLabReconFuseSimpleTrain" # available networks from net.models.py file _C.MODEL.BACKBONE = "resnet" # choices: ['resnet', 'xception', 'drn', 'mobilenet'] _C.MODEL.OUT_STRIDE = 16 # deeplab output stride _C.MODEL.SYNC_BN = None # whether to use sync bn (for multi-gpu), None == Auto detect _C.MODEL.FREEZE_BN = False

_C.MODEL.RECONSTRUCTION = CN() _C.MODEL.RECONSTRUCTION.LATENT_DIM = 4 # number of channels of latent space

_C.MODEL.RECONSTRUCTION.SEGM_MODEL = "/mnt/datagrid/personal/vojirtom/sod/mcsegm/20210209_112729_903607/checkpoints/checkpoint-best.pth" #resnet 51.6

_C.MODEL.RECONSTRUCTION.SEGM_MODEL = "/mnt/datagrid/personal/vojirtom/sod/mcsegm/20210302_234038_642070/checkpoints/checkpoint-best.pth" #resnet 66.1

_C.MODEL.RECONSTRUCTION.SEGM_MODEL = "/mnt/datagrid/personal/vojirtom/sod/mcsegm/20210306_213340_619898/checkpoints/checkpoint-best.pth" #mobilenet 61.2

_C.MODEL.RECONSTRUCTION.SEGM_MODEL = "/mnt/datagrid/personal/vojirtom/sod/mcsegm/20210306_214758_686017/checkpoints/checkpoint-best.pth" #xception 50.3

_C.MODEL.RECONSTRUCTION.SEGM_MODEL = "F:/下载/JSRNet-main/code/config/checkpoint-best.pth" _C.MODEL.RECONSTRUCTION.SEGM_MODEL_NCLASS = 19 # 19 for cityscapes _C.MODEL.RECONSTRUCTION.SKIP_CONN = False _C.MODEL.RECONSTRUCTION.SKIP_CONN_DIM = 32

_C.LOSS = CN()

_C.LOSS.TYPE = "ReconstructionAnomalyLoss" # available losses from net.loss.py

_C.LOSS.TYPE = "ReconstructionAnomalyLossFuseSimple" # available losses from net.loss.py

_C.LOSS.TYPE = "ReconstructionAnomalyLossFuseTrainAux" # available losses from net.loss.py _C.LOSS.IGNORE_LABEL = 255 _C.LOSS.SIZE_AVG = True _C.LOSS.BATCH_AVG = True

_C.EXPERIMENT= CN() _C.EXPERIMENT.NAME = None # None == Auto name from date and time

_C.EXPERIMENT.OUT_DIR = "/ssd/temporary/vojirtom/code_temp/sod/training/mcsegm/"

_C.EXPERIMENT.OUT_DIR = "F:/下载/JSRNet-main/code/result" _C.EXPERIMENT.EPOCHS = 200 # number of training epochs _C.EXPERIMENT.START_EPOCH = 0 _C.EXPERIMENT.USE_BALANCED_WEIGHTS = False _C.EXPERIMENT.RESUME_CHECKPOINT = None # path to resume file (stored checkpoint) _C.EXPERIMENT.EVAL_INTERVAL = 1 # eval every X epoch _C.EXPERIMENT.EVAL_METRIC = "AnomalyEvaluator" # available evaluation metrics from utils.metrics.py file

_C.INPUT = CN() _C.INPUT.BASE_SIZE = 896 _C.INPUT.CROP_SIZE = 896 _C.INPUT.NORM_MEAN = [0.485, 0.456, 0.406] # mean for the input image to the net (image -> (0, 1) -> mean/std) _C.INPUT.NORM_STD = [0.229, 0.224, 0.225] # std for the input image to the net (image -> (0, 1) -> mean/std) _C.INPUT.BATCH_SIZE_TRAIN = None # None = Auto set based on training dataset _C.INPUT.BATCH_SIZE_TEST = None # None = Auto set based on training batch size

_C.AUG = CN() _C.AUG.RANDOM_CROP_PROB = 0.5 # prob that random polygon (anomaly) will be cut from image vs. random noise _C.AUG.SCALE_MIN = 0.5 _C.AUG.SCALE_MAX = 2.0 _C.AUG.COLOR_AUG = 0.25

_C.OPTIMIZER = CN() _C.OPTIMIZER.LR = 0.001 _C.OPTIMIZER.LR_SCHEDULER = "poly" # choices: ['poly', 'step', 'cos'] _C.OPTIMIZER.MOMENTUM = 0.9 _C.OPTIMIZER.WEIGHT_DECAY = 5e-4 _C.OPTIMIZER.NESTEROV = False

_C.DATASET = CN() _C.DATASET.TRAIN = "cityscapes_2class" # choices: ['cityscapes'], _C.DATASET.VAL = "LaF" # choices: ['cityscapes'], _C.DATASET.TEST = "LaF" # choices: ['LaF'], _C.DATASET.FT = False # flag if we are finetuning

def get_cfg_defaults(): """Get a yacs CfgNode object with default values for my_project.""" return _C.clone()

parameters.yaml: AUG: COLOR_AUG: 0.25 RANDOM_CROP_PROB: 0.5 SCALE_MAX: 2.0 SCALE_MIN: 0.5 DATASET: FT: false TEST: LaF TRAIN: cityscapes_2class VAL: LaF EXPERIMENT: EPOCHS: 200 EVAL_INTERVAL: 1 EVAL_METRIC: AnomalyEvaluator NAME: '20210311_212250_897984' OUT_DIR: F:/下载/JSRNet-main/code/result RESUME_CHECKPOINT: null START_EPOCH: 0 USE_BALANCED_WEIGHTS: false INPUT: BASE_SIZE: 896 BATCH_SIZE_TEST: 4 BATCH_SIZE_TRAIN: 4 CROP_SIZE: 896 NORM_MEAN:

vojirt commented 5 months ago

Have you downloaded the checkpoints files and put them to the directories you set in the configuration, i.e. SEGM_MODEL: F:/下载/JSRNet-main/code/config/checkpoint-segmentation.pth ?

The issues you describing does not seem to be problem of the code. Try to follow the Readme instructions thoroughly, debug yourself why it fails, and let me know if it something code related.

bieyl commented 5 months ago

Thanks! Please check my setups. For default.py ,_C.MODEL.RECONSTRUCTION.SEGM_MODEL = "F:/下载/JSRNet-main/code/config/checkpoint-best.pth". For parameters.yaml,SEGM_MODEL: F:/下载/JSRNet-main/code/config/checkpoint-segmentation.pth. Above all, are the two .pth files inserting correctly? And the checkpoint-best.pth gived in readme is just pretrained .pth,all right? So,could you send me your trained checkpoint-best.pth? My email:1041389171@qq.com

vojirt commented 5 months ago

all references of SEGM_MODEL should point to F:/下载/JSRNet-main/code/config/checkpoint-segmentation.pth, you need to download checkpoint-best.pth (look to github readme, link is available there under Model section point 2) and save this model to F:/下载/JSRNet-main/code/checkpoints/checkpoint-best.pth (the ReconAnom.py is looking to this directory automatically to load the model).

bieyl commented 5 months ago

Thanks! You mean in the defeult.py and parameters.yaml ,SEGM_MODEL all should point to F:/下载/JSRNet-main/code/config/checkpoint-segmentation.pth. Then save this model to F:/下载/JSRNet-main/code/checkpoints/checkpoint-best.pth without pointed to?

bieyl commented 5 months ago
联想截图_20240404133457 联想截图_20240404133605
bieyl commented 5 months ago

from ..net.sync_batchnorm.batchnorm import SynchronizedBatchNorm2d ImportError: attempted relative import with no known parent package

bieyl commented 5 months ago
联想截图_20240404225029
bieyl commented 5 months ago
联想截图_20240405122254
bieyl commented 5 months ago

Hello! Aboved is the result of running ReconAnom.py. But,i try to find the finally result in images . where can i find the segmentation images?

bieyl commented 5 months ago

Hello! Aboved is the result of running ReconAnom.py. But,i try to find the finally result in images . where can i find the segmentation images? Could U instruct me? Thank you sincerely!