diff --git a/ppcls/arch/backbone/model_zoo/gvt.py b/ppcls/arch/backbone/model_zoo/gvt.py index 2e1ae0fedb3e594026da1735645822f8b0d9651a..d1afbecaac6f27d95a9780209cdb5ac33ce911b0 100644 --- a/ppcls/arch/backbone/model_zoo/gvt.py +++ b/ppcls/arch/backbone/model_zoo/gvt.py @@ -324,8 +324,7 @@ class PyramidVisionTransformer(nn.Layer): self.pos_drops.append(nn.Dropout(p=drop_rate)) dpr = [ - x.numpy()[0] - for x in paddle.linspace(0, drop_path_rate, sum(depths)) + float(x) for x in paddle.linspace(0, drop_path_rate, sum(depths)) ] # stochastic depth decay rule cur = 0 @@ -551,8 +550,7 @@ class ALTGVT(PCPVT): self.wss = wss # transformer encoder dpr = [ - x.numpy()[0] - for x in paddle.linspace(0, drop_path_rate, sum(depths)) + float(x) for x in paddle.linspace(0, drop_path_rate, sum(depths)) ] # stochastic depth decay rule cur = 0 self.blocks = nn.LayerList() diff --git a/ppcls/engine/evaluation/classification.py b/ppcls/engine/evaluation/classification.py index 45eccf71d64b372a73d78ece62ceadc4f721a469..1c82d94d20ad1f04052162a89203b6d28da40d28 100644 --- a/ppcls/engine/evaluation/classification.py +++ b/ppcls/engine/evaluation/classification.py @@ -130,8 +130,7 @@ def classification_eval(engine, epoch_id=0): for key in loss_dict: if key not in output_info: output_info[key] = AverageMeter(key, '7.5f') - output_info[key].update(loss_dict[key].numpy()[0], - current_samples) + output_info[key].update(float(loss_dict[key]), current_samples) # calc metric if engine.eval_metric_func is not None: diff --git a/ppcls/engine/train/utils.py b/ppcls/engine/train/utils.py index 44e54660b6453b713b2325e26b1bd5590b23c933..b96b254d56bb6571bcb8da9f6e96841f0d20512b 100644 --- a/ppcls/engine/train/utils.py +++ b/ppcls/engine/train/utils.py @@ -25,8 +25,8 @@ def update_metric(trainer, out, batch, batch_size): for key in metric_dict: if key not in trainer.output_info: trainer.output_info[key] = AverageMeter(key, '7.5f') - trainer.output_info[key].update(metric_dict[key].numpy()[0], - batch_size) + trainer.output_info[key].update( + float(metric_dict[key]), batch_size) def update_loss(trainer, loss_dict, batch_size): @@ -34,7 +34,7 @@ def update_loss(trainer, loss_dict, batch_size): for key in loss_dict: if key not in trainer.output_info: trainer.output_info[key] = AverageMeter(key, '7.5f') - trainer.output_info[key].update(loss_dict[key].numpy()[0], batch_size) + trainer.output_info[key].update(float(loss_dict[key]), batch_size) def log_info(trainer, batch_size, epoch_id, iter_id): @@ -53,14 +53,13 @@ def log_info(trainer, batch_size, epoch_id, iter_id): ips_msg = "ips: {:.5f} samples/s".format( batch_size / trainer.time_info["batch_cost"].avg) - eta_sec = ((trainer.config["Global"]["epochs"] - epoch_id + 1 - ) * trainer.max_iter - iter_id - ) * trainer.time_info["batch_cost"].avg + eta_sec = ( + (trainer.config["Global"]["epochs"] - epoch_id + 1 + ) * trainer.max_iter - iter_id) * trainer.time_info["batch_cost"].avg eta_msg = "eta: {:s}".format(str(datetime.timedelta(seconds=int(eta_sec)))) logger.info("[Train][Epoch {}/{}][Iter: {}/{}]{}, {}, {}, {}, {}".format( epoch_id, trainer.config["Global"]["epochs"], iter_id, - trainer.max_iter, lr_msg, metric_msg, time_msg, ips_msg, - eta_msg)) + trainer.max_iter, lr_msg, metric_msg, time_msg, ips_msg, eta_msg)) for i, lr in enumerate(trainer.lr_sch): logger.scaler( diff --git a/ppcls/metric/metrics.py b/ppcls/metric/metrics.py index 134ef279b2b6fbb4810893946292abcbe58f4522..b1e40732fba1cf31e5d640bd22aaf53f3d323909 100644 --- a/ppcls/metric/metrics.py +++ b/ppcls/metric/metrics.py @@ -113,7 +113,7 @@ class mAP(nn.Layer): precision_mask = paddle.multiply(equal_flag, precision) ap = paddle.sum(precision_mask, axis=1) / paddle.sum(equal_flag, axis=1) - metric_dict["mAP"] = paddle.mean(ap).numpy()[0] + metric_dict["mAP"] = float(paddle.mean(ap)) return metric_dict @@ -157,7 +157,7 @@ class mINP(nn.Layer): hard_index = paddle.argmax(auxilary, axis=1).astype("float32") all_INP = paddle.divide(paddle.sum(equal_flag, axis=1), hard_index) mINP = paddle.mean(all_INP) - metric_dict["mINP"] = mINP.numpy()[0] + metric_dict["mINP"] = float(mINP) return metric_dict @@ -207,7 +207,7 @@ class TprAtFpr(nn.Layer): result = "threshold: {}, fpr: 0.0, tpr: {:.5f}".format( threshold, tpr) msg = f"The number of negative samples is 0, please add negative samples." - logger.warning(msg) + logger.warning(msg) fpr = np.sum( gt_neg_score_list > threshold) / len(gt_neg_score_list) if fpr <= self.max_fpr and tpr > max_tpr: @@ -362,7 +362,7 @@ class HammingDistance(MultiLabelMetric): metric_dict["HammingDistance"] = paddle.to_tensor( hamming_loss(target, preds)) self.avg_meters["HammingDistance"].update( - metric_dict["HammingDistance"].numpy()[0], output.shape[0]) + float(metric_dict["HammingDistance"]), output.shape[0]) return metric_dict @@ -402,7 +402,7 @@ class AccuracyScore(MultiLabelMetric): sum(tps) + sum(tns) + sum(fns) + sum(fps)) metric_dict["AccuracyScore"] = paddle.to_tensor(accuracy) self.avg_meters["AccuracyScore"].update( - metric_dict["AccuracyScore"].numpy()[0], output.shape[0]) + float(metric_dict["AccuracyScore"]), output.shape[0]) return metric_dict diff --git a/ppcls/utils/misc.py b/ppcls/utils/misc.py index 8015552437998264322661518ba3ce40c7cd7db5..b63da7c5f6930f3a5935b3d1163a8f32bf2484b1 100644 --- a/ppcls/utils/misc.py +++ b/ppcls/utils/misc.py @@ -47,7 +47,7 @@ class AverageMeter(object): @property def avg_info(self): if isinstance(self.avg, paddle.Tensor): - self.avg = self.avg.numpy()[0] + self.avg = float(self.avg) return "{}: {:.5f}".format(self.name, self.avg) @property