You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched related issues but cannot get the expected help.
I have read related documents and don't know what to do.
Describe the question you meet
I modified the configuration of MGD in the mmrazor demo, using YOLOv5_X from mmYOLO as the teacher model and YOLOv5_S as the student model for knowledge distillation. However, during training, the student model's mAP remained at 0 and did not improve even after training up to the 12th epoch.
Post related information
The output of pip list | grep "mmcv\|mmrazor\|^torch"
Other code you modified in the mmrazor folder.
Used in custom_imports module/dataset/yolov5/coco_dataloader.py
# Copyright (c) OpenMMLab. All rights reserved.fromtypingimportAny, Optionalfrommmdet.datasetsimportBaseDetDataset, CocoDatasetfromtypingimportList, Sequenceimportnumpyasnpimporttorchfrommmengine.datasetimportCOLLATE_FUNCTIONSfrommmengine.distimportget_dist_info@COLLATE_FUNCTIONS.register_module()defyolov5_collate_local(data_batch: Sequence,
use_ms_training: bool=False) ->dict:
"""Rewrite collate_fn to get faster training speed. Args: data_batch (Sequence): Batch of data. use_ms_training (bool): Whether to use multi-scale training. """batch_imgs= []
batch_bboxes_labels= []
batch_masks= []
batch_keyponits= []
batch_keypoints_visible= []
foriinrange(len(data_batch)):
datasamples=data_batch[i]['data_samples']
inputs=data_batch[i]['inputs']
batch_imgs.append(inputs)
gt_bboxes=datasamples.gt_instances.bboxes.tensorgt_labels=datasamples.gt_instances.labelsif'masks'indatasamples.gt_instances:
masks=datasamples.gt_instances.masksbatch_masks.append(masks)
if'gt_panoptic_seg'indatasamples:
batch_masks.append(datasamples.gt_panoptic_seg.pan_seg)
if'keypoints'indatasamples.gt_instances:
keypoints=datasamples.gt_instances.keypointskeypoints_visible=datasamples.gt_instances.keypoints_visiblebatch_keyponits.append(keypoints)
batch_keypoints_visible.append(keypoints_visible)
batch_idx=gt_labels.new_full((len(gt_labels), 1), i)
bboxes_labels=torch.cat((batch_idx, gt_labels[:, None], gt_bboxes),
dim=1)
batch_bboxes_labels.append(bboxes_labels)
collated_results= {
'data_samples': {
'bboxes_labels': torch.cat(batch_bboxes_labels, 0)
}
}
iflen(batch_masks) >0:
collated_results['data_samples']['masks'] =torch.cat(batch_masks, 0)
iflen(batch_keyponits) >0:
collated_results['data_samples']['keypoints'] =torch.cat(
batch_keyponits, 0)
collated_results['data_samples']['keypoints_visible'] =torch.cat(
batch_keypoints_visible, 0)
ifuse_ms_training:
collated_results['inputs'] =batch_imgselse:
collated_results['inputs'] =torch.stack(batch_imgs, 0)
returncollated_results@TASK_UTILS.register_module()classBatchShapePolicy:
"""BatchShapePolicy is only used in the testing phase, which can reduce the number of pad pixels during batch inference. Args: batch_size (int): Single GPU batch size during batch inference. Defaults to 32. img_size (int): Expected output image size. Defaults to 640. size_divisor (int): The minimum size that is divisible by size_divisor. Defaults to 32. extra_pad_ratio (float): Extra pad ratio. Defaults to 0.5. """def__init__(self,
batch_size: int=32,
img_size: int=640,
size_divisor: int=32,
extra_pad_ratio: float=0.5):
self.img_size=img_sizeself.size_divisor=size_divisorself.extra_pad_ratio=extra_pad_ratio_, world_size=get_dist_info()
# During multi-gpu testing, the batchsize should be multiplied by# worldsize, so that the number of batches can be calculated correctly.# The index of batches will affect the calculation of batch shape.self.batch_size=batch_size*world_sizedef__call__(self, data_list: List[dict]) ->List[dict]:
image_shapes= []
fordata_infoindata_list:
image_shapes.append((data_info['width'], data_info['height']))
image_shapes=np.array(image_shapes, dtype=np.float64)
n=len(image_shapes) # number of imagesbatch_index=np.floor(np.arange(n) /self.batch_size).astype(
np.int64) # batch indexnumber_of_batches=batch_index[-1] +1# number of batchesaspect_ratio=image_shapes[:, 1] /image_shapes[:, 0] # aspect ratioirect=aspect_ratio.argsort()
data_list= [data_list[i] foriinirect]
aspect_ratio=aspect_ratio[irect]
# Set training image shapesshapes= [[1, 1]] *number_of_batchesforiinrange(number_of_batches):
aspect_ratio_index=aspect_ratio[batch_index==i]
min_index, max_index=aspect_ratio_index.min(
), aspect_ratio_index.max()
ifmax_index<1:
shapes[i] = [max_index, 1]
elifmin_index>1:
shapes[i] = [1, 1/min_index]
batch_shapes=np.ceil(
np.array(shapes) *self.img_size/self.size_divisor+self.extra_pad_ratio).astype(np.int64) *self.size_divisorfori, data_infoinenumerate(data_list):
data_info['batch_shape'] =batch_shapes[batch_index[i]]
returndata_list
The text was updated successfully, but these errors were encountered:
Checklist
Describe the question you meet
I modified the configuration of MGD in the mmrazor demo, using YOLOv5_X from mmYOLO as the teacher model and YOLOv5_S as the student model for knowledge distillation. However, during training, the student model's mAP remained at 0 and did not improve even after training up to the 12th epoch.
Post related information
pip list | grep "mmcv\|mmrazor\|^torch"
mmrazor
folder.Used in custom_imports
module/dataset/yolov5/coco_dataloader.py
The text was updated successfully, but these errors were encountered: