WongKinYiu / yolov7

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
GNU General Public License v3.0
13.41k stars 4.23k forks source link

[bug] AttributeError: module 'numpy' has no attribute 'int' while training model on custom dataset for image segmentation task #2007

Open sahilbirje4551 opened 8 months ago

sahilbirje4551 commented 8 months ago

edit: I've made the required changes in my fork, might need reviewing , pull request pending

code: %cd {HOME}/yolov7/seg !python segment/train.py --batch 16 \ --epochs 10 \ --data {dataset.location}/data.yaml \ --weights $WEIGHTS_PATH \ --device 0 \ --name custom

Error: train: New cache created: /content/yolov7/seg/Lane-Detection-3/train/labels.cache Traceback (most recent call last): File "/content/yolov7/seg/segment/train.py", line 681, in main(opt) File "/content/yolov7/seg/segment/train.py", line 577, in main train(opt.hyp, opt, device, callbacks) File "/content/yolov7/seg/segment/train.py", line 191, in train train_loader, dataset = create_dataloader( File "/content/yolov7/seg/./utils/segment/dataloaders.py", line 43, in create_dataloader dataset = LoadImagesAndLabelsAndMasks( File "/content/yolov7/seg/./utils/segment/dataloaders.py", line 98, in init super().init(path, img_size, batch_size, augment, hyp, rect, image_weights, cache_images, single_cls, File "/content/yolov7/seg/./utils/dataloaders.py", line 488, in init bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index File "/usr/local/lib/python3.10/dist-packages/numpy/init.py", line 319, in getattr raise AttributeError(__former_attrs__[attr]) AttributeError: module 'numpy' has no attribute 'int'. np.int was a deprecated alias for the builtin int. To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'inf'?

Asiful-Haque commented 7 months ago

I am also facing this issue.Did you fix that?

abdulghani91 commented 6 months ago

@sahilbirje4551 @Asiful-Haque

If you have the same:

train: New cache created: /content/yolov7/seg/Street_dataset/train/labels.cache Traceback (most recent call last): File "/content/yolov7/seg/segment/train.py", line 681, in main(opt) File "/content/yolov7/seg/segment/train.py", line 577, in main train(opt.hyp, opt, device, callbacks) File "/content/yolov7/seg/segment/train.py", line 191, in train train_loader, dataset = create_dataloader( File "/content/yolov7/seg/./utils/segment/dataloaders.py", line 43, in create_dataloader dataset = LoadImagesAndLabelsAndMasks( File "/content/yolov7/seg/./utils/segment/dataloaders.py", line 98, in init super().init(path, img_size, batch_size, augment, hyp, rect, image_weights, cache_images, single_cls, File "/content/yolov7/seg/./utils/dataloaders.py", line 488, in init bi = np.floor(np.arange(n) / batch_size).astype(np.int) # batch index File "/usr/local/lib/python3.10/dist-packages/numpy/init.py", line 319, in getattr raise AttributeError(__former_attrs__[attr]) AttributeError: module 'numpy' has no attribute 'int'. np.int was a deprecated alias for the builtin int. To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:

I managed to solve the issue and run the training.

Go to seg/utils/dataloaders.py (I am using the u7 branch for segmentation). Then, navigate to line 488 and make the following changes:

original: bi = np.floor(np.arange(n) / batch_size).astype(np.int)

change: .astype(np.int) ===> to .astype(np.int)

bi = np.floor(np.arange(n) / batch_size).astype(np.int64)

this will fix your problem.

I fixed it and ran the training on Colab; it works fine now.