when i try to do "from tensorflow.keras import intitializers" i get
"cannot import name 'set_policy' from 'keras.mixed_precision.policy'" this error.
Any solutions?
I would try:
tf.keras.mixed_precision.set_global_policy
or
policy = mixed_precision.Policy('mixed_float16')
mixed_precision.set_global_policy(policy)
More info you can find here:
https://www.tensorflow.org/guide/mixed_precision
go to the error directory and change the import from
from tensorflow.python.keras.mixed_precision.policy import set_policy
to
from tensorflow.python.keras.mixed_precision.policy import set_global_policy
or
from tensorflow.python.keras.mixed_precision.policy import set_policy as set_global_policy
Related
When I ask execute this code:
from tf_pose.estimator import TfPoseEstimator
shows error:
cannot import name 'trt_convert' from
'tensorflow.python.compiler.tensorrt'
(C:\Users\AMAN SHRIVASTAVA\anaconda3\lib\
site-packages\tensorflow\python\compiler\
tensorrt\__init__.py)
How can I resolve this?
I'm trying to import KNeihgborsClassifier from 'sklearn.neighbors' but I have this error ImportError: cannot import name 'KNeihgborsClassifier' from 'sklearn.neighbors' (C:\Users\lenovo\anaconda3\lib\site-packages\sklearn\neighbors_init_.py)
You are importing KNeihgborsClassifier which is wrong, change it to:
from sklearn.neighbors import KNeighborsClassifier
When i import it, i get an error about that.
from imgaug.augmentables.segmaps import SegmentationMapsOnImage
Error:
ImportError: cannot import name 'SegmentationMapsOnImage' from
'imgaug.augmentables.segmaps'
(/usr/local/lib/python3.7/dist-packages/imgaug/augmentables/segmaps.py)
Here is the documentation link
Thanks in advance!
I've written a python file and am trying to import it but it's not recognized.
The file was saved as gentleboost_c_class.c in C:\User\apps\My documents.
I tried to import it like this:
import gentleboost_c_class as gbc
But I get this error:
NameError: name 'gentleboost_c_class' is not defined
gentleboost_c_class.py begins like this:
from sklearn.externals.six.moves import zip
import numpy as np
import statsmodels.api as sm
class GentleBoostC:
.....
It compiles fine.
Both files are in the same folder.
What am I doing wrong?
You're getting a NameError, not an ImportError.
So it seems to me that you import your module as gbc, but later try to refer to it as gentleboost_c_class.
If you import the module with
import gentleboost_c_class as gbc
that means it will be available under the global name gbc, but not as gentleboost_c_class.
I have a module that I am testing that depends on another module that won't be available at the time of testing. To get around this, I wrote (essentially):
import mock
import sys
sys.modules['parent_module.unavailable_module'] = mock.MagicMock()
import module_under_test
This works fine as long as module_under_test is doing one of the following import parent_module, import parent_module.unavailable_module. However, the following code generates a traceback:
>>> from parent_module import unavailable_module
ImportError: cannot import name unavailable_module
What's up with this? What can I do in my test code (without changing the import statement) to avoid this error?
Alright, I think I've figured it out. It appears that in the statement:
from parent_module import unavailable_module
Python looks for an attribute of parent_module called unavailable_module. Therefore, the following set up code fully replaces unavailable_module within parent_module:
import mock
import sys
fake_module = mock.MagicMock()
sys.modules['parent_module.unavailable_module'] = fake_module
setattr(parent_module, 'unavailable_module', fake_module)
I tested the four import idioms of which I am aware:
import parent_module
import parent_module.unavailable_module
import parent_module.unavailable_module as unavailabe_module
from parent_module import unavailable_module
and each worked with the above set up code.