OSerror: loading a h5 saved model in tensorflow keras after updating the environment in anaconda on windows with python 3.7 - python-3.x

I am recieving an OSerror (withouth any other text) from h5py when loading an h5 model created with keras- tensorflow after updating my enviroment, or working with an up-to-date environment.
I trained some models with keras and tf in the older versions, and also with keras-tf v1.15 and saved them using the model.save('filename.h5') code. Afterwards i am able to load them and work with them further using before the keras.load_model, and now tensorflow.keras.models.load_model without any problems but recieving some warnings that my tf version was not compiled to use the avx2 instructions and so.
The version installed is tensorflow 1.15 using pip install tensorflow-cpu and it seems to work well, my enviroment installed is Anaconda3-2020.02-Windows-x86_64 installed from the anaconda binaries on Windows.
After trying to change the packages to tensorflow-mkl, and needing to update my enviroment because of enviromental conflicts (shows even with the fresh install of anaconda) the OSerror raised by h5py appears.
Using the default enviromental packages from the anaconda binary with tf-cpu seems to work fine, either by cloning the environment. When updating the environment with conda update --all it raises the error either with tfc-cpu or tf-mkl.
The version of h5py in both cases is: '2.10.0' and the error is the following:
Traceback (most recent call last):
File "C:\Users\Oscar\bwSyncAndShare\OPT_PV22WP_intern\pv2wp_control\SIM\Sim_future.py", line 88, in <module>
model = load_model(pathfile_model)
File "C:\Users\Oscar\anaconda3\envs\optimizer2\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 142, in load_model
isinstance(filepath, h5py.File) or h5py.is_hdf5(filepath))):
File "C:\Users\Oscar\anaconda3\envs\optimizer2\lib\site-packages\h5py\_hl\base.py", line 44, in is_hdf5
return h5f.is_hdf5(filename_encode(fname))
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5f.pyx", line 156, in h5py.h5f.is_hdf5
OSError
Have anyone had this problem?
I have tried training a model with the updated environment and saving
it, when loading i get the same error.
Updating to tf-cpu v2.3.1
with the base environment and loading works also.
Creating a new env, with conda create -n name python==3.7.x anaconda
and then installing tf, doesn´t work.
i think then some other library is making the problem, but i cannot figure out what is the problem.

I use hd5 instead of h5 as the extension,and solve the problem.
i can load my deep model in colab bu when i want load that model in pc i can't

Related

Running and building Pytorch on Google Colab

I am trying to run a python package that requires pytorch-gpu. I have change the runtime type of my Colab notebook to GPU. When I run the command, I am facing the following error. Not sure if I am able to build pytorch on colab myself?
Traceback (most recent call last):
File "inference_unet.py", line 9, in <module>
import torchvision.transforms as transforms
File "/usr/local/lib/python3.6/dist-packages/torchvision/__init__.py", line 10, in <module>
from .extension import _HAS_OPS
File "/usr/local/lib/python3.6/dist-packages/torchvision/extension.py", line 58, in <module>
_check_cuda_version()
File "/usr/local/lib/python3.6/dist-packages/torchvision/extension.py", line 54, in _check_cuda_version
.format(t_major, t_minor, tv_major, tv_minor))
RuntimeError: Detected that PyTorch and torchvision were compiled with different CUDA versions. PyTorch has CUDA Version=10.2 and torchvision has CUDA Version=10.1. Please reinstall the torchvision that matches your PyTorch install.
Now you can directly use pytorch-gpu on google colab, no need of installation.
Just change your runtime to gpu, import torch and torchvision and you are done.
I have attached screenshot doing just the same.
Hope the answer will find helpful.
But in case you want to install different version of pytorch or any other package then you can install using pip, just add ! before your pip command and run the cell.
for example,

ImportError while importing sklearn

I am using python 3.7
Recently I started getting this error while importing sklearn module.
I get the same error in Jupyter Notebook, Python IDLE, Pycharm virtual environment
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\aditya\AppData\Roaming\Python\Python37\site-packages\sklearn\__init__.py", line 75, in <module>
from .utils._show_versions import show_versions
File "C:\Users\aditya\AppData\Roaming\Python\Python37\site-packages\sklearn\utils\_show_versions.py", line 12, in <module>
from ._openmp_helpers import _openmp_parallelism_enabled
ImportError: DLL load failed: The specified module could not be found.
I have tried reinstalling too.
After that I copied contents of sklearn of venv of another project which had no issues. This thing worked for couple of times. But now it's not working again
Note: pandas, numpy, scipy etc are installed and working absolutely fine. Sklearn was also working fine few days back
This is an issue in the packaging in scikit-learn 0.22.0 which will be solved in 0.22.1 (released next week). The issue is tracked at: github.com/scikit-learn/scikit-learn/issues/15899. There are 2 possible workarounds:
Install scikit-learn from conda-forge (conda include the missing dll) by default: conda install conda-forge::scikit-learn
Install VC++ which will have the openmp library (https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads)

