Skip to content
New issue

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

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

Already on GitHub? # to your account

Implementation about BaseDataSource member funcion 'get_img' #431

Closed
pUmpKin-Co opened this issue Aug 18, 2022 · 1 comment
Closed

Implementation about BaseDataSource member funcion 'get_img' #431

pUmpKin-Co opened this issue Aug 18, 2022 · 1 comment

Comments

@pUmpKin-Co
Copy link

Describe the feature

Motivation
I think there is some redundancy in the get_img member function of the BaseDataSource.
Related resources
In mmselfsup/datasets/data_sources/base.py. The get_img function of class BaseDataSource:

def get_img(self, idx):
  if self.file_client is None:
      self.file_client = mmcv.FileClient(**self.file_client_args)

  if 'ImageNet-21k' in self.data_prefix:
      filename = osp.join(self.data_prefix,
                          self.data_infos[idx].decode('utf-8'))
      img_bytes = self.file_client.get(filename)
      img = mmcv.imfrombytes(
          img_bytes,
          flag=self.color_type,
          channel_order=self.channel_order)
  elif self.data_infos[idx].get('img_prefix', None) is not None:
      if self.data_infos[idx]['img_prefix'] is not None:
          filename = osp.join(
              self.data_infos[idx]['img_prefix'],
              self.data_infos[idx]['img_info']['filename'])
      else:
          filename = self.data_infos[idx]['img_info']['filename']
      img_bytes = self.file_client.get(filename)
      img = mmcv.imfrombytes(
          img_bytes,
          flag=self.color_type,
          channel_order=self.channel_order)
  else:
      img = self.data_infos[idx]['img']

  img_bytes = self.file_client.get(filename)
  img = mmcv.imfrombytes(
      img_bytes, flag=self.color_type, channel_order=self.channel_order)
  img = img.astype(np.uint8)
  return Image.fromarray(img)
  1. The filename variable may be not set on the if-else logic. So This may cause error in processing img_bytes = self.file_client.get(filename)
  2. The img_bytes and img set twice when if-elif logic occur.

Additional context
I'm trying to implement a custom dataset without annotated data, and when I read the source code I had some questions here. If there is another reason for this design, please let me know.
Many thanks!

@fangyixiao18
Copy link
Collaborator

fangyixiao18 commented Aug 19, 2022

Thanks for your issue.
We have already fix this redundancy, #386

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

No branches or pull requests

2 participants