NumpyBackend' object has no attribute 'tucker' - python

I have some codes for doing image compression using svd and some more codes for experiments.
So I have the following code for experiment:
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()
But I got the following errors:
---------------------------------------------------------------------------
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'
The method for compression is here:
!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

Related

Trouble Importing KMeans from Sklearn

I Have an error message when importing KMeans but I am able to import pandas and matplotlib.pyplot
Error Message is as follows:
TypeError Traceback (most recent call last)
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/getlimits.py:649, in iinfo.__init__(self, int_type)
648 try:
--> 649 self.dtype = numeric.dtype(int_type)
650 except TypeError:
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/Users/Downloads/Unclassified Learning/Unclassified Learning.ipynb Cell 27 in <cell line: 1>()
----> 1 from sklearn.cluster.KMeans import KMeans
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sklearn/__init__.py:82, in <module>
80 from . import _distributor_init # noqa: F401
81 from . import __check_build # noqa: F401
---> 82 from .base import clone
83 from .utils._show_versions import show_versions
85 __all__ = [
86 "calibration",
87 "cluster",
(...)
128 "show_versions",
...
--> 651 self.dtype = numeric.dtype(type(int_type))
652 self.kind = self.dtype.kind
653 self.bits = self.dtype.itemsize * 8
TypeError: 'NoneType' object is not callable
I tried different variations of the code to import KMeans but still get the same error, would love to understand what is causing this. I have tried pip install -U scikit-learn and then the import but has this error instead:
TypeError Traceback (most recent call last)
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/getlimits.py:649, in iinfo.__init__(self, int_type)
648 try:
--> 649 self.dtype = numeric.dtype(int_type)
650 except TypeError:
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/Users/Downloads/Unclassified Learning/Unclassified Learning.ipynb Cell 27 in <cell line: 2>()
1 get_ipython().system('pip install -U scikit-learn')
----> 2 from sklearn.cluster import KMeans
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sklearn/__init__.py:82, in <module>
80 from . import _distributor_init # noqa: F401
81 from . import __check_build # noqa: F401
---> 82 from .base import clone
83 from .utils._show_versions import show_versions
85 __all__ = [
86 "calibration",
87 "cluster",
(...)
...
--> 651 self.dtype = numeric.dtype(type(int_type))
652 self.kind = self.dtype.kind
653 self.bits = self.dtype.itemsize * 8
TypeError: 'NoneType' object is not callable
I have done this for other libraries and no issue so I am very lost, would appreciate any help!

What should I do with this error in python when importing Paraview?

I finished the installation of Paraview by conda, but I got an attribute error when importing paraview.simple in jupyter notebook:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-56-51050ddfbc7e> in <module>
----> 1 import paraview.simple
~\Anaconda3\lib\site-packages\paraview\simple.py in <module>
39
40 import paraview
---> 41 from paraview import servermanager
42 import paraview._backwardscompatibilityhelper
43
~\Anaconda3\lib\site-packages\paraview\servermanager.py in <module>
3372 SetActiveConnection(activeConnection)
3373
-> 3374 __initialize()
3375
3376 if hasattr(sys, "ps1"):
~\Anaconda3\lib\site-packages\paraview\servermanager.py in __initialize()
3354 # Monitor connection creations/deletions on the ProcessModule.
3355 pm = vtkProcessModule.GetProcessModule()
-> 3356 pm.AddObserver("ConnectionCreatedEvent", __connectionCreatedCallback)
3357 pm.AddObserver("ConnectionClosedEvent", __connectionClosedCallback)
3358
AttributeError: 'paraview.modules.vtkRemotingCore.vtkProcessModule' object has no attribute 'AddObserver'
What should I do to fix it?

AttributeError: module 'tensorflow._api.v1.config' has no attribute 'run_functions_eagerly'

Trying to run ImageAI in Jupyter.
I'm getting the following error
Using TensorFlow backend.
AttributeError Traceback (most recent call last)
in
----> 1 from imageai.Detection.Custom import DetectionModelTrainer
~\anaconda3\envs\ImageAI\lib\site-packages\imageai\Detection\Custom_init_.py in
19 import cv2
20
---> 21 tf.config.run_functions_eagerly(True)
22 os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
23
~\anaconda3\envs\ImageAI\lib\site-packages\tensorflow_core\python\util\module_wrapper.py in getattr(self, name)
191 def getattr(self, name):
192 try:
--> 193 attr = getattr(self._tfmw_wrapped_module, name)
194 except AttributeError:
195 if not self._tfmw_public_apis:
AttributeError: module 'tensorflow._api.v1.config' has no attribute 'run_functions_eagerly
What is the issue here?
Thanks in advance
You can try like this:
import tensorflow.compat.v1 as tf
tf.config.experimental_run_functions_eagerly(True)
#tf.function
def fn():
# `enter code here

Cannot get a SIMPLE HISTOGRAM to plot in Python 3.7 Notebook

Below is the error code I received as I am trying to do a Histogram from the DF "code" and the column ("Age")
code['Age'].plt.hist()
1
code['Age'].plt.hist()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-44-2117f9d17105> in <module>
----> 1 code['Age'].plt.hist()
~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
5177 if self._info_axis._can_hold_identifiers_and_holds_name(name):
5178 return self[name]
-> 5179 return object.__getattribute__(self, name)
5180
5181 def __setattr__(self, name, value):
AttributeError: 'Series' object has no attribute 'plt'
Use the hist function directly from matplotlib:
import matplotlib.pyplot as plt
plt.hist(code['Age'])
plt.show()
This should work. You can also do:
import matplotlib.pyplot as plt
code['Age'].hist()
plt.show()

Theano step gives File in wrong format error

I am trying to replicate the example
Getting Started PyMC3.
on Windows 2012 R2.
The step
from pymc3 import Model, Normal, HalfNormal
gives
D:\Anaconda3\libs/python35.lib: error adding symbols: File in wrong format
collect2.exe: error: ld returned 1 exit status
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
D:\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
64 if version != getattr(lazylinker_ext, '_version', None):
---> 65 raise ImportError()
66 except ImportError:
ImportError:
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
D:\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
81 if version != getattr(lazylinker_ext, '_version', None):
---> 82 raise ImportError()
83 except ImportError:
ImportError:
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
<ipython-input-4-582c90a634a6> in <module>()
----> 1 from pymc3 import Model, Normal, HalfNormal
D:\Anaconda3\lib\site-packages\pymc3\__init__.py in <module>()
1 __version__ = "3.0"
2
----> 3 from .core import *
4 from .distributions import *
5 from .math import *
D:\Anaconda3\lib\site-packages\pymc3\core.py in <module>()
1 from .vartypes import *
----> 2 from .model import *
3 from .theanof import *
4 from .blocking import *
5 import numpy as np
D:\Anaconda3\lib\site-packages\pymc3\model.py in <module>()
1 from .vartypes import *
2
----> 3 from theano import theano, tensor as t, function
4 from theano.tensor.var import TensorVariable
5
D:\Anaconda3\lib\site-packages\theano\__init__.py in <module>()
53 object2, utils
54
---> 55 from theano.compile import \
56 SymbolicInput, In, \
57 SymbolicOutput, Out, \
D:\Anaconda3\lib\site-packages\theano\compile\__init__.py in <module>()
7 SpecifyShape, specify_shape, register_specify_shape_c_code)
8
----> 9 from theano.compile.function_module import *
10
11 from theano.compile.mode import *
D:\Anaconda3\lib\site-packages\theano\compile\function_module.py in <module>()
16 from theano import gof
17 from theano.compat.python2x import partial
---> 18 import theano.compile.mode
19 from theano.compile.io import (
20 In, SymbolicInput, SymbolicInputKit, SymbolicOutput)
D:\Anaconda3\lib\site-packages\theano\compile\mode.py in <module>()
9 import theano
10 from theano import gof
---> 11 import theano.gof.vm
12 from theano.configparser import config, AddConfigVar, StrParam
13 from theano.compile.ops import register_view_op_c_code, _output_guard
D:\Anaconda3\lib\site-packages\theano\gof\vm.py in <module>()
566
567 try:
--> 568 from . import lazylinker_c
569
570 class CVM(lazylinker_c.CLazyLinker, VM):
D:\Anaconda3\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
115 args = cmodule.GCC_compiler.compile_args()
116 cmodule.GCC_compiler.compile_str(dirname, code, location=loc,
--> 117 preargs=args)
118 # Save version into the __init__.py file.
119 init_py = os.path.join(loc, '__init__.py')
D:\Anaconda3\lib\site-packages\theano\gof\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module)
2008 # difficult to read.
2009 raise Exception('Compilation failed (return status=%s): %s' %
-> 2010 (status, compile_stderr.replace('\n', '. ')))
2011 elif config.cmodule.compilation_warning and compile_stderr:
2012 # Print errors just below the command line.
I have for gcc
C:\>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=C:/TDM-GCC-64/bin/../libexec/gcc/x86_64-w64-mingw32/5.1.0/lt
o-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-5.1.0/configure --build=x86_64-w64-mingw32 --e
nable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable
-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC -
-disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-libstdcxx-d
ebug --enable-threads=posix --enable-version-specific-runtime-libs --enable-full
y-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-l
d --disable-werror --disable-nls --disable-win32-registry --prefix=/mingw64tdm -
-with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-1 --with-bugurl=http://td
m-gcc.tdragon.net/bugs
Thread model: posix
gcc version 5.1.0 (tdm64-1)
what am i missing?
thanks
Whatever the issue was creating a python 3.4 environment together with
conda install mingw libpython
solved it.
What solved my issue is installing Python 2.7 version of anaconda
I got the same error using ipython. Using just python I imported theano without problem. Subsequent uses with ipython worked fine after the first compilation with just python.

Categories

Resources