open-mmlab / mmpretrain

OpenMMLab Pre-training Toolbox and Benchmark
https://mmpretrain.readthedocs.io/en/latest/
Apache License 2.0
3.48k stars 1.08k forks source link

[Bug] RuntimeError: Invalid mode "predict". #1539

Open alaa-shubbak opened 1 year ago

alaa-shubbak commented 1 year ago

Branch

main branch (mmpretrain version)

Describe the bug

i try to run the training of a model of densecl on my custom dataset i run this command on 1 gpu system

python tools/train.py configs/densecl/densecl_resnet50_8xb32-coslr-200e_ACID.py --work-dir train_dir/densecl_resnet50_ACID/

the model started the training ,and reached to 1st iterative values ,saved the epoch results of 10 then gave me the following error message:

new error using mmpretrain after epoch1

which is the RuntimeError: Invalid mode "predict". i don't have any idea about such error , could you please help me?

Environment

after running /getting the environment info , i got this `` {'sys.platform': 'linux', 'Python': '3.8.11 (default, Jul 13 2021, 14:00:03) [GCC 4.8.5 20150623 (Red ' 'Hat 4.8.5-44)]', 'CUDA available': True, 'numpy_random_seed': 2147483648, 'GPU 0': 'Tesla V100-SXM2-32GB', 'CUDA_HOME': '/usr/local/cuda', 'NVCC': 'Cuda compilation tools, release 12.1, V12.1.105', 'GCC': 'gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)', 'PyTorch': '2.0.0+cu117', 'TorchVision': '0.15.1+cu117', 'OpenCV': '4.7.0', 'MMEngine': '0.7.3', 'MMCV': '2.0.0', 'MMPreTrain': '1.0.0rc7+e80418a'}

``

Other information

i did the modification on the my new dataset file , which is under base/dataset

also i add more info in the config file to ensure that the iteartive will be 10 instead of 100 in the original densecl as my dataset is smaller compared to the imagenet dataset.

i used the original imagenet_bs32_mocov2.py

but add more info /dir for test and val dataloader , pipleline ,cfg and evaluator .

alaa-shubbak commented 1 year ago

until now i did not understand why making this mmpretrain repository and add mmselfsup to it . it is more complicate to get it and make me confused.

why not work separately on the mmselfsup? and what is the benefit of that? even more there is no colab example or complete example explain what is going on here with mmpretrain like what have been mentioned in mmselfsup.

should i install mmselfsup with mmpretrain so i can train my selfsup model, or just train it with mmpretrain library?

fangyixiao18 commented 1 year ago

For self-supervised leanrnig algorithms, there is no mode for 'predict'. Besides, to train your selfsup model, you could just train it with mmpretrain library.

alaa-shubbak commented 1 year ago

For self-supervised leanrnig algorithms, there is no mode for 'predict'. Besides, to train your selfsup model, you could just train it with mmpretrain library.

thank you for response. I did so . I try to train my selfsup model using mmpretrain as mentioned above , but I got such error RuntimeError: Invalid mode "predict".

so i was so confused ,as it is my first time to see such error in open-mmlab

could you please help me in solving such error?

here is the dataset config i modified :

image image image

is it forbidden to have the test,val dataloader, pipeline and evaluator within training the selfsup models?

looking forward to have an answer from your side.

alaa-shubbak commented 1 year ago

I still need to open this issue again , but for another task as bellow :

I try to run inference over my self-supervised trained model. so i used this info and commands in this doc

unfortunately , I got this error again :

    raise RuntimeError(f'Invalid mode "{mode}".')
RuntimeError: Invalid mode "predict".

which means that inference does not working with mmselfsupervised model , although i modified my config to have the test_pipeline and the val_dataloader

according to this , can some one please explain to me how to test my pretrained self-supervised model over my part of the data (images without labels) and get the classes ? I don't need to use another downstream tasks such as detection and segmenation , i only need the classification.

any help please ?

here is the full error log after running the last command of >>> result = inferencer(image)[0]

Inference ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Traceback (most recent call last): File "", line 1, in File "/scratch/shubbak/mmpretrain/mmpretrain/apis/image_classification.py", line 123, in call return super().call(inputs, return_datasamples, batch_size, File "/home/shubbak/pose_env2/lib/python3.8/site-packages/mmengine/infer/infer.py", line 217, in call preds.extend(self.forward(data, forward_kwargs)) File "/home/shubbak/pose_env2/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(args, kwargs) File "/home/shubbak/pose_env2/lib/python3.8/site-packages/mmengine/infer/infer.py", line 290, in forward return self.model.test_step(inputs) File "/home/shubbak/pose_env2/lib/python3.8/site-packages/mmengine/model/base_model/base_model.py", line 145, in test_step return self._run_forward(data, mode='predict') # type: ignore File "/home/shubbak/pose_env2/lib/python3.8/site-packages/mmengine/model/base_model/base_model.py", line 340, in _run_forward results = self(data, mode=mode) File "/home/shubbak/pose_env2/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(args, kwargs) File "/scratch/shubbak/mmpretrain/mmpretrain/models/selfsup/base.py", line 129, in forward raise RuntimeError(f'Invalid mode "{mode}".') RuntimeError: Invalid mode "predict".