czg1225 / SlimSAM

[NeurIPS 2024] SlimSAM: 0.1% Data Makes Segment Anything Slim
Apache License 2.0
274 stars 17 forks source link

list index out of range #3

Open BuKeMod opened 9 months ago

BuKeMod commented 9 months ago

I'm using the dataset from roboflow. Can you help me?

!CUDA_VISIBLE_DEVICES=0 python prune_distill_step1.py --traindata_path "/kaggle/working/Crop-Fields-LOD-13-14-15-4/train/_annotations.coco.json" --valdata_path "/kaggle/working/Crop-Fields-LOD-13-14-15-4/valid/_annotations.coco.json" --trainsize 480 --valsize 126 --prune_ratio 0.3 --epochs 20

===========================Parameter Settings=========================== Pruning Ratio: 0.3 VIT num_heads: 12 norm_type: mean imptype: Disturb global: False learning rate: 0.0001 a_weight: 0.5 round_to 12 TRAIN_SIZE 480 VAL_SIZE 126 GRAD_SIZE 1000 Epochs 20 Traceback (most recent call last): File "/kaggle/working/SlimSAM/prune_distill_step1.py", line 295, in train_model() File "/kaggle/working/SlimSAM/prune_distill_step1.py", line 118, in train_model batch = next(grad_iter) File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 634, in next data = self._next_data() File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1346, in _next_data return self._process_data(data) File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1372, in _process_data data.reraise() File "/opt/conda/lib/python3.10/site-packages/torch/_utils.py", line 644, in reraise raise exception IndexError: Caught IndexError in DataLoader worker process 0. Original Traceback (most recent call last): File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop data = fetcher.fetch(index) File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/opt/conda/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/kaggle/working/SlimSAM/load_sam_json.py", line 39, in getitem image = cv2.imread(self._image_paths[index]) IndexError: list index out of range

https://universe.roboflow.com/cropfields/crop-fields-lod-13-14-15/dataset/4

czg1225 commented 9 months ago

Hello @BuKeMod , Consider verifying if you have altered the '--gradsize' parameter. The default setting for 'gradsize' is 1000. It's important to ensure that the 'gradsize' value is less than the 'trainsize'. Thanks.

BuKeMod commented 9 months ago

I've encountered a new issue. Do you have any examples of training, such as using Colab or Kaggle? I'm a beginner and don't quite understand yet. Thank you.

CUDA visible devices: 1 CUDA Device Name: Tesla P100-PCIE-16GB ===========================Parameter Settings=========================== Pruning Ratio: 0.3 VIT num_heads: 12 norm_type: mean imptype: Disturb global: False learning rate: 0.0001 a_weight: 0.5 round_to 12 TRAIN_SIZE 40 VAL_SIZE 12 GRAD_SIZE 0 Epochs 5 ===========================Pruning Start=========================== /kaggle/working/SlimSAM/torch_pruning/dependency.py:639: UserWarning: Unwrapped parameters detected: ['pos_embed', 'neck.3.bias', 'neck.3.weight', 'neck.1.bias', 'neck.1.weight']. Torch-Pruning will prune the last non-singleton dimension of a parameter. If you wish to customize this behavior, please provide an unwrapped_parameters argument. warnings.warn(warning_str) Traceback (most recent call last): File "/kaggle/working/SlimSAM/prune_distill_step1.py", line 295, in train_model() File "/kaggle/working/SlimSAM/prune_distill_step1.py", line 136, in train_model model.image_encoder = prune_sam_step1(model=model.image_encoder, example_inputs=example_inputs, model_name=model_name, round_to=round_to, ratio=ratio, imptype = imptype, norm_type=norm_type, global_way=global_way) File "/kaggle/working/SlimSAM/prune_funcs.py", line 140, in prune_sam_step1 pruner.step() File "/kaggle/working/SlimSAM/torch_pruning/pruner/algorithms/metapruner.py", line 162, in step for group in pruning_fn(): File "/kaggle/working/SlimSAM/torch_pruning/pruner/algorithms/metapruner.py", line 212, in prune_local imp = self.estimate_importance(group, ch_groups=ch_groups) File "/kaggle/working/SlimSAM/torch_pruning/pruner/algorithms/metapruner.py", line 166, in estimate_importance return self.importance(group, ch_groups=ch_groups) File "/kaggle/working/SlimSAM/torch_pruning/pruner/importance.py", line 426, in call dw = layer.weight.grad.data[idxs].flatten(1) AttributeError: 'NoneType' object has no attribute 'data'

czg1225 commented 9 months ago

Please ensure that the 'gradsize' parameter is set to a value greater than 0. The importance estimation algorithm relies on gradient information for each parameter, making it essential that 'gradsize' is not zero. Note that while 'gradsize' should be less than 'trainsize', a larger 'gradsize' can be more effective for pruning purposes. Thanks!