1

マニホールド学習法を使用して、次元を縮小して RGB 画像をグレーにしようとしています。

画像を numpy 配列 (image_array) に変換しました

import numpy as np
from sklearn.datasets import load_sample_image
china = load_sample_image("china.jpg")

# Convert to floats instead of the default 8 bits integer coding. Dividing by
# 255 is important so that plt.imshow behaves works well on float data (need to
# be in the range [0-1]

china = np.arraychina, dtype=np.float64) / 255

# Load Image and transform to a 2D numpy array.

w, h, d = original_shape = tuple(china.shape)
assert d == 3
image_array = np.reshape(china, (w * h, d))

image_array を調べる

image_array.shape

(273280、3)

しようとすると、

X, color = image_array

私は得る

ValueError: アンパックする値が多すぎます。

これを回避する方法はありますか?

4

1 に答える 1

0

できるよ

china = (china[:,:,:3] * [0.2989, 0.5870, 0.1140]).sum(axis=2)

これは、私が diy の機械学習で行ったことです (純粋な numpy は、scikit を使用するよりも大幅に高速であることがわかりました。これには、勾配の方向付けられたヒストグラムのバージョンが含まれています https://github.com/paddywwoof/Machine-Learning/blob/master/image_processorを参照してください)。 .py )

于 2016-04-28T21:20:06.737 に答える