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
Related
I am trying to run some code to setup and load a model, keep getting this error:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/x/.cache/huggingface/hub/models--openai--clip-vit-large-patch14/refs/main'
tried to create it directly in my terminal (mac m1) and now I am getting this error instead (IsADirectoryError: [Errno 21] Is a directory: '/Users/x/.cache/huggingface/hub/models--openai--clip-vit-large-patch14/refs/main'), not sure what I am supposed to do to avoid this error.
I have these loaded, gives no error and sd-v1-4.ckpt and sd-clip-vit-l14-img-embed_ema_only.ckpt under the models. Please let me know if I need to provide any additional information, I am new to this and not sure if I missed anything important! Thank you!
!pip3 install omegaconf
!pip3 install torch torchvision
!pip3 install pytorch-lightning
!pip3 install einops
!pip3 install lightning-bolts
!pip3 install --ignore-installed PyYAML #referenced from https://stackoverflow.com/questions/62402718/error-cannot-uninstall-pyyaml-resolved-method
!pip3 install taming-transformers-rom1504
!pip3 install git+https://github.com/openai/CLIP.git
!pip3 install transformers
!pip3 install kornia
from omegaconf import OmegaConf
import torch
from PIL import Image
from torchvision import transforms
import os
from tqdm import tqdm
from einops import rearrange
import numpy as np
from pathlib import Path
import matplotlib.pyplot as plt
from huggingface_hub import notebook_login
from transformers import CLIPProcessor, CLIPModel
from ldm.util import instantiate_from_config
from ldm.models.diffusion.ddim import DDIMSampler
from ldm.models.diffusion.plms import PLMSSampler
from ldm.invoke.devices import choose_torch_device
tried to create it directly in my terminal (mac m1) and now I am getting this error instead (IsADirectoryError: [Errno 21] Is a directory: '/Users/x/.cache/huggingface/hub/models--openai--clip-vit-large-patch14/refs/main'), not sure what I am supposed to do to avoid this error.
I am trying to import python package, but having import errors
from albumentations.augmentations.transforms import Crop
showing error
cannot import name 'Crop'
Does anyone know why?
I have the same problem with resize.
Try this (source):
Update albumentations: pip install --upgrade albumentations
Also you can install latest version from git: pip install git+https://github.com/albumentations-team/albumentations.git
But it didn't help me =( I used next:
import albumentations as A
resized_image = A.Resize( height, weight)(image=image) ['image']
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
I'm trying to use pyscenedetect library on python for videos but I get this error when using the python interface and when I use the command line interface I get the error "ModuleNotFoundError: No module named 'cv2'"
even though I believe I installed both correctly according to the documentations.
I have trying to look for different ways to import opencv for the second error but to no avail. As for the first error i can't find any answers to my problem.
import cv2
import numpy as numpy
import os
import scenedetect
from scenedetect.video_manager import VideoManager
from scenedetect.scene_manager import SceneManager
from scenedetect.frame_timecode import FrameTimecode
from scenedetect.stats_manager import StatsManager
from scenedetect.detectors import ContentDetector
If you have pip you can try
pip install opencv-python
If you have anaconoda, you can try
conda install -c conda-forge opencv
it's probable that you installed it on a different python installation in your PC.
To know where your python installation is you can launch python and:
import sys
sys.path
To get the list of everything you have installed you can:
pip freeze > installed_modules.txt
Try only running
import cv2
So that you can test it
I found the problem. As Ivan was pointing out, the problem was with openCV.
I used the following command:
sudo apt install python3-opencv
I am a total newbie in Python 3 and programming in general so I looked at other peoples code and just for the beginning paste one example into Jupyter. But right at the beginning, I get an Error "ModuleNotFoundError: No module named 'xgboost'" Why does this not work?
import pandas as pd
import numpy as np
import re
import sklearn
import xgboost as xgb // error
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
import plotly.offline as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
import plotly.tools as tls
import warnings
warnings.filterwarnings('ignore')
# Going to use these 5 base models for the stacking
from sklearn.ensemble import (RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier, ExtraTreesClassifier)
from sklearn.svm import SVC
from sklearn.cross_validation import KFold
I am assuming you are running Anaconda, because this is the first error you encountered. You need to install this package: https://anaconda.org/anaconda/py-xgboost because the code you copied uses it and needs it.
You will probably get a plotly error too, so install https://anaconda.org/plotly/plotly and remember to restart Jupyter (or the kernel at least).
If you are not running Anaconda, run pip install xgboost and pip install plotly.
I tried
pip install xgboost
and
pip3 install xgboost
But it doesn't work
##ModuleNotFoundError: No module named 'xgboost'
It worked in the Jupyter Notebook cell
import sys
!{sys.executable} -m pip install xgboost
Go to command prompt >> By typing "cmd" in your windows search engine.>> Please type "pip install xgboost".
Later, close your Jupyter notebook and open it again. Run the respective cell.
If you are still getting the error then :
Add a cell in Jupyter notebook and type "pip install xgboost". Run this cell. Now it will work.
Giving a very detailed answer since beginners might be here too. Hope this helps! Be motivated! You can do it!
conda install -c conda-forge xgboost