Spaces:
Sleeping
Sleeping
Update trained model trashsort_cnn.h5
Browse files- fix_model_config.py +30 -0
- src/models/trashsort_cnn.h5 +2 -2
fix_model_config.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import h5py
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
model_path = 'src/models/trashsort_cnn.h5'
|
| 5 |
+
|
| 6 |
+
with h5py.File(model_path, 'r+') as f:
|
| 7 |
+
config_raw = f.attrs.get('model_config')
|
| 8 |
+
|
| 9 |
+
# If bytes, decode; if string, use as is
|
| 10 |
+
if isinstance(config_raw, bytes):
|
| 11 |
+
config_str = config_raw.decode('utf-8')
|
| 12 |
+
else:
|
| 13 |
+
config_str = config_raw
|
| 14 |
+
|
| 15 |
+
config = json.loads(config_str)
|
| 16 |
+
|
| 17 |
+
def fix_config(cfg):
|
| 18 |
+
if isinstance(cfg, dict):
|
| 19 |
+
if cfg.get('class_name') == 'InputLayer' and 'config' in cfg and 'batch_shape' in cfg['config']:
|
| 20 |
+
cfg['config'].pop('batch_shape')
|
| 21 |
+
for v in cfg.values():
|
| 22 |
+
fix_config(v)
|
| 23 |
+
elif isinstance(cfg, list):
|
| 24 |
+
for item in cfg:
|
| 25 |
+
fix_config(item)
|
| 26 |
+
|
| 27 |
+
fix_config(config)
|
| 28 |
+
f.attrs['model_config'] = json.dumps(config).encode('utf-8')
|
| 29 |
+
|
| 30 |
+
print("Model config fixed successfully.")
|
src/models/trashsort_cnn.h5
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4629b65fb48a0eaa1c86ef9e12886d9b53c6d709499ca3ab7580a8475b78371c
|
| 3 |
+
size 9783944
|