0

I´m new with Nmf with python . I´m trying to create a list of images to then get the components. Here is the code:

from skimage import color
from skimage import io
import matplotlib.pyplot as plt

f=color.rgb2gray(io.imread('f.jpg'))
e=color.rgb2gray(io.imread('e.jpg'))


images2= (e,f)

from sklearn.decomposition import NMF
model=NMF(n_components=2)
features=model.fit_transform(images2)

And then the next error appears:

Found array with dim 3. Estimator expected <= 2.
desertnaut
  • 57,590
  • 26
  • 140
  • 166
DAVID LOBO
  • 11
  • 1

1 Answers1

2

According to the documentation. The design matrix (argument of NMF.fit) needs to be of size (n_samples,n_features). Which means that you need to flatten your images.

Try:

from skimage import color
from skimage import io
import matplotlib.pyplot as plt

f=color.rgb2gray(io.imread('f.jpg'))
e=color.rgb2gray(io.imread('e.jpg'))


images2= (e,f)

#flattening
images2 = np.array(images2).reshape(2,-1)

from sklearn.decomposition import NMF
model=NMF(n_components=2)
features=model.fit_transform(images2)
Learning is a mess
  • 7,479
  • 7
  • 35
  • 71