Official implementation of the Fake News Revealer paper
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

data_loader.py 1.0KB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132
  1. import cv2
  2. import pickle
  3. from PIL import Image
  4. from numpy import asarray
  5. from data.data_loader import DatasetLoader
  6. class TwitterDatasetLoader(DatasetLoader):
  7. def __getitem__(self, idx):
  8. item = self.set_text(idx)
  9. item.update(self.set_img(idx))
  10. return item
  11. def set_img(self, idx):
  12. try:
  13. if self.mode == 'train':
  14. image = cv2.imread(f"{self.config.train_image_path}/{self.image_filenames[idx]}")
  15. elif self.mode == 'validation':
  16. image = cv2.imread(f"{self.config.validation_image_path}/{self.image_filenames[idx]}")
  17. else:
  18. image = cv2.imread(f"{self.config.test_image_path}/{self.image_filenames[idx]}")
  19. image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  20. except:
  21. image = Image.open(f"{self.config.train_image_path}/{self.image_filenames[idx]}").convert('RGB')
  22. image = asarray(image)
  23. return self.set_image(image)
  24. def __len__(self):
  25. return len(self.text)