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
12345678910111213141516171819202122232425262728293031323334
  1. import pickle
  2. import cv2
  3. from PIL import Image
  4. from numpy import asarray
  5. from data.data_loader import DatasetLoader
  6. class WeiboDatasetLoader(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. if self.labels[idx] == 1:
  13. try:
  14. image = cv2.imread(f"{self.config.rumor_image_path}/{self.image_filenames[idx]}")
  15. except:
  16. image = Image.open(f"{self.config.rumor_image_path}/{self.image_filenames[idx]}").convert('RGB')
  17. image = asarray(image)
  18. else:
  19. try:
  20. image = cv2.imread(f"{self.config.nonrumor_image_path}/{self.image_filenames[idx]}")
  21. except:
  22. image = Image.open(f"{self.config.nonrumor_image_path}/{self.image_filenames[idx]}").convert('RGB')
  23. image = asarray(image)
  24. return self.set_image(image)
  25. def __len__(self):
  26. return len(self.text)