【报错】ValueError: Unable to create dataset (name already exists)

一直报错

Traceback (most recent call last):
  File "/home/shuangyanli/seizure-prediction-CNN/mainconfusion.py", line 167, in <module>
    main(dataset=args.dataset, build_type=args.mode)
  File "/home/shuangyanli/seizure-prediction-CNN/mainconfusion.py", line 102, in main
    model.fit(X_train, y_train, X_val, y_val)
  File "/home/shuangyanli/seizure-prediction-CNN/models/cnn_mvit.py", line 150, in fit
    self.model.fit(X_train, Y_train, batch_size=self.batch_size,
  File "/data7/shuangyanLi/AnaConda3/envs/tf39/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/shuangyanli/seizure-prediction-CNN/models/customCallbacks.py", line 97, in on_epoch_end
    self.model.save_weights(filepath, overwrite=True) # 7.26
  File "/data7/shuangyanLi/AnaConda3/envs/tf39/lib/python3.9/site-packages/h5py/_hl/group.py", line 183, in create_dataset
    dsid = dataset.make_new_dset(group, shape, dtype, data, name, **kwds)
  File "/data7/shuangyanLi/AnaConda3/envs/tf39/lib/python3.9/site-packages/h5py/_hl/dataset.py", line 165, in make_new_dset
    dset_id = h5d.create(parent.id, name, tid, sid, dcpl=dcpl, dapl=dapl)
  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/h5d.pyx", line 135, in h5py.h5d.create
ValueError: Unable to create dataset (name already exists)

将保存下来的h5文件读取一下
code:

>>> import h5py
>>> import tensorflow as tf
>>> path = 'weights_3_cv.h5'
>>> from tensorflow.keras.models import Sequential, Model
>>> mdoel.load_weights(path)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'mdoel' is not defined
>>> mdoel=load_weights(path)                                                                                                                                                      
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'load_weights' is not defined
>>> from keras.models import load_model
>>> model = load_model(path)

error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data7/shuangyanLi/AnaConda3/envs/tf39/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/data7/shuangyanLi/AnaConda3/envs/tf39/lib/python3.9/site-packages/keras/utils/generic_utils.py", line 562, in class_and_config_for_serialized_keras_object
    raise ValueError(
ValueError: Unknown layer: MViT. Please ensure this object is passed to the `custom_objects` argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

参考链接:
https://stackoverflow.com/questions/50837728/valueerror-unknown-layer-capsulelayer
添加图层的初始化参数
添加了但是没有用

换一种方式:
https://stackoverflow.com/questions/72776335/valueerror-unable-to-create-dataset-name-already-exists-when-using-modelcheck
将 ‘.h5’ 保存为 ‘.tf’ 但是还是报错,这样 .tf是一个文件

最后怎么解决的?
答:
没有保存h5文件
而是:

checkpoint_save_path = "weights_%s_%s/" %(self.target, self.mode)
checkpoint_callback = keras.callbacks.ModelCheckpoint(
			checkpoint_save_path,
			monitor="val_accuracy",
			save_best_only=True,
			save_weights_only=True,
		)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值