AttributeError: module 'tensorflow.data' has no attribute 'experimental' - python

I am trying to run the image segmentation tutorial from tensorflow.
i am getting this error in the line
from tensorflow_examples.models.pix2pix import pix2pix
The comeplete error is following
AttributeError Traceback (most recent call last)
<ipython-input-3-bfebd9cf4be1> in <module>()
----> 1 from tensorflow_examples.models.pix2pix import pix2pix
2
3 import tensorflow_datasets as tfds
4 tfds.disable_progress_bar()
5
~\Anaconda3\lib\site-packages\tensorflow_examples\models\pix2pix\pix2pix.py in <module>()
37 IMG_WIDTH = 256
38 IMG_HEIGHT = 256
---> 39 AUTOTUNE = tf.data.experimental.AUTOTUNE
40
41
AttributeError: module 'tensorflow.data' has no attribute 'experimental'

Related

PAYG tokens - error messages (on both Disco and Stable Diffusion)

I signed up for some pay as you go credit - and to my dismay now receive this error both on Disco AND Stable Diffusion:
FileNotFoundError Traceback (most recent call last)
<ipython-input-4-191981527364> in <module>
38 import py3d_tools as p3d
39
---> 40 from helpers import DepthModel, sampler_fn
41 from k_diffusion.external import CompVisDenoiser
42 from ldm.util import instantiate_from_config
4 frames
/content/MiDaS/midas/backbones/next_vit.py in <module>
6 from .utils import activations, forward_default, get_activation
7
----> 8 file = open("./externals/Next_ViT/classification/nextvit.py", "r")
9 source_code = file.read().replace(" utils", " externals.Next_ViT.classification.utils")
10 exec(source_code)
FileNotFoundError: [Errno 2] No such file or directory: './externals/Next_ViT/classification/nextvit.py'
I also receive this error on Stable:
NameError Traceback (most recent call last)
<ipython-input-5-d64464a7a6a5> in <module>
154 if load_on_run_all and ckpt_valid:
155 local_config = OmegaConf.load(f"{ckpt_config_path}")
--> 156 model = load_model_from_config(local_config, f"{ckpt_path}", half_precision=half_precision)
157 device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
158 model = model.to(device)
<ipython-input-5-d64464a7a6a5> in load_model_from_config(config, ckpt, verbose, device, half_precision)
136 print(f"Global Step: {pl_sd['global_step']}")
137 sd = pl_sd["state_dict"]
--> 138 model = instantiate_from_config(config.model)
139 m, u = model.load_state_dict(sd, strict=False)
140 if len(m) > 0 and verbose:
Despite clearing my Google Drive and reloading Disco and Stable Diffusion, (including the .ckpt file, placed correctly as before in the models folder) the same errors occur.

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!

UPDATED - Further complications - ImportError: `load_weights` requires h5py

I'm working with a previously saved model, however, when I try to load the model, I receive the following error message:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-11-f8d353bad309> in <module>
----> 1 estimator, corpus_encoder, label_encoder, tokenizer = load_model(MODEL_PATH, loss=weighted_binary_crossentropy)
<ipython-input-6-03f944f0a51f> in load_model(model_base_dir, loss, optimizer, metrics)
9 json_file.close()
10 model = model_from_json(loaded_model_json)
---> 11 model.load_weights(os.path.join(MODEL_PATH, 'model.h5'))
12 model.compile(loss=loss, optimizer=optimizer, metrics=metrics)
13 # loading context_encoder
~\anaconda3\envs\davis_env\lib\site-packages\keras\engine\network.py in load_weights(self, filepath, by_name, skip_mismatch, reshape)
1154 """
1155 if h5py is None:
-> 1156 raise ImportError('`load_weights` requires h5py.')
1157 with h5py.File(filepath, mode='r') as f:
1158 if 'layer_names' not in f.attrs and 'model_weights' in f:
ImportError: `load_weights` requires h5py.
I have since install cython and h5py as described in the answers found here and here
Are there any other solutions?
I'm using tensorflow version 1.12.0 and keras version 2.2.4
UPDATE:
When simply trying to import h5py (via ```import h5py``) I receive the following error message:
ImportError Traceback (most recent call last)
<ipython-input-15-c9f0b8c65221> in <module>
----> 1 import h5py
~\anaconda3\envs\davis_env\lib\site-packages\h5py\__init__.py in <module>
32 raise
33
---> 34 from . import version
35
36 if version.hdf5_version_tuple != version.hdf5_built_version_tuple:
~\anaconda3\envs\davis_env\lib\site-packages\h5py\version.py in <module>
15
16 from collections import namedtuple
---> 17 from . import h5 as _h5
18 import sys
19 import numpy
h5py\h5.pyx in init h5py.h5()
ImportError: DLL load failed: The specified procedure could not be found.```

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

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