Pytorch报错 The truth value of an array with more than one element is ambiguous Use a.any() or a.all()

报错

        debug_error_string = "UNKNOWN:Error received from peer ipv4:192.168.0.198:52009 {created_time:"2022-11-22T17:08:36.984605152+08:00", grpc_status:2, grpc_message:"Exception calling application: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"}"

错误原因

        for cid, cls_result in enumerate(result):
            if cls_result:
                for i in range(cls_result.shape[0]):
                    bbox = cls_result[i, :4].numpy()
                    label = self.cfg.id_label_dict.get(cid, 'none')
                    score = cls_result[i, -1].item()

列表中的项为[]或者shape为(n, 5),当该项不为[]时,无法直接得到一个非空的ndarray的布尔值,因此会报上述错误

解决办法

        for cid, cls_result in enumerate(result):
            if cls_result is not []:
                for i in range(cls_result.shape[0]):
                    bbox = cls_result[i, :4].numpy()
                    label = self.cfg.id_label_dict.get(cid, 'none')
                    score = cls_result[i, -1].item()

你可能感兴趣的:(Python,pytorch,python,人工智能)