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

Seek for help when I revised my dataloader file #13

Closed
GewelsJI opened this issue Sep 25, 2019 · 4 comments
Closed

Seek for help when I revised my dataloader file #13

GewelsJI opened this issue Sep 25, 2019 · 4 comments

Comments

@GewelsJI
Copy link

  • I have two class in my task. And I have revised your code suggested by this link

  • PROBLEM: After I train the network with my own database and run inference.py. I got the prediction map with all black pixels.

  • CHECK: In this line, I print the variable prediction.sum() and get the big negative number (e.g., prediction=-15624.34)

  • How can I solve this issue? please help me. Thanks

This is my dataloader file with python:

from base import BaseDataSet, BaseDataLoader
from utils import palette
import numpy as np
import os
import torch
import cv2
from PIL import Image
from glob import glob
from torch.utils.data import Dataset
from torchvision import transforms


class COD10KDataset(BaseDataSet):

    def __init__(self, **kwargs):
        self.num_classes = 2
        self.palette = palette.COD10K_palette
        super(COD10KDataset, self).__init__(**kwargs)

    def _set_files(self):
        if self.split in ["training", "validation"]:
            # self.image_dir = os.path.join(self.root, 'images', self.split)
            # self.label_dir = os.path.join(self.root, 'annotations', self.split)
            self.image_dir = os.path.join(self.root, 'images')
            self.label_dir = os.path.join(self.root, 'annotations')
            self.files = [os.path.basename(path).split('.')[0] for path in glob(self.image_dir + '/*.jpg')]
            print(len(self.files))
        else:
            raise ValueError(f"Invalid split name {self.split}")

    def _load_data(self, index):
        image_id = self.files[index]
        image_path = os.path.join(self.image_dir, image_id + '.jpg')
        label_path = os.path.join(self.label_dir, image_id + '.png')
        image = np.asarray(Image.open(image_path).convert('RGB'), dtype=np.float32)
        label = np.asarray(Image.open(label_path), dtype=np.int32)
        return image, label, image_id


class COD10K(BaseDataLoader):
    def __init__(self, data_dir, batch_size, split, crop_size=None, base_size=None, scale=True, num_workers=1, val=False,
                    shuffle=False, flip=False, rotate=False, blur= False, augment=False, val_split= None, return_id=False):

        self.MEAN = [0.48897059, 0.46548275, 0.4294]
        self.STD = [0.22861765, 0.22948039, 0.24054667]

        kwargs = {
            'root': data_dir,
            'split': split,
            'mean': self.MEAN,
            'std': self.STD,
            'augment': augment,
            'crop_size': crop_size,
            'base_size': base_size,
            'scale': scale,
            'flip': flip,
            'blur': blur,
            'rotate': rotate,
            'return_id': return_id,
            'val': val
        }

        self.dataset = COD10KDataset(**kwargs)
        super(COD10K, self).__init__(self.dataset, batch_size, shuffle, num_workers, val_split)
@yassouali
Copy link
Owner

Hi, your dataloader seem correct, just for the palette, I see you're using COD10K_palette, I suppose you added it with the correct colors (if not you can just call get_voc_palette() with two classes).

When training your model, monitor the training process by launching tensorboard, this way in the tab images, you can see the input images, the ground truths and the predictions, if your see black ground truths then there is a problem when loading the labels, also keep an eye on the mIoU of each class. Any how, I think you already have the tensorboard checkpoints in saved/ if you didn't change the config, you can just run tensorboard and inspect things.

@GewelsJI
Copy link
Author

GewelsJI commented Sep 28, 2019

Sorry for my late reply firstly
I am new in tensorboardX, so how can i achieve this procedure to monitor my input image?
@yassouali

@yassouali
Copy link
Owner

simply run in the main path: tensorboard --logdir saved/, then open the link you'll be provided with

@littleChurchill
Copy link

my input images, the ground truths and the predictions is correct in tensorboard, but why do I get the prediction map with all black pixels when I run inference.py
@yassouali

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants