Skip to content

Instantly share code, notes, and snippets.

@SeaOfOcean
Created September 28, 2017 02:03
Show Gist options
  • Save SeaOfOcean/b235ad0155e9b232ce059a050e13cfe2 to your computer and use it in GitHub Desktop.
Save SeaOfOcean/b235ad0155e9b232ce059a050e13cfe2 to your computer and use it in GitHub Desktop.
from scipy import misc
# data preprocess
def preprocess(imgRdd):
means = np.array([127.5, 127.5, 127.5]) # mean value in BGR order
sizes = imgRdd.map(lambda img: img.shape)
data = imgRdd.map(lambda original_img: misc.imresize(original_img, (300, 300))) \
.map(lambda resized_img: (resized_img[:, :] - means) * 0.007843) \
.map(lambda normalized_img: normalized_img.transpose(2, 0, 1)) \
.map(lambda normalized_img: Sample.from_ndarray(normalized_img, np.array([-1])))
return (data, sizes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment