Closed dguhanus closed 1 year ago
Hi @dguhanus, the code does not handle loading the data for you, it expects a 2-dimensional NumPy array.
One way of doing that would be to use PIL (converting the image to grayscale as well):
import numpy as np
from PIL import Image
img = Image.open('small.jpg').convert('L')
data = np.asarray(img)
nmf = NMF(data, 2)
nmf.factorize(method='mur')
Small disclaimer: this is basically an archive repo and not actively maintained. If you encounter further problems, I am happy to have a look and help as much as I can, but I can not promise extensive support.
Dear Dr. Ralf Engbers , Thank you for your prompt reply and extending your support. After your reply, I am able to execute the MUR and AO-ADMM method. I am encountering a problem when I want to use ADMM. Below is the code that I am following to invoke ADMM.
`import numpy as np from PIL import Image
import matplotlib.pyplot as plt from nmf import NMF
img = Image.open('small.jpg').convert('L') data = np.asarray(img) nmf = NMF(data, 50) nmf.factorize(method='admm', rho=0.2, max_iter=600) nmf.save_factorization('./results/nmf_exp_admm.npz') saved_npimag = np.load('./results/nmf_exp_admm.npz') ` Below is the error that I am encountering due to attribute of rho
`base) dguha@dguha:~/ADMM_Code/nmf$ python admm_sample.py /home/dguha/ADMM_Code/nmf/nmf/admm.py:143: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. k = -np.array([np.ones(n - 1), -2 * np.ones(n), np.ones(n - 1)])
Algorithm converged (2).
WARNING:root:Converged.
Factorization done.
Traceback (most recent call last):
File "admm_sample.py", line 14, in
Hm. I get a different error when trying to reproduce the issue. I might find some time at the end of the week or on the weekend to have a closer look.
@dguhanus Feel free to try again. I pushed two changes (#2 & #3) which hopefully fixes your issues.
Dear Ralf Engbers, Thank you very much for your update. I have tested, it working fine. But I have another doubt for which I am posting a separate query.
Nice, closing this one then. Will checkout the other issue hopefully during this weekend.
Dear Ralf Engbers , Thank you for the NMF code with all the 4 mechanisms. I am trying to run the code. I am unable to pass on the argument for the NMF code. I have attached the error of the console. Below is the python code written inside a file:
data = "small.jpg" components = 20 from nmf import NMF nmf = NMF(data, components) nmf.factorize(method='mur', distance_type='eu', min_iter='60')
Please let me know how to resolve the issue.