pythonで1枚の画像から、部分画像を切り出してきてミニバッチを生成するプログラムで
256x256画像から、20パターンの回転、3ピクセルごとのスライディングウィンドウで32x32を切り出し、並べてミニバッチを作成します。
プログラムは下記の様に作成し機能は満たしていますが、非常に時間がかかるため、
高速化したいです。どのようにコーディングすれば良いでしょうか。
def genImageInputs(image, stride=5, size=32, num_rot=20): width = image.shape[1] height = image.shape[0] hsize = size//2 stack = np.copy(image).reshape(1, width, height) output = None for r in range(1, num_rot): rot = r * 180 / num_rot pil_img = Image.fromarray(image) pil_img = pil_img.rotate(rot) stack = np.concatenate([stack, np.asarray(pil_img).reshape(1, width, height)], 0) #print(stack.shape) for i in np.arange(hsize, width-hsize, stride): for j in np.arange(hsize, height-hsize, stride): sub = stack[:, j-hsize:j+hsize, i-hsize:i+hsize] if output is None: output = sub else: output = np.concatenate([output, sub], 0) return output

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。