python - 如何规范化tensorflow中的数据

标签 python tensorflow keras

<分区>

我尝试按照 this example 创建一个简单的神经网络,但是当我想规范化数据时遇到问题

import tensorflow as tf
from tensorflow import keras


fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

train_images = test_images / 255.0
test_images = test_images / 255.0

这是我的代码,在最后两行中,如您所见,我尝试对数据进行规范化,如图所示 here ,但是在我执行此行之后,变量 training_images 只有 10,000 个样本而不是 60,000(就像在开始时一样),现在当我尝试拟合模型时(model.fit() ) 我得到一个异常

Input arrays should have the same number of samples as target arrays. Found 10000 input samples and 60000 target samples.

当我尝试在没有规范化的情况下运行这个示例时,我最多只能得到 0.2 的精度(而在网站上它们的精度要高得多) 我哪里出错了?

最佳答案

这个错误是一个简单的错字 -

train_images = test_images / 255.0
test_images = test_images / 255.0

你两次都通过 test_images 划分。将第一个分区更改为 train_images,它应该可以工作

关于python - 如何规范化tensorflow中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52059621/

相关文章:

tensorflow - 使用 output_layer=pool_3 运行 label_image 时出错

python - 交叉熵为 nan

tensorflow - 如何创建带有用于图像分割的掩码的自定义图像数据集?(特别是针对 Tensorflow)

Azure VM加载运行时CuDNN库: 8. 2.4,但源是用: 8. 6.0编译的

python - 计算 CSV 中有多少列?

python - 在 Vista 上使用 ctypes 加载 dll 时访问被拒绝

python - Tensorflow softmax 函数返回 one-hot 编码数组

python - Django formwizard - 无法从步骤1到步骤2获取数据

tensorflow - ArcFace 严格来说是损失函数还是激活函数?

python - 如何使用 keras RNN 对数据集中的文本进行分类?