SPAMS
をPython
で使用してDictionary Learning
に取り組んでいます。ここで asfortranarrayでの実行時の警告
import spams
import numpy as np
from PIL import Image
import time
import matplotlib.pyplot as plt
img_file = 'gray-car.jpg'
try:
img = Image.open(img_file)
except:
print("Cannot load image %s : skipping test" %img_file)
I = np.array(img)/255.
print('Shape : ',I.shape)
if I.ndim == 3:
A = np.asfortranarray(I.reshape((I.shape[0],I.shape[1] * I.shape[2])))
rgb = True
else:
A = np.asfortranarray(I)
rgb = False
m = 8;n = 8;
X = spams.im2col_sliding(A,m,n,rgb)
X = X - np.tile(np.mean(X,0),(X.shape[0],1))
X = np.asfortranarray(X/np.tile(np.sqrt((X * X).sum(axis=0)),(X.shape[0],1)),dtype=np.float64)
param = { 'K' : 100, # learns a dictionary with 100 elements
'lambda1' : 0.15, 'numThreads' : 4, 'batchsize' : 400,
'iter' : 1000}
tic = time.time()
D = spams.trainDL(X,**param)
tac = time.time()
t = tac - tic
print('time of computation for Dictionary Learning: %f' %t)
##param['approx'] = 0
# save dictionnary as dict.png
plt.imshow(D)
plt.show()
_objective(X,D,param,'dict')
私は学習=>
noise.py:27: RuntimeWarning: invalid value encountered in true_divide
X = np.asfortranarray(X/np.tile(np.sqrt((X *
X).sum(axis=0)),(X.shape[0],1)),dtype=np.float64)
/usr/local/lib/python3.4/dist-packages/numpy/core/fromnumeric.py:2699:
VisibleDeprecationWarning: `rank` is deprecated; use the `ndim`
attribute or function instead. To find the rank of a matrix see
`numpy.linalg.matrix_rank`. VisibleDeprecationWarning)
私はここで使用している
入力画像=>
中に取得していますエラー
私は除数にゼロ(またはナノ/ inf)があると思います。私はこれが 'np.asfortranarray'とは関係ないと思います。 _実際にコードを確認できるように、サンプル入力をいくつか共有してください。 – MSeifert
@MSeifert私が使用した写真をアップロードしています –
'asfortran'、' X/np.tile(np.sqrt((X * X).sum(axis = 0)) 'の中の式について教えてください' 。形状、dtype、実行するかどうかなど – hpaulj