logo_dataset.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from __future__ import print_function
  15. import io
  16. import tarfile
  17. import numpy as np
  18. from PIL import Image #all use default backend
  19. import paddle
  20. from paddle.io import Dataset
  21. import pickle
  22. import os
  23. import cv2
  24. import random
  25. from .common_dataset import CommonDataset
  26. class LogoDataset(CommonDataset):
  27. def _load_anno(self):
  28. assert os.path.exists(self._cls_path)
  29. assert os.path.exists(self._img_root)
  30. self.images = []
  31. self.labels = []
  32. with open(self._cls_path) as fd:
  33. lines = fd.readlines()
  34. for l in lines:
  35. l = l.strip().split("\t")
  36. if l[0] == 'image_id':
  37. continue
  38. self.images.append(os.path.join(self._img_root, l[3]))
  39. self.labels.append(np.int64(l[1]) - 1)
  40. assert os.path.exists(self.images[-1])