Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python NumpyBackend';对象没有属性';塔克';_Python - Fatal编程技术网

Python NumpyBackend';对象没有属性';塔克';

Python NumpyBackend';对象没有属性';塔克';,python,Python,我有一些使用svd进行图像压缩的代码,还有一些用于实验的代码 所以我有以下实验代码: plt.figure(figsize=(20,12)) for i,rank in enumerate([2,10,20]): plt.subplot(2,3,i+1) plt.imshow(svd_compression(image1,rank)) plt.title("rank:%i - compression: %.2f%%" %(rank,svd_compress_ratio(i

我有一些使用svd进行图像压缩的代码,还有一些用于实验的代码

所以我有以下实验代码:

plt.figure(figsize=(20,12))
for i,rank in enumerate([2,10,20]):
    plt.subplot(2,3,i+1)
    plt.imshow(svd_compression(image1,rank))
    plt.title("rank:%i - compression: %.2f%%" %(rank,svd_compress_ratio(image1,rank)*100))
for i,rank in enumerate([2,10,20]):
    plt.subplot(2,3,i+4)
    plt.imshow(svd_compression(image2,rank))
    plt.title("rank:%i - compression: %.2f%%" %(rank,svd_compress_ratio(image2,rank)*100))

plt.show()
但我犯了以下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorly/backend/__init__.py in _get_backend_method(key)
     91     try:
---> 92         return getattr(_LOCAL_STATE.backend, key)
     93     except AttributeError:

AttributeError: 'NumpyBackend' object has no attribute 'tucker'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
3 frames
/usr/local/lib/python3.6/dist-packages/tensorly/backend/__init__.py in _get_backend_method(key)
     92         return getattr(_LOCAL_STATE.backend, key)
     93     except AttributeError:
---> 94         return getattr(_LOADED_BACKENDS[_DEFAULT_BACKEND], key)
     95 
     96 def _get_backend_dir():

AttributeError: 'NumpyBackend' object has no attribute 'tucker'
压缩方法如下:

!pip install tensorly
import numpy as np
import pylab as plt
import scipy.sparse.linalg 
import PIL.Image
import tensorly as tl
import matplotlib.pyplot as plt2
from scipy.sparse.linalg import svds

def svd_compression(image, rank):


    unfolded = tl.unfold(image, mode=0)
    u, s, vt = svds(unfolded, rank)
    return tl.fold(np.round(np.dot(u*s,vt),1), 0, image.shape) # need to round to have a color lvl