# MindSpore报错'Resize' from mindspore.dataset.vision.c\_transforms is deprecated

**1. 系统环境**

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

软件环境: MindSpore 版本: 1.10.0；mindvision=0.1.0

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

Python 版本: 3.7.6

操作系统平台: linux

**2. 报错信息**

2.1 报错信息

```
[WARNING] ME(2285:140565113722688,MainProcess):2023-10-07-11:49:35.271.471 [mindspore/dataset/core/validator_helpers.py:806] 'Resize' from mindspore.dataset.vision.c_transforms is deprecated from version 1.8 and will be removed in a future version. Use 'Resize' from mindspore.dataset.vision instead.
[WARNING] ME(2285:140565113722688,MainProcess):2023-10-07-11:49:35.272.486 [mindspore/dataset/core/validator_helpers.py:806] 'Rescale' from mindspore.dataset.vision.c_transforms is deprecated from version 1.8 and will be removed in a future version. Use 'Rescale' from mindspore.dataset.vision instead.
[WARNING] ME(2285:140565113722688,MainProcess):2023-10-07-11:49:35.273.343 [mindspore/dataset/core/validator_helpers.py:806] 'HWC2CHW' from mindspore.dataset.vision.c_transforms is deprecated from version 1.8 and will be removed in a future version. Use 'HWC2CHW' from mindspore.dataset.vision instead.
```

2.2 脚本信息

```
from mindvision.dataset import Mnist

download_train = Mnist(path="./mnist", split="train", resize=32, download=True) 
download_eval = Mnist(path="./mnist", split="test", resize=32, download=True) 
dataset_train = download_train.run() 
dataset_eval = download_eval.run() 
```

**3. 根因分析**

其实只是 WARNING出错的是Mnist的default\_transform方法 使用了mindspore.dataset.vision.c\_transforms的Resize, Rescale,HWC2CHW

```
    def default_transform(self):
        """Set the default transform for Mnist dataset."""
        rescale = 1.0 / 255.0
        shift = 0.0
        rescale_nml = 1 / 0.3081
        shift_nml = -1 * 0.1307 / 0.3081

        # define map operations
        trans = [
            Resize(size=self.resize, interpolation=Inter.LINEAR),
            Rescale(rescale, shift),
            Rescale(rescale_nml, shift_nml),
            HWC2CHW(),
        ]
        return trans
```

有这个警告是因为这几个方法加了@deprecated\_c\_vision\(\)这个装饰器.

Resize, Rescale,HWC2CHW 的 \_\_init\_\_方法上都加了类似的装饰器

```
    @deprecated_c_vision()
    @check_resize_interpolation
    def __init__(self, size, interpolation=Inter.LINEAR):
        if isinstance(size, int):
            size = (size,)
        self.size = size
        self.interpolation = interpolation
```

最新的mindspore已经不使用mindvision， 而是直接使用mindspore.dataset

https://www.mindspore.cn/docs/zh-CN/r2.2/api\_python/mindspore.dataset.html

所以有第二种解法。

**4. 解决方案**

第一种:修改mnist.py，这个直接修改mindvision的代码。

添加导入

```
from mindspore.dataset.vision import Resize,Rescale,HWC2CHW
```

```
        trans = [
            Resize(size=self.resize, interpolation=Inter.LINEAR),
            Rescale(rescale, shift),
            Rescale(rescale_nml, shift_nml),
            HWC2CHW(),
        ]
```

第二种代码：

```
import mindspore.dataset as ds
mnist_dataset_dir = "E:\\MNIST_Data"

dataset_train = ds.MnistDataset(dataset_dir=mnist_dataset_dir, usage='train')
dataset_eval = ds.MnistDataset(dataset_dir=mnist_dataset_dir, usage='test')
```

