Skip to content

Instantly share code, notes, and snippets.

@gyglim
Last active December 7, 2018 13:31
Show Gist options
  • Save gyglim/714cb24a1c34c95e0a0c9a8a4ec0620c to your computer and use it in GitHub Desktop.
Save gyglim/714cb24a1c34c95e0a0c9a8a4ec0620c to your computer and use it in GitHub Desktop.
Example for loading the splits used in "Exploring Compositional High Order Pattern Potentials for Structured Output Learning" from Li et al.
# TODO: Get weizmann_32_32_trainval.mat from https://www.cs.toronto.edu/~yujiali/papers/chopps.zip
# TODO: Get horse.mat from https://www.cs.toronto.edu/~yujiali/papers/cvpr13_data.zip
# TODO: Update the paths below
split_path='YOUR_PATH_TO/weizmann_32_32_trainval.mat'
data_path='YOUR_PATH_TO/horse.mat'
# Imports
import matplotlib.pyplot as plt
import numpy as np
import scipy.io
import json
split_info=scipy.io.loadmat(split_path)
image_data = scipy.io.loadmat(data_path)
def get_data_for_split(data, split_info, split_name):
"""Get the images and masks for a given split."""
splits = {"train": [0, 160], "val": [160, 200], "test": [200, 328]}
split = splits[split_name]
# Substract 1, as the idx uses 1-based indexing.
indices= split_info['idx'][0][split[0]:split[1]] - 1
images = [i[0] for i in data['imgs'][indices]]
masks = [m.reshape(32,32).T for m in data['segs'][indices]]
return images, masks
# Load the data for a given split ('train','val' or 'test')
images, masks = get_data_for_split(image_data, split_info, 'test')
# Show the first image
plt.subplot(1,2,1)
plt.imshow(masks[-1])
plt.grid('off')
plt.subplot(1,2,2)
plt.imshow(images[-1])
plt.grid('off')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment