I am getting below error while trying to import tensorflow_hub. I have applied the already available solutions on Github or on stackoverflow and even downgraded my tesnorflow and estimator too. Still I am getting below. Can you please help ?
ImportError: cannot import name 'dnn_logit_fn_builder' from partially initialized module 'tensorflow_estimator.python.estimator.canned.dnn' (most likely due to a circular import) (C:\Users\kumar\anaconda3\lib\site-packages\tensorflow_estimator\python\estimator\canned\dnn.py)
code -
import tensorflow as tf
from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
import tensorflow_hub as hub
Given code worked fine with Tf v2.8 and v2.9.1
import tensorflow as tf
from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
import tensorflow_hub as hub
Related
I was trying to run this code, first time using Tensorflow API in Python. Donwloaded latest version of tensorflow and pip through terminal. However, when I attempt to import from keras subpackage, an error is returned
from keras.models import Model
from keras.layers import Dense
from keras.layers import Input
ImportError: cannot import name 'pywrap_tensorflow' from partially initialized module 'tensorflow.python' (most likely due to a circular import) (/Users/macbook/Library/Python/3.9/lib/python/site-packages/tensorflow/python/__init__.py) ```
I'm try learning TensorFlow but i have a problem. I'm importing TensorFlow like in official website but i take a error.
import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
Traceback (most recent call last):
File "C:\Users\Koray\Desktop\Python\main.py", line 4, in
from tensorflow import keras
ImportError: cannot import name 'keras' from 'tensorflow'
(C:\Users\Koray\Desktop\Python\tensorflow.py)
For community benefit, adding #John Gordon answer here in the answer section.
Don't name your script tensorflow.py. Your import finds that script instead of the real one.
Instead you can name any other for example learning.py. Now all your imports work as expected.
import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
I'm trying my hand at replicating what this dude did on his github and trying to run some of his scripts (stock price prediction allegedly). I keep bumping into this error no matter what I do. I have a feeling I didn't set up tensorflow or keras properly.
File "/home/mihai/.local/lib/python3.8/site-packages/keras/api/_v2/keras/utils/__init__.py", line 38, in <module>
from keras.utils.vis_utils import plot_model
ImportError: cannot import name 'plot_model' from partially initialized module 'keras.utils.vis_utils' (most likely due to a circular import) (/home/mihai/.local/lib/python3.8/site-packages/keras/utils/vis_utils.py)
Would appreciate any input!
you can look here -> This worked taking from TensorFlow documentation
try is also
from keras.utils.vis_utils import plot_model
or
from tensorflow.keras.utils import plot_model
when I try to import keras on a Jupyter notebook I receive this error message: ModuleNotFoundError: No module named 'tensorflow'.
I need to use keras to build an LSTM model fora project and am a beginner in python so I don't know how to get around this error. I have tried to install tenserflow and keras into an environment on anaconda but I receive the same error. For reference, I am using a Mac.
My code:
#Import libraries used
import math
import pandas as pd
import pandas_datareader.data as web
import datetime as dt
import numpy as np
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers import Dense, LSTM
Any help would be greatly appreciated!
My code:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
from tensorflow.python.compiler.tensorrt import trt_convert as trt
# import tensorflow.contrib.slim as slim
When I run it, get this error:
ModuleNotFoundError: No module named 'tensorflow.python.compiler.tensorrt'
Also, instead of from tensorflow.python.compiler.tensorrt import trt_convert as trt I used from tensorflow.python.compiler.tensorrt import trt but it did not change anything.
I use TensorFlow version 1.14.
Also worth mentioning https://forums.developer.nvidia.com/t/error-converting-tensorflow-model-to-tensorrt-on-windows-10/83892 its not supported on windows 10
In version that lower then 1.14.1 the right import is:
import tensorflow.contrib.tensorrt as trt
try to change
from tensorflow.python.compiler.mlcompute import mlcompute
for setting the GPU device in Metal plugin. We honor the Tensorflow's device placement logic. So depending on the supported operations in Metal plugin the layers will be mapped to GPU by TF's device placer. You can use tf.debugging.set_log_device_placement(
True) to dump out the layers mapped to GPU. I just removed the mlcompute import below and was able to train the network.