Created
September 28, 2017 02:03
-
-
Save SeaOfOcean/b235ad0155e9b232ce059a050e13cfe2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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