OSError: [E053] Could not read config.cfg from C:\Users - spacy

I'm trying to run spaCY's lemmatizer on a text by running the command nlp = spacy.load("en_core_web_sm", disable=["parser", "ner"]), but then I get the following error:
OSError: [E053] Could not read config.cfg from C:\Users.
I'm using spaCy version 3.2.1, and I also installed en-core-web-sm-2.2.0.
I also get this warning, but I'm not sure what it means:
UserWarning: [W094] Model 'en_core_web_sm' (2.2.0) specifies an under-constrained spaCy version requirement: >=2.2.0. This can lead to compatibility problems with older versions, or as new spaCy versions are released, because the model may say it's compatible when it's not. Consider changing the "spacy_version" in your meta.json to a version range, with a lower and upper pin. For example: >=3.2.1,<3.3.0.
Hope someone can help me.

A v2 spaCy model won't work with spaCy v3 - you need to update your model. Do this:
spacy download en_core_web_sm
The error could be easier to understand, but it's not a situation that comes up much - usually you'd have to upgrade from spaCy v2 to v3 but not upgrade your models for that to happen. Not sure how you got in that state.

Related

Streamlit Cloud OSError: [E053] Could not read config file

I am deploying an app that specifically requires spaCy==3.3.1 to Streamlit cloud, which I added to the requirement.txt as well as the link to download and install en_core_web_sm which is
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz#egg=en_core_web_sm.
The import is okay but when I load the model i.e. nlp = spacy.load("en_core_web_sm"), I will get the OSError below:
OSError: [E053] Could not read config file from /home/appuser/venv/lib/python3.9/site-packages/en_core_web_sm/en_core_web_sm-2.2.0/config.cfg
What am I doing wrong?
Thanks in advance for your help.
My requirements.txt:
spacy==3.3.1
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.2.0/en_core_web_sm-2.2.0.tar.gz#egg=en_core_web_sm
Main code:
import en_core_web_sm
nlp = spacy.load("en_core_web_sm")
I expected no error but got the OSError: [E053] above.
Packages trained with spaCy v2.x are not compatible with spaCy v3.x
(source)
Note that the model has version 2.2.0 but spacy has version 3.3.1.
I'd suggest to use a newer version of the model. The requirements could look like:
spacy==3.3.1
en-core-web-sm # https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.3.0/en_core_web_sm-3.3.0-py3-none-any.whl

Error when saving model with tensorflow-agents

I am trying to save a model with tensorflow-agents. First I define the following:
collect_policy = tf_agent.collect_policy
saver = PolicySaver(collect_policy, batch_size=None)
and then save the model like this:
saver.save('my_directory/')
This works ok in google colab but I am getting the following error in my local PC.
AttributeError: module 'tensorflow.python.saved_model.nested_structure_coder' has no attribute 'StructureCoder'
These are the library versions I am using:
tensorflow 2.9.1
tf-agents 0.11.0
Tl;dr
Make sure you have the right tensorflow-probability version that is compatible for 2.9.x and tf-agents 0.11.0
pip uninstall tensorflow-probability
pip install tensorflow-probability==0.17.0
(0.19.0 for TF 2.11, 0.18.0 for TF 2.10 or look at the release notes)
Also make sure to restart your kernel from the notebook.
What the problem was
StructureCoder has been moved to tensorflow API. Therefore, other dependent libraries have made changes like this in tf-agent and like this in tensorflow-probability. Your machine is somehow picking up an older version that depends on the previous version of nested_structure_coder.
For me, I was using
tensorflow 2.9.0
tf-agents 0.13.0
tensorflow-probabilities 0.17.0
Try making an explicit import in your notebook:
import tensorflow_probability
print(tensorflow_probability.__version__) # was 0.17.0 for me

How to make Tensorflow vid2depth inference works?

I tried to test Tensorflow's vid2depth inference (https://github.com/tensorflow/models/tree/master/research/vid2depth).
I followed the instruction of the README. However, I got the below error:
ValueError: Couldn't find 'checkpoint' file or checkpoints in given directory vid2depth/trained-model/model-119496
I test with tf 0.12, 1.0.0. 1.8 and 1.15.
I used the below command:
python3.6 inference.py --kitti_dir ~/vid2depth/kitti-raw-uncompressed --output_dir ~/vid2depth/inference --kitti_video 2011_09_26/2011_09_26_drive_0009_sync --model_ckpt ~/vid2depth/trained-model/model-119496/
The content of the checkpoint folder I downloaded is:
model-119496.data-00000-of-00001 model-119496.index model-119496.meta
It seems provided files are not in the correct format, but I followed the link of the README.
It seems to be an old checkpoint format (Loading older checkpoint in tensorflow).
Could anyone make vid2depth works?
Thank you.

Is there any way to load FaceNet model as a tf.keras.layers.Layer using Tensorflow 2.3?

I want to use FaceNet as a embedding layer (which won't be trainable).
I tried loading FaceNet like so :
tf.keras.models.load_model('./path/tf_facenet')
where directory ./path/tf_facenet contains 4 files that can be downloaded at https://drive.google.com/file/d/0B5MzpY9kBtDVZ2RpVDYwWmxoSUk/edit
but a message error shows up :
OSError: SavedModel file does not exist at: ./path/tf_facenet/{saved_model.pbtxt|saved_model.pb}
And the h5 files downloaded from https://github.com/nyoki-mtl/keras-facenet doesn't seem to work either (they use tensorflow 1.3)
I had issued like you when load model facenet-keras. Maybe you python env missing h5py modules.
So you should install that conda install h5py
Hope you success!!!

module 'tensorflow' has no attribute 'logging'

I'm trying to run a tensorflow code in v2.0 and I'mg getting the following error
AttributeError: module 'tensorflow' has no attribute 'logging'
I don't want to simply remove it from the code.
why this code has been removed?
why should I do instead?
tf.logging was for Logging and Summary Operations and in TF 2.0 it has been removed in favor of the open-source absl-py, and to make the main tf.* namespace has functions that will be used more often.
In TF.2 lesser used functions are gone or moved into sub-packages like tf.math
So instead of tf.logging you could:
tf_upgrade_v2 will upgrade script and changes tf.logging to tf.compat.v1.logging
Python logging module can be used instead
Import absl-py library
If you are using someone else's code it's better to install same Tensorflow version as the author used, or downgrade your Tensorflow version. You may wanna try this:
pip install tensorflow==1.15.0
Or if you have gpu:
pip install tensorflow-gpu==1.15.0
You may still get depricated warnings, however you don't need to modify several files replacing tf with tf.compat.v1