I'm trying to run my GPU instead of CPU in Jupyter Notebook. My GPU works now. However, I'm getting an error as in the snippet below.I've tried virtually every to fix that h5py missing file bug, but I haven't succeeded. That essentially means that in my activate envGPU4 I cannot run some code. I was reasoning along the lines that some h5py file overwrites that system one, but I'm unable to fix it.From Anaconda it does work somehow:
(C:\Users\Documents\myenvGPU4) C:\Users\Documents>python -c "import h5py; print(h5py.__file__)"
C:\Users\Documents\myenvGPU4\lib\site-packages\h5py\__init__.py
Gives this output:
C:\Users\Documents\myenvGPU4\lib\site-packages\h5py\__init__.py
and
python -c "import h5py; print(h5py.__version__)"
3.10.0
But not in the Jupyter Notebook!
EDIT The initial code was like this:
import numpy as np
import tensorflow as tf
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.applications.mobilenet_v2 import preprocess_input, decode_predictions
from tensorflow.keras.preprocessing import image
# Load the pre-trained MobileNetV2 model
model = MobileNetV2(weights='imagenet', include_top=True)
# Load and preprocess an image
# Replace 'path/to/your/image.jpg' with the actual file path
img_path = 'path/to/your/image.jpg'
img = image.load_img(img_path, target_size=(224, 224)) # MobileNetV2 expects images of size 224x224
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
# Make a prediction
predictions = model.predict(x)
# Decode and print the top-3 predicted classes
for _, pred_class, prob in decode_predictions(predictions, top=3)[0]:
print(f"Predicted: {pred_class} with probability {prob}")
EDIT 2 Also with Anaconda terminal it doesn't work:
root@2:~# /mnt/c/Users//Documents/myenvGPU3/python.exe ./a
2023-12-25 19:07:55.247085: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not f
2023-12-25 19:07:55.247284: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
2023-12-25 19:07:56.445709: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not f
2023-12-25 19:07:56.446225: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublas64_11.dll'; dlerror: cublas64_11.dll not fou
2023-12-25 19:07:56.446665: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublasLt64_11.dll'; dlerror: cublasLt64_11.dll not
2023-12-25 19:07:56.447011: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2023-12-25 19:07:56.447354: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not fou2023-12-25 19:07:56.447723: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusolver64_11.dll'; dlerror: cusolver64_11.dll not
2023-12-25 19:07:56.448077: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not
2023-12-25 19:07:56.448397: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2023-12-25 19:07:56.448491: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above
Skipping registering GPU devices...
2023-12-25 19:07:56.448812: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use t
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
File "\wsl.localhost\Ubuntu-22.04\root\a", line 8, in <module>
model = MobileNetV2(weights='imagenet', include_top=True)
File "C:\Users\Documents\myenvGPU3\lib\site-packages\keras\applications\mobilenet_v2.py", line 484, in MobileNetV2
model.load_weights(weights_path)
File "C:\Users\Documents\myenvGPU3\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\Documents\myenvGPU3\lib\site-packages\keras\engine\training.py", line 2931, in load_weights
with h5py.File(filepath, "r") as f:
AttributeError: module 'h5py' has no attribute 'File'
