Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use 5 channel image in detectron2 deep learning? #5041

Open
martiInfa opened this issue Jul 25, 2023 · 0 comments
Open

Is it possible to use 5 channel image in detectron2 deep learning? #5041

martiInfa opened this issue Jul 25, 2023 · 0 comments
Labels
documentation Problems about existing documentation or comments

Comments

@martiInfa
Copy link

To run detectron2 for imaging with 5 channels I followed #2062 . I have implement a custom dataloader and changed PIXEL_MEAN/STD but I have this error:
FloatingPointError: Loss became infinite or NaN at iteration=4!
loss_dict = {'loss_cls': 0.5807800889015198, 'loss_box_reg': 0.0, 'loss_mask': 0.0, 'loss_rpn_cls': 6.5862717628479, 'loss_rpn_loc': inf}

This is the implementation of class Trainer(DefaultTrainer)
def custom_mappe(dataset_dict):
dataset_dict = copy.deepcopy(dataset_dict) # it will be modified by code below
# can use other ways to read image
image=read_tiff_with_5_bands(dataset_dict["file_name"])
#image = utils.read_image(dataset_dict["file_name"], format="BGR")
# See "Data Augmentation" tutorial for details usage

#auginput = T.AugInput(image)
#transform = T.Resize((650, 650))(auginput)
#image = torch.from_numpy(auginput.image.transpose(2, 0, 1))
'''
annos = [
    utils.transform_instance_annotations(annotation, [transform], image.shape[1:])
    for annotation in dataset_dict.pop("annotations")
]
'''
annos=[]
for annotation in dataset_dict.pop("annotations"):
    annos+=[annotation]

image = torch.from_numpy(image.transpose(2, 0, 1))
return {
   # create the format that the model expects
    
   "image": image,
   "instances":utils.annotations_to_instances(annos, image.shape[1:]),
    #"istances":dataset_dict['annotations'],
    "width":dataset_dict['width'],
    "height":dataset_dict['height']
}

class Trainer(DefaultTrainer):
@classmethod
def build_train_loader(cls, cfg):
return build_detection_train_loader(cfg, mapper=custom_mappe)

@martiInfa martiInfa added the documentation Problems about existing documentation or comments label Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Problems about existing documentation or comments
Projects
None yet
Development

No branches or pull requests

1 participant