keras_vggface: No module named 'keras.engine.topology' - python

There are several tutorials online that import a VGGFace model from keras_vggface like this:
from keras_vggface.vggface import VGGFace
However, I get the following error:
ModuleNotFoundError: No module named 'keras.engine.topology'
This problem happens on my local machine, but also on Google Colab after installing keras_vggface with
!pip install keras_vggface

I solved this issue in Google Colab by changing the import from
from keras.engine.topology import get_source_inputs
to
from keras.utils.layer_utils import get_source_inputs
in usr/local/lib/python3.7/dist-packages/keras_vggface/models.py

! pip install git+https://github.com/rcmalli/keras-vggface.git
!pip install keras_applications --no-deps
filename = "/usr/local/lib/python3.7/dist-packages/keras_vggface/models.py"
text = open(filename).read()
open(filename, "w+").write(text.replace('keras.engine.topology', 'tensorflow.keras.utils'))
import tensorflow as tf
from keras_vggface.vggface import VGGFace
vggface = VGGFace(model='resnet50') # or VGGFace() as default
worked for me and colab

I think you need to install it as below:
!pip install keras_vggface
It should work

Related

AttributeError: module 'tensorflow.python.util.dispatch' has no attribute 'add_fallback_dispatch_list'

Why the following error only when running Jupyter notebook via Anaconda Navigator?
I've tried pip install --upgrade tensorflow but it doesn't help and the error remains.
However, it is fine without this error when running on Colaboratory.
import tensorflow as tf
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.layers import Input, Embedding, Bidirectional, LSTM, Dropout, Dense
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import RMSprop
Error snapshot
Reason might be a wrong version of tensorflow-estimator being installed.
Can you try:
!pip uninstall tensorflow-estimator
!pip install tensorflow-estimator==2.1
in Jupyter notebook.
If this didn't work:
conda remove tensorflow
conda install tensorflow-estimator=2.1
conda install tensorflow-gpu=2.1
reinstall tensorflow and try importing?
Try creating a new environment and then run.
Else, if you are running it in a new environment then, try the base environment.
This resolves issue some times. Won't hurt trying!! Good luck

layoutparser gives error "module layoutparser has no attribute ocr"

I am trying to use the new layoutparser package to do some OCR. However, coming from an R backgroud I have a hard time getting it up and running.
I installed it via (worked fine):
pip install layoutparser
pip install "layoutparser[ocr]"
Now, when I run the following I get an error:
import layoutparser as lp
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import cv2
ocr_agent = lp.ocr.TesseractAgent()
AttributeError: module layoutparser has no attribute ocr
ocr_agent = lp.TesseractAgent()
This worked for me (at least no python error):
import layoutparser.ocr as ocr
ocr_agent = ocr.TesseractAgent()
But need an explaination why the following does not work:
import layoutparser as lp
ocr_agent = lp.ocr.TesseractAgent()
The documentation states 'If you would like to use the Detectron2 models for layout detection, you might need to run the following command:'
pip install layoutparser torchvision && pip install "detectron2#git+https://github.com/facebookresearch/detectron2.git#v0.5#egg=detectron2"
I had to import pytesseract after layoutparser, torchvision and detectron2 for the same error
pip install pytesseract

How to import keras-vggface in google colab?

I tried to import keras-vggface like this:
from keras_vggface.vggface import VGGFace
But it always gives me this error
"ModuleNotFoundError: No module named 'keras_vggface".
I tried to install keras_vggface with pip like this:
!pip install --user keras-vggface
!pip install keras-vggface
!pip install git+https://github.com/rcmalli/keras-vggface.git
I think you need to install it as below:
!pip install keras_vggface
this works like a charm.
Hope it can be useful.
Struggling with VGGFace use in colab as well, resolved your problem by specifying in colab tensor flow x1 with %tensorflow_version 1.xas informed by colab warning VGGFace git:
"VGGFAce works only with 1.x TensorFlow backend AND without eager execution!!!"
EDIT: but you have to properly call !pip install keras_vggface first

How to fix ' ModuleNotFoundError: No module named 'tensorflow.python.keras' importing ImagePrediction?

I want to run tensorflow for image recognition. I have followed all the steps for it and both keras and tensorflow are installed on my computer.
Steps in this post: https://github.com/OlafenwaMoses/ImageAI/
But when I try:
from imageai.Prediction import ImagePrediction
I keep getting the error:
from tensorflow.python.keras.preprocessing import image
ModuleNotFoundError: No module named 'tensorflow.python.keras'
I think the error comes from my installation of 'tensorflow'. When I tried the method:
pip3 install --upgrade tensorflow
I got the error:
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
So I used instead:
python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl
I got it from this post: TensorFlow not found using pip
My guess is that the first error drives me to the second, but I don't know how to fix any of them.
Any suggestions?
My code until the problem is:
import tensorflow
from imageai.Prediction import ImagePrediction
Try writing
from keras.preprocessing import image
Instead of
from tensorflow.python.keras.preprocessing import image
And do the same with all Keras calls.
Make sure you have the latest version of tensorflow (2.0)
import tensorflow as tf
print(tf.__version__)
from tensorflow.keras.preprocessessing.text import Tokenizer

ImportError: No module named downsample

I am using Theano. The OS is Ubuntu. The Theano is UPTODATE. I am wondering why I am getting by from theano.tensor.signal.downsample import max_pool_2d command.
ImportError: No module named downsample.
update theano and lasagne
pip install --upgrade https://github.com/Theano/Theano/archive/master.zip
pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip
Lasagne vs Theano possible version mismatch (Windows)
The downsample module has been moved to pool, so try declaring it as:
from theano.tensor.signal.pool import pool_2d
After changing delete your theano cache with the command:
theano-cache purge
Try to update the Theano using this link.
pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip
Same issue [theano v.0.9.0dev1.dev-2...]; changed
from theano.tensor.signal import downsample
pooled_out = downsample.max_pool_2d( ... )
to
from theano.tensor.signal import pool
pooled_out = pool.pool_2d( ... )
in /lib/python2.7/site-packages/lasagne/layers/pool.py

Categories