PACS数据集
Paper:Self-supervised Domain Adaptation for Computer Vision Tasks
GitHub:https://github.com/robertofranceschi/Domain-adaptation-on-PACS-dataset
数据集下载:https://github.com/MachineLearning2020/Homework3-PACS/tree/master/PACS
- PACS数据集总共9991张图片,每张图片3x227x227
- 7 classes:Dog, Elephant, Giraffe, Guitar, Horse, House, Person
- 4 domains: Art painting, Cartoon, Photo and Sketch.
- Photo (1,670 images), Art Painting (2,048 images), Cartoon (2,344 images) and Sketch (3,929 images)
用Pytorch加载PACS数据集
详见:https://github.com/ValerioDiEugenio/DomainAdaptation-PACSDataset/blob/main/DomainAdaptation.ipynb
class Pacs(VisionDataset):
def __init__(self, root, split='', transform=None, target_transform=None):
self.split = split
self.root = os.path.join(root,self.split)
self.transform = transform
self.dataset= []
self.dataset = ImageFolder(self.root, transform=transform, loader=pil_loader)
print(self.dataset[2])
print(len(self.dataset))
def __getitem__(self, index):
return self.dataset[index]
def __len__(self):
return len(self.dataset)
最后以dog类别为例,用Python代码展示四种不同风格的图片
Python可视化图片数据集的代码
修改dir_path为对应的文件夹,dir_path = f"{DATA_PATH}/PACS/art_painting/dog"
import os
import matplotlib.pyplot as plt
import random
from PIL import Image
def plotPics(data, h=3, w=3, filename="out.jpg"):
fig, ax_array = plt.subplots(h, w, figsize=(15, 15))
axes = ax_array.flatten()
for i, ax in enumerate(axes):
ri = random.randint(0, len(data) - 1)
ax.imshow(data[ri], cmap=plt.cm.gray)
plt.setp(axes, xticks=[], yticks=[], frame_on=False)
fig.tight_layout()
fig.savefig(filename)
plt.show()
DATA_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data/raw_data"))
dir_path = f"{DATA_PATH}/PACS/art_painting/dog"
data = []
for pic in os.listdir(dir_path):
data.append(Image.open(f"{dir_path}/{pic}"))
plotPics(data, h=5, w=5)
art_painting风格
sketch风格
cartoon风格
photo风格
|