Skip to content

Instantly share code, notes, and snippets.

@adash333
Last active August 4, 2017 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adash333/15d9b33eef7a00f993bbc32a168f6ca0 to your computer and use it in GitHub Desktop.
Save adash333/15d9b33eef7a00f993bbc32a168f6ca0 to your computer and use it in GitHub Desktop.
import numpy as np
filepath = "./mikan.jpg"
# 画像を25x25pixelに変換し、1要素が[R,G,B]3要素を含む配列の25x25の2次元配列として読み込む。
# [R,G,B]はそれぞれが0-255の配列。
image = np.array(Image.open(filepath).resize((5, 5)))
print(filepath)
print(image)
# 配列を変換し、[[Redの配列],[Greenの配列],[Blueの配列]] のような形にする。
image = image.transpose(2, 0, 1)
print(image)
# さらにフラットな1次元配列に変換。最初の1/3はRed、次がGreenの、最後がBlueの要素がフラットに並ぶ。
image = image.reshape(1, image.shape[0] * image.shape[1] * image.shape[2]).astype("float32")[0]
print(image)
# 出来上がった配列を正規化?
image = image / 255.
print(image)
# kerasに渡すためにnumpy配列に変換。
image = np.array(image)
print(image)
#途中です。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment