You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:无法从TensorFlow数据集显示原始图像问题排查

训练数据集图像显示异常问题

我尝试显示训练数据集中的图像,但无法正常还原原始图像。每张图像数组的形状为(200,200,3),且已完成归一化处理。我试过将数组乘以255并调用transpose(1,2,0),但显示效果仍无改善。

图像预处理/归一化代码

img_list = []
for file in sorted(os.listdir(img_folder)):
    img_path = os.path.join(img_folder, file)
    if os.path.isfile(img_path):
        img = np.array(Image.open(img_path))
        img = np.resize(img, (img_height,img_width,3))
        img = img.astype('float32')
        img /= 255
        img_list.append(img)
    img_np = np.array(img_list)
    return img_np

数据集创建函数

def data_split(id_arr):
    imgs = []
    labels = []
    for id_ in id_arr:
        for n, (k,v) in enumerate(class_dict.items()):
            if id_ == k:
                imgs.append(img_data[n,:])
                labels.append(v)
                break
    return tf.data.Dataset.from_tensor_slices((imgs, labels))

尝试的图像显示代码

plt.figure(figsize=(5,5))
for img, label in train_ds.take(1):
    img_after = Image.fromarray(img.numpy(), 'RGB')
    plt.imshow(img_)

运行上述显示代码后,图像显示色彩失真、无法还原原始样貌。尝试过他人提供的修改方案后,问题依旧存在,显示效果仍然异常。

内容的提问来源于stack exchange,提问作者Jenny Lin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 13:43:11