RuntimeError: Cannot find the MXNet library

I want to create executable for my code where i'm using mxnet with pyinstaller.
I got this error
File "mxnet/libinfo.py", line 74, in find_lib_path
RuntimeError: Cannot find the MXNet library.
List of candidates:
/home/rit/test/exe/dist/test/libmxnet.so
/home/rit/test/exe/dist/test/libmxnet.so
/home/rit/test/exe/dist/test/mxnet/libmxnet.so
/home/rit/test/exe/dist/test/mxnet/../../lib/libmxnet.so
/home/rit/test/exe/dist/test/mxnet/../../build/libmxnet.so
Added libmxnet.so though spec file but gave me PyInstallerImportError
Uninstalled mxnet though pip and copied python3.5/dist-packages/mxnet to my project same problem facing.
File "PyInstaller/loader/pyiboot01_bootstrap.py", line 151, in __init__
__main__.PyInstallerImportError: Failed to load dynlib/dll '/home/rit/test/exe/dist/test/libmxnet.so'. Most probably this dynlib/dll was not found when the application was frozen.
Now what is dynlib/dll? How to resolve this error?
Thanks
MXNet needs external binaries to be fed when you freeze it. You can use add-data flag to add libmxnet files to your executable:
pyinstaller -F --add-data="<python_path>/lib/python3.7/site-packages/mxnet/*.so*:./mxnet" script.py

No module named 'torch' or 'torch.C'

Would appreciate an explanation like I'm 5 simply because I have checked all relevant answers and none have helped.
I have installed Python.
I have installed Pycharm.
I have installed Anaconda.
I have installed Microsoft Visual Studio.
I have not installed the CUDA toolkit.
In Anaconda, I used the commands mentioned on Pytorch.org (06/05/18)
conda install pytorch -c pytorch
pip3 install torchvision
Both have downloaded and installed properly, and I can find them in my Users/Anaconda3/pkgs folder, which I have added to the Python path.
Trying to enter
import torch
in the Python console proved unfruitful - always giving me the same error,
No module named 'torch'
I have also tried using the Project Interpreter to download the Pytorch package. It worked for numpy (sanity check, I suppose) but told me to go to Pytorch.org when I tried to install the "pytorch" or "torch" packages.
When trying to use the console in PyCharm, pip3 install codes (thinking maybe I need to save the packages into my current project, rather than in the Anaconda folder) return me an error message saying
torch-0.4.0-cp35-cp35m-win_amd64.whl is not a supported wheel on this
platform.
The same message shows no matter if I try downloading the CUDA version or not, or if I choose to use the 3.5 or 3.6 Python link (I have Python 3.7)
Currently the closest I have gotten to a solution, is manually copying the "torch" and "torch-0.4.0-py3.6.egg-info" folders into my current Project's lib folder.
However, when I do that and then run "import torch" I received the following error:
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 19, in do_import
module = self._system_import(name, *args, **kwargs) File "C:\Users\Michael\PycharmProjects\Pytorch_2\venv\lib\site-packages\torch__init__.py",
line 78, in
from torch._C import *
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 19, in do_import
module = self._system_import(name, *args, **kwargs) ModuleNotFoundError: No module named 'torch._C'
pip uninstall torch
then
pip install torch worked for me.
I encountered the same problem because I updated my python from 3.5 to 3.6 yesterday. I think the connection between Pytorch and Python is not correctly changed. Thus, I installed Pytorch for 3.6 again and the problem is solved.
Check the install command line here[1].

Error training tensor-flow object detection api using google cloud VM. [ImportError: No module named 'tensorflow.python.eager']

When training tensor-flow object detection api using the typical steps in google cloud VM. After configuring all the dependence, when i try to run the train.py script the error [ImportError: No module named 'tensorflow.python.eager'] poped up. I already trained using the same steps in my local PC without any errors. I couldn't find any solution related to this error.
System Info: gcloud VM; TensorFlow-GPU 1.3.0; Python 3.5; CUDA 8.0 /cuDNN 6.0:
script running command:
$ python3 train.py --logtostderr --train_dir=training/ --pipeline_config_path=ssd_mobilenet_v1_lap.config
Error:
Traceback (most recent call last): File "train.py", line 49, in
from object_detection import trainer File "/usr/local/lib/python3.5/dist-packages/object_detection-0.1-py3.5.egg/object_detection/trainer.py", line 33 , in
from deployment import model_deploy File "/home/ragulh28/project/models/research/slim/deployment/model_deploy.py",
line 106, in
from tensorflow.python.eager import context ImportError: No module named 'tensorflow.python.eager'
This issue is caused by a dependency on the new TF Eager API some of the newer models in slim use. They require the latest version of tensorflow, which is why the library is not being found.
Our apologies for the inconvenience. As a workaround, could you try checking out an older version of the Tensorflow Object Detection API? This commit should be a good candidate.

Resources