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
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 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
When I am importing the package ArcFace.
from arcface.metrics import ArcFace
It is showning the import error. Like this,
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-fe2759a1802e> in <module>
15 from keras.layers.convolutional import MaxPooling2D
16 from keras.layers.core import Activation, Flatten, Dropout, Dense
---> 17 from arcface.metrics import ArcFace
18 from keras.layers import Input
19 from keras import backend as K
ModuleNotFoundError: No module named 'arcface'
I have searched for importing it for Anaconda and pip too. I have not found any results. Please help me to solve this.
This is part of project keras-arcface but it is not part of keras so you have to install/copy it separatelly.
If you put it in your project in subfolder arcface then it should work.
You can run ArcFace within deepface. The framework is mainly based on keras and tensorflow. It handles model building and downloading pre-trained weights in the background. Besides, it covers face recognition pipeline stages includign detect, align.
#!pip install deepface
from deepface import DeepFace
resp = DeepFace.verify("img1.jpg", "img2.jpg", model_name = 'ArcFace')
This is the error it gives me when I try to run it:
Traceback (most recent call last):
File "/Users/kids/Library/Mail/V5/E60CBF1C-9021-4A10-8D60-06C96C141AF1/Outbox.mbox/E7C72E99-E3DB-4CDC-B1C9-15116F3478D8/Data/Attachments/405/2/ASL-Finger-Spelling-Recognition-master/main.py", line 10, in <module>
from keras.layers.convolutional import Convolution3D, MaxPooling3D
This is the code error which it is showing:
from keras.layers.convolutional import Convolution3D, MaxPooling3D
Keras version is 2.3.1. Python version is Python 3.8. Running on MacOS.
Your import statement
from keras.layers.convolutional import Convolution3D, MaxPooling3D
attempts to import MaxPooling3D from keras.layers.convolutional. MaxPooling3D is actually part of the pooling module, i.e. keras.layers.pooling.
According to the keras source and docs, the best way to import these two classes in a single statement would be
from keras.layers import Convolution3D, MaxPooling3D
Alternatively, you could import them separately:
from keras.layers.convolutional import Convolution3D
from keras.layers.pooling import MaxPooling3D
but in general, you should pay attention to what is purposefully exposed via the package; that is, the classes accessible from keras.layers.
I have a bunch of code written using Keras that was installed as a separate pip install and the import statements are written like from keras.models import Sequential, etc..
On a new machine, I have Tensorflow installed which now includes Keras inside the contrib directory. In order to keep the versions consistent I thought it would be best to use what's in contrib instead of installing Keras separately, however this causes some import issues.
I can import Keras using import tensorflow.contrib.keras as keras but doing something like from tensorflow.contrib.keras.models import Sequential gives ImportError: No module named models, and from keras.models import Sequential gives a similar ImportError: No module named keras.models.
Is there a simple method to get the from x.y import z statements to work? If not it means changing all the instances to use the verbose naming (ie.. m1 = keras.models.Sequential()) which isn't my preferred syntax but is do-able.
Try this with recent versions of tensorflow:
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import LSTM, TimeDistributed, Dense, ...
Try with tensorflow.contrib.keras.python.keras:
from tensorflow.contrib.keras.python.keras.models import Sequential
Unfortunately from tensorflow.contrib.keras.python.keras.models import Sequential no longer works. It looks like they are changing the interface as of version 1.4 (currently at RC0). There is a note saying the tensorflow.contrib.keras interface is deprecated and you should use tensorflow.keras but this doesn't work either without python in the line.
The following did work for me under V1.4rc0
from tensorflow.python.keras.models import Sequential
import tensorflow.python.keras
import tensorflow.contrib.keras as keras
The following did not...
import tensorflow.python.keras as keras
Hopefully this gets cleaned up a bit more before final release.