1 Error description
1.1 System Environment
ardware Environment(Ascend/GPU/CPU): CPU
Software Environment:
– MindSpore version (source or binary): 1.6.0
– Python version (eg, Python 3.7.5): 3.7.6
– OS platform and distribution (eg, Linux Ubuntu 16.04): Ubuntu 4.15.0-74-generic
– GCC/Compiler version (if compiled from source):
1.2 Basic information
1.2.1 Script
This case uses the mindspore.dataset custom dataset:
import os
import numpy as np
from PIL import Image
import mindspore.common.dtype as mstype
import mindspore.dataset as ds
import mindspore.dataset.transforms.c_transforms as C
import mindspore.dataset.vision.c_transforms as vc
class _dcp_Dataset:
def __init__(self,img_root_dir,device_target="CPU"):
if not os.path.exists(img_root_dir):
raise RuntimeError(f"the input image dir {img_root_dir} is invalid")
self.img_root_dir=img_root_dir
self.img_names=[i for i in os.listdir(img_root_dir) if i.endswith(".jpg")]
self.target=device_target
def __len__(self):
return len(self.img_names)
def __getitem__(self, index):
img_name=self.img_names[index]
im=Image.open(os.path.join(self.img_root_dir,img_name))
image=np.array(im)
label_str=img_name.split("_")[-1]
label_str=label_str.split(".")[0]
label=np.array(label_str)
return image,label
def creat_dataset(dataset_path,batch_size=2,num_shards=1,shard_id=0,device_target="CPU"):
dataset=_dcp_Dataset(dataset_path,device_target)
data_set=ds.GeneratorDataset(dataset,["image","label"],shuffle=True,num_shards=1,shard_id=0)
image_trans=[
vc.Resize((224,224)),
vc.RandomHorizontalFlip(),
vc.Rescale(1/255,shift=0),
vc.Normalize((0.4465, 0.4822, 0.4914), (0.2010, 0.1994, 0.2023)),
vc.HWC2CHW
]
label_trans=[C.TypeCast(mstype.int32)]
data_set=data_set.map(operations=image_trans,input_columns=["image"])
data_set=data_set.map(operations=label_trans,input_columns=["label"])
# data_set=data_set.shuffle(buffer_size=batch_size)
data_set=data_set.batch(batch_size=batch_size,drop_remainder=True)
# data_set=data_set.repeat(1)
return data_set
if __name__ == '__main__':
data=creat_dataset("./image_DCP")
print(data)
data_loader = data.create_dict_iterator()
for i, data in enumerate(data_loader):
print(i)
print(data)
1.2.2 Error reporting
Error message:
2 Reason analysis and solution
There is a lack of () here, change the code here to vc.HWC2CHW() to execute normally.
3 Summary
Steps to locate the problem
For example: there is a data processing flow such as xxDataset -> map -> map -> batch.
Scripts can be debugged as follows:
- Only keep xxDataset, and then run the script to see if an error is reported;
- Keep xxDataset -> map, and then run the script to see if an error is reported;
- Keep xxDataset -> map -> map, and then run the script to see if an error is reported;
- Keep xxDataset -> map -> map -> batch, and then run the script to see if an error is reported;
According to the above method, you can locate which map/batch is wrong.
Read More:
- [Solved] MindSpore Error: TypeError: For ‘TopK’, the type of ‘x’ should be…
- [Solved] MindSpore Network custom reverse error: TypeError: The params of function ‘bprop’ of
- K8S error validating data: ValidationError(Deployment.spec): missing required field selector
- ERROR ITMS-90022: “Missing required icon file. [How to Solve]
- [Solved] fastapi error: {“detail”:[{“loc”:[“body”],”msg”:”field required”,”type”:”value_error.missing”}]}
- [Solved] MindSpore Error: “RuntimeError: Unable to data from Generator..”
- [Solved] Azkaban Error: Missing required property ‘azkaban.native.lib’
- [Solved] MindSpore Error: `half_pixel_centers`=True only support in Ascend
- [Solved] MindSpore Error: For ‘MirrorPad‘, paddings must be a Tensor with *
- [Solved] MindSpore Error: “RuntimeError: Unexpected error. Inconsistent batch..
- [Solved] MindSpore Error: Should not use Python in runtime
- [Solved] MindSpore Error: Select GPU kernel op * fail! Incompatible data type
- [Solved] MindSpore Error: ValueError: `padding_idx` in `Embedding` out of range
- [Solved] MindSpore Error: “GeneratorDataset’s num_workers=8, this value is …”
- [Solved] MindSpore Error: “RuntimeError: Invalid data, Page size.”
- [Solved] MindSpore Error: ValueError: Minimum inputs size 0 does not match…
- [Solved] MindSpore Error: ValueError: For ‘AvgPool’ every dimension of the output shape must be greater than zero
- [Solved] MindSpore Error: StridedSlice operator does not support input of uint8 data type on Ascend hardware
- [Solved] MindSpore Error: task_fail_info or current_graph_ is nullptr
- [Solved] MindSpore infer error when passing in sens values for derivation: For ‘MatMul’, the input dimensions