Check out my YouTube Video on MNIST attention maps
MNIST-M is created by blending digits from the original set (MNIST) over patches that are randomly extracted from color photos in BSDS500 (Arbelaez et al., 2011). MNIST-M is usually used as a target dataset in domain adaptation tasks (Ganin et al., 2016).
The file MNIST-M.zip
contains images from MNIST-M dataset organized into subfolders, where each folder represents a class. This setup makes it ready to be imported using torchvision.datasets.ImageFolder
.
You might have donwloaded MNIST-M, where images are not organized into subfolders. In this case, this code fragment could be useful. Run it twice, one for mnist_m_train_labels.txt
and another run for mnist_m_test_labels.txt
import os
import shutil
import pandas as pd
df = pd.read_csv('mnist_m_train_labels.txt', sep=" ", header=None)
df.columns = ["file name", "subfolder"]
cwd = os.getcwd().replace('\\', '/')
for index, row in df.iterrows():
print(row['file name'], row['subfolder'])
shutil.move(os.path.join(cwd+'/',row['file name']),
os.path.join(cwd+'/', str(row['subfolder'])))