当我在google colab中执行vit模型时,我得到了一些错误。
import numpy as np
from datasets import Features, ClassLabel, Array3D
def preprocess_images(examples):
images = examples['img']
images = [np.array(image, dtype=np.uint8) for image in images]
images = [np.moveaxis(image, source=-1, destination=0) for image in images]
inputs = feature_extractor(images=images)
examples['pixel_values'] = inputs['pixel_values']
return examples
features = Features({
'label': ClassLabel(
names=['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']),
'img': Array3D(dtype="int64", shape=(3,32,32)),
'pixel_values': Array3D(dtype="float32", shape=(3, 224, 224)),
})
preprocessed_train_ds = train_ds.map(preprocess_images, batched=True, features=features)
preprocessed_val_ds = val_ds.map(preprocess_images, batched=True, features=features)
preprocessed_test_ds = test_ds.map(preprocess_images, batched=True, features=features)
ArrowTypeError:无法转换PngImageFile类型的〈PIL.PngImagePlugin.PngImageFile image mode=RGB size= 32 x32 at 0x 7 F2223 B6 ED 10〉:不是序列或识别为null,无法转换为列表类型
错误发生在preprocessed_train_ds
这一行,我猜可能是特征提取问题。
使用:
1.抱抱脸/变形金刚
- ViTFatureExtractor:谷歌/维生素C基础补丁16 -224-in 21 k
- cifar 10,split=['train [:5000]','test[:2000]'])(与大多数示例设置一致)
有人能帮帮我吗?这个问题已经困扰我很久了。
1条答案
按热度按时间eqoofvh91#
如果“img”列是PIL镜像列表,则需要将“img”的特性从数组更改为镜像,将features替换为以下内容: