Cannot load weights from h5 file 
Hi @2320sharon, We were able to replicate the issue in Windows10 using Tensorflow 2.12 and gdal 3.6.4. Please find the screenshot below
![image](https://user-images.githubusercontent.com/98147397/235688703-5983ec11-9672-4f96-ac05-24723dc23281.png)
It seems like we have to dig deep into the issue. We'll update here soon. Thank you! Thank you so much for looking into this, if there is anything I can do to help I am happy to assist. @2320sharon, 
Apologies for the delay.
This issue has been resolved in the latest tf-nightly version (2.14.0-dev20230509). Kindly find the screenshot of the output below
![image](https://github.com/tensorflow/tensorflow/assets/98147397/9d4369de-5567-409e-9a53-119bb29d587e)
Thank you!  Hi @synandi thank you for working on this issue.
Unfortunately, when I ran `test_script.py` with tf-nightly it did not resolve the issue.

## Commands I Ran
```
conda create -n test_new_env python=3.10 -y
conda activate test_new_env 
conda install -c conda-forge gdal==3.6.4
pip install  tf-nightly==2.14.0-dev20230509
python test_script.py
```
## Output
```
(test_new_env) C:\1_USGS\1_CoastSeg\1_official_CoastSeg_repo\CoastSeg>python test_script.py
2023-05-10 08:22:26.780726: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Model: "sequential"
_________________________________________________________________
 Layer (type)                Output Shape              Param #
=================================================================
 dense (Dense)               (None, 64)                2112

 dense_1 (Dense)             (None, 10)                650

=================================================================
Total params: 2762 (10.79 KB)
Trainable params: 2762 (10.79 KB)
Non-trainable params: 0 (0.00 Byte)
_________________________________________________________________
Traceback (most recent call last):
  File "C:\1_USGS\1_CoastSeg\1_official_CoastSeg_repo\CoastSeg\test_script.py", line 22, in <module>
    model.save_weights('my_model_weights.h5')
  File "C:\Users\Sharon\anaconda3\envs\test_new_env\lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\Sharon\anaconda3\envs\test_new_env\lib\site-packages\keras\src\saving\legacy\save.py", line 355, in save_weights
    raise ImportError(
ImportError: `save_weights` requires h5py when saving in hdf5, but h5py is not available. Try installing h5py package.
```
However, I have been able to find a solution that does work. After I ran the commands above and got the error I ran the following commands and it worked. 
```
pip uninstall h5py
conda install -c conda-forge h5py
```
![image](https://github.com/tensorflow/tensorflow/assets/61564689/a41332d4-9e3f-4ec4-9242-3acc33fd7326)

 Hi @2320sharon, We are glad that the issue is resolved.  Please feel free to close the issue. Thank you! Hi @synandi thank you for working on this issue.
Unfortunately, when I ran test_script.py with tf-nightly it did not resolve the issue. Hi @2320sharon, It is working in tf-nightly(2.14.0-dev20230515). Since it is working in the latest tf-nightly version, it will be fixed in the next stable release. 
I ran the following commands.
```
conda create -n tf python=3.10 -y
conda activate tf 
conda install -c conda-forge gdal==3.6.4
pip install  tf-nightly

pip uninstall h5py
conda install -c conda-forge h5py
python test_script.py
```

Kindly find the screenshot below
![image](https://github.com/tensorflow/tensorflow/assets/98147397/63f35a35-abe0-43a1-817e-dceec90480e9)
Thank you! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60464">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60464">No</a>
 It solved my issue when I run this command and restart my computer
pip uninstall h5py
conda install -c conda-forge h5py
<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

No

### Source

binary

### Tensorflow Version

2.12.0

### Custom Code

Yes

### OS Platform and Distribution

Windows 10 22H2

### Mobile device

_No response_

### Python version

3.10.11

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

Hello, 

Thank you for all your hard work on tensorflow I was hoping you could help me with this issue I've been facing.
I'm having an issue getting the h5py package to import properly when I have gdal and tensorflow installed in the same conda environment.

 I have the latest version of  gdal  3.6.4 and tensorflow 2.12.0 installed in an anaconda environment and when I attempt to load model weights from an .h5 file it fails claiming that h5py is not installed in the environment. The thing is h5py is installed in the environment ( I have the outputs of conda list below), but both gdal and tensorflow both use it. I believe the issue is from a [recent update to gdal which places a lock on the hdf5 library at build time](https://github.com/OSGeo/gdal/pull/7357) and I was wondering if I could modify how tensorflow imports h5py to get around this problem?

Thank you for any help you can provide.

## Anaconda Environment to reproduce the issue
``` 
conda create -n test_env python=3.10 
conda activate test_env
conda install -c conda-forge gdal==3.6.4
pip install tensorflow==2.12.0
python test_script.py
```
## Outputs of conda list
```
# Name                    Version                   Build  Channel
absl-py                   1.4.0                    pypi_0    pypi
astunparse                1.6.3                    pypi_0    pypi
blosc                     1.21.3               h6c2663c_0
boost-cpp                 1.74.0               h5b4e17d_6    conda-forge
bzip2                     1.0.8                he774522_0
ca-certificates           2022.12.7            h5b45459_0    conda-forge
cachetools                5.3.0                    pypi_0    pypi
cairo                     1.16.0            h63a05c6_1001    conda-forge
certifi                   2022.12.7                pypi_0    pypi
cfitsio                   3.470                h2bbff1b_7
charset-normalizer        3.1.0                    pypi_0    pypi
curl                      7.88.1               h2bbff1b_0
expat                     2.5.0                h63175ca_1    conda-forge
flatbuffers               23.3.3                   pypi_0    pypi
fontconfig                2.14.1               h9c4af85_2
freetype                  2.10.4               h546665d_1    conda-forge
freexl                    1.0.6                ha8e266a_0    conda-forge
gast                      0.4.0                    pypi_0    pypi
gdal                      3.6.2           py310h1c2bfe4_1
geos                      3.8.0                h33f27b4_0
geotiff                   1.7.0                h4545760_1
glib                      2.69.1               h5dc1a3c_2
google-auth               2.17.3                   pypi_0    pypi
google-auth-oauthlib      1.0.0                    pypi_0    pypi
google-pasta              0.2.0                    pypi_0    pypi
grpcio                    1.54.0                   pypi_0    pypi
h5py                      3.8.0                    pypi_0    pypi
hdf4                      4.2.13               h712560f_2
hdf5                      1.10.6          nompi_h5268f04_1114    conda-forge
icu                       58.2                 ha925a31_3
idna                      3.4                      pypi_0    pypi
intel-openmp              2023.1.0         h57928b3_46319    conda-forge
jax                       0.4.8                    pypi_0    pypi
jpeg                      9e                   h8ffe710_2    conda-forge
kealib                    1.5.0                hde4a422_0
keras                     2.12.0                   pypi_0    pypi
krb5                      1.19.3               h1176d77_0    conda-forge
lcms2                     2.12                 h83e58a3_0
lerc                      3.0                  hd77b12b_0
libblas                   3.9.0                     8_mkl    conda-forge
libcblas                  3.9.0                     8_mkl    conda-forge
libclang                  16.0.0                   pypi_0    pypi
libcurl                   7.88.1               h86230a5_0
libdeflate                1.17                 h2bbff1b_0
libexpat                  2.5.0                h63175ca_1    conda-forge
libffi                    3.4.2                hd77b12b_6
libgdal                   3.6.2                h11d7215_1
libiconv                  1.17                 h8ffe710_0    conda-forge
libkml                    1.3.0             h9859afa_1014    conda-forge
liblapack                 3.9.0                     8_mkl    conda-forge
libnetcdf                 4.8.1                h6685c40_2
libpng                    1.6.39               h8cc25b3_0
libpq                     12.9                 hb652d5d_3
libspatialite             4.3.0a              h6ec8781_23
libssh2                   1.10.0               h680486a_2    conda-forge
libtiff                   4.5.0                h6c2663c_2
libwebp-base              1.2.4                h2bbff1b_1
libxml2                   2.10.3               h0ad7f3c_0
libzip                    1.8.0                h49b8836_0
lz4-c                     1.9.4                h2bbff1b_0
markdown                  3.4.3                    pypi_0    pypi
markupsafe                2.1.2                    pypi_0    pypi
mkl                       2020.4             hb70f87d_311    conda-forge
ml-dtypes                 0.1.0                    pypi_0    pypi
numpy                     1.22.3          py310hed7ac4c_2    conda-forge
oauthlib                  3.2.2                    pypi_0    pypi
openjpeg                  2.4.0                h4fc8c34_0
openssl                   1.1.1t               h2bbff1b_0
opt-einsum                3.3.0                    pypi_0    pypi
packaging                 23.1                     pypi_0    pypi
pcre                      8.45                 h0e60522_0    conda-forge
pcre2                     10.37                h0ff8eda_1
pip                       23.0.1          py310haa95532_0
pixman                    0.38.0            hfa6e2cd_1003    conda-forge
poppler                   22.12.0              h268424c_0
poppler-data              0.4.12               hd8ed1ab_0    conda-forge
postgresql                12.9                 hb652d5d_3
proj                      6.2.1                h3758d61_0
protobuf                  4.22.3                   pypi_0    pypi
pyasn1                    0.5.0                    pypi_0    pypi
pyasn1-modules            0.3.0                    pypi_0    pypi
python                    3.10.11              h966fe2a_2
python_abi                3.10                    2_cp310    conda-forge
qhull                     2020.2               h70d2c02_2    conda-forge
requests                  2.29.0                   pypi_0    pypi
requests-oauthlib         1.3.1                    pypi_0    pypi
rsa                       4.9                      pypi_0    pypi
scipy                     1.10.1                   pypi_0    pypi
setuptools                66.0.0          py310haa95532_0
six                       1.16.0                   pypi_0    pypi
sqlite                    3.41.2               h2bbff1b_0
tensorboard               2.12.2                   pypi_0    pypi
tensorboard-data-server   0.7.0                    pypi_0    pypi
tensorboard-plugin-wit    1.8.1                    pypi_0    pypi
tensorflow                2.12.0                   pypi_0    pypi
tensorflow-estimator      2.12.0                   pypi_0    pypi
tensorflow-intel          2.12.0                   pypi_0    pypi
tensorflow-io-gcs-filesystem 0.31.0                   pypi_0    pypi
termcolor                 2.3.0                    pypi_0    pypi
tiledb                    2.3.3                h3649cd2_2
tk                        8.6.12               h2bbff1b_0
typing-extensions         4.5.0                    pypi_0    pypi
tzdata                    2023c                h04d1e81_0
urllib3                   1.26.15                  pypi_0    pypi
vc                        14.2                 h21ff451_1
vs2015_runtime            14.27.29016          h5e58377_2
werkzeug                  2.3.3                    pypi_0    pypi
wheel                     0.38.4          py310haa95532_0
wrapt                     1.14.1                   pypi_0    pypi
xerces-c                  3.2.4                hd77b12b_0
xz                        5.2.10               h8cc25b3_1
zlib                      1.2.13               h8cc25b3_0
zstd                      1.5.5                hd43e919_0
```

### Standalone code to reproduce the issue

```shell
from osgeo import gdal

import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense

# Create a simple model
model = Sequential([
    Dense(64, activation='relu', input_shape=(32,)),
    Dense(10)
])

# Compile the model
model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

# Print the model summary
model.summary()

# Save the initial weights to a file
model.save_weights('my_model_weights.h5')

# Change the weights of the model
for layer in model.layers:
    weights = layer.get_weights()  # list of numpy arrays
    weights = [weight * 0 for weight in weights]
    layer.set_weights(weights)

# Check that weights have been changed
print('Weights after resetting:')
print(model.layers[0].get_weights())

# Load the initial weights from the file
model.load_weights('my_model_weights.h5')

# Check that weights have been loaded
print('Weights after loading from file:')
print(model.layers[0].get_weights())
```


### Relevant log output

```shell
(test_env) > python sample_model.py
Model: "sequential"
_________________________________________________________________
 Layer (type)                Output Shape              Param #
=================================================================
 dense (Dense)               (None, 64)                2112

 dense_1 (Dense)             (None, 10)                650

=================================================================
Total params: 2,762
Trainable params: 2,762
Non-trainable params: 0
_________________________________________________________________
Traceback (most recent call last):
  File "C:\1_USGS\1_CoastSeg\1_official_CoastSeg_repo\CoastSeg\src\coastseg\sample_model.py", line 22, in <module>
    model.save_weights('my_model_weights.h5')
  File "C:\Users\Sharon\anaconda3\envs\test_env\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\Sharon\anaconda3\envs\test_env\lib\site-packages\keras\saving\legacy\save.py", line 351, in save_weights
    raise ImportError(
ImportError: `save_weights` requires h5py when saving in hdf5, but h5py is not available. Try installing h5py package.
```
</details>