# MindSpore实现Swin Transformer时遇到tensor和numpy均不能采用.format经行格式化输出

**1. 系统环境**

硬件环境\(Ascend/GPU/CPU\): GPU

软件环境: MindSpore 版本: 2.0

执行模式（静态图/动态图）： 不限

Python 版本: 3.7.6

操作系统平台: linux

**2. 报错信息**

2.1 问题描述

tensor和numpy均不能采用.format经行格式化输出。

2.2 脚本信息

```
for image,label in data_loader:
    step += 1
    images,lagels = image,label
    sample_num += image.shape[0]

    pred = model(images)
    pred_classes = pred.max(axis=1,return_indices=True)[1]
    accu_num += ops.equal(pred_classes,labels.astype(ms.int32)).sum()

    loss = train_one_step(iamge,label,astype(ms.int32))
    accu_loss += loss
    data_loader.desc = "[valid epoch {}] loss: {:.3f}".format(epoch,accu_loss.asnumpy().item()/(step+1),accu_num.asnumpy().item()/sample_num)

    if not ops.isfinite(loss):
        print("WARNING:non-finite loss,ending training",loss)
        sys.exit(1)

    return accu_loss.asnumpy()/(step+1),accu_num.asnumpy()/sample_num
```

**3. 解决方案**

putorch也需要转换，可以这样

```
accu_num.item()
```

mindspore需要

```
accu_num.asnumpy().item()
```

