报错解决:ValueError: Media Bounding Box Debugger/Images is invalid.Please remove invalid

在进行yolov5进行目标检测进行训练时,运行train.py,产生报错。错误内容:ValueError: Media Bounding Box Debugger/Images is invalid. Please remove invalid filename characters

报错原因:

 

解决方法

1、关闭wandb

在utils\loggers\wandb\wandb_utils.py

try:
    import wandb

    assert hasattr(wandb, '__version__')  # verify package import not local dir
    if pkg.parse_version(wandb.__version__) >= pkg.parse_version('0.12.2') and RANK in [0, -1]:
        wandb.login(timeout=30)
except (ImportError, AssertionError):
    wandb = None

后面增加 wandb = None

try:
    import wandb

    assert hasattr(wandb, '__version__')  # verify package import not local dir
    if pkg.parse_version(wandb.__version__) >= pkg.parse_version('0.12.2') and RANK in [0, -1]:
        wandb.login(timeout=30)
except (ImportError, AssertionError):
    wandb = None
wandb = None

2、重新安装wandb可能可以解决,并没有尝试

3、修改utils/loggers/wandb/wandb_utils.py

查找 def end_epoch 进行修改

    def end_epoch(self, best_result=False):
        """
        commit the log_dict, model artifacts and Tables to W&B and flush the log_dict.

        arguments:
        best_result (boolean): Boolean representing if the result of this evaluation is best or not
        """
        if self.wandb_run:
            with all_logging_disabled():
                if self.bbox_media_panel_images:
                    sself.log_dict["Bounding Box Debugger/Images"] = self.bbox_media_panel_images
                wandb.log(self.log_dict)
                self.log_dict = {}
                self.bbox_media_panel_images = []
            if self.result_artifact:
                self.result_artifact.add(self.result_table, 'result')
                wandb.log_artifact(self.result_artifact, aliases=['latest', 'last', 'epoch ' + str(self.current_epoch),
                                                                  ('best' if best_result else '')])

                wandb.log({"evaluation": self.result_table})
                self.result_table = wandb.Table(["epoch", "id", "ground truth", "prediction", "avg_confidence"])
                self.result_artifact = wandb.Artifact("run_" + wandb.run.id + "_progress", "evaluation")

修改为

    def end_epoch(self, best_result=False):
        """
        commit the log_dict, model artifacts and Tables to W&B and flush the log_dict.

        arguments:
        best_result (boolean): Boolean representing if the result of this evaluation is best or not
        """
        if self.wandb_run:
            with all_logging_disabled():
                if self.bbox_media_panel_images:
                    self.log_dict["BoundingBoxDebugger"] = self.bbox_media_panel_images
                wandb.log(self.log_dict)
                self.log_dict = {}
                self.bbox_media_panel_images = []
            if self.result_artifact:
                self.result_artifact.add(self.result_table, 'result')
                wandb.log_artifact(self.result_artifact, aliases=['latest', 'last', 'epoch ' + str(self.current_epoch),
                                                                  ('best' if best_result else '')])

                wandb.log({"evaluation": self.result_table})
                self.result_table = wandb.Table(["epoch", "id", "ground truth", "prediction", "avg_confidence"])
                self.result_artifact = wandb.Artifact("run_" + wandb.run.id + "_progress", "evaluation")

### 加载 TensorFlow Keras 模型时遇到未知优化器错误的解决方案 当使用 `load_model` 函数加载保存为 SavedModel 格式的模型并自定义了优化器(如 Custom Adam),可能会遇到 `ValueError: Unknown optimizer` 错误。为了成功加载此类模型,可以采取以下措施: #### 设置 `compile=False` 为了避免因未识别的组件而引发异常,在调用 `load_model` 方法时应指定参数 `compile=False`[^3]。 ```python from tensorflow.keras.models import load_model model = load_model('/path/to/saved/model', compile=False) ``` #### 手动编译模型 一旦通过上述方式绕过了自动编译过程,则需显式地重新配置模型以应用所需的优化算法和其他选项。这一步骤涉及提供完整的优化器实例以及任何必要的度量标准或损失函数。 ```python import tensorflow as tf optimizer_instance = tf.keras.optimizers.Adam( learning_rate=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-07, ) model.compile( optimizer=optimizer_instance, loss='binary_crossentropy', metrics=['accuracy'] ) ``` #### 使用 `custom_objects` 参数传递自定义类 如果使用的优化器不是内置类型而是用户自定义实现版本,则还需要借助于 `custom_objects` 参数来告知框架如何解析这些实体。对于名为 “CustomAdam”的定制化优化器而言,具体做法如下所示[^4]: ```python class CustomAdam(tf.keras.optimizers.Optimizer): # 定义自己的优化器逻辑... custom_objects_dict = { 'CustomAdam': CustomAdam } model = load_model( '/path/to/saved/model', custom_objects=custom_objects_dict, compile=True # 如果已注册所有依赖项则可尝试开启此标志位 ) ``` 以上策略能够有效处理由不兼容或者缺失的优化器引起的加载失败情况,并确保所恢复的对象具备预期的行为特性。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值