Google colaboratory Google Colab未从cifar10获取完整数据

Google colaboratory Google Colab未从cifar10获取完整数据,google-colaboratory,Google Colaboratory,输出为: from sklearn.preprocessing import LabelBinarizer from sklearn.metrics import classification_report import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true' from tensorflow.keras.optimizers import SGD

输出为:

from sklearn.preprocessing import LabelBinarizer
from sklearn.metrics import classification_report

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'

from tensorflow.keras.optimizers import SGD
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
from tensorflow.keras.datasets import cifar10

print("[INFO] loading CIFAR-10 data")
((trainX, trainY), (testX, testY)) = cifar10.load_data()
trainX = trainX.astype("float") / 255.0
testX = testX.astype("float") / 255.0

print("trainX: {}, testX ={}".format(trainX.shape,testX.shape))

lb=LabelBinarizer()
# convert the labels from integers to vectors
trainY = lb.fit_transform(trainY)
testY = lb.transform(testY)

labelNames = ["airplane", "automobile", "bird", "cat", "deer",
"dog", "frog", "horse", "ship", "truck"]

print("[INFO] compiling model")
opt=SGD(lr=0.01, decay=0.01/40, momentum=0.9, nesterov=True)
model= MiniVGGNet.build(width=32,height=32,depth=3, classes=10)
model.compile(loss="categorical_crossentropy",
        optimizer=opt,metrics=["accuracy"])

#train the network

print("[INFO] training network..")
H=model.fit(trainX, trainY, validation_data=(testX, testY),
        batch_size=64, epochs=40, verbose=1)
当我从上面的网站下载数据时,我得到了正确的cifar数据,但当我运行我的模型时,我只能看到782张图像。 我也研究过其他模型,但结果相同。
这只发生在谷歌colab上,而不是我的本地pc上。我错过了什么

训练集和测试集都运行良好。列车组有50000张图像,测试组有10000张图像。因此,您发布的代码中没有问题。考虑添加用于训练模型的其余代码。可以通过执行来检查集合的形状

[INFO] loading CIFAR-10 data
Downloading data from https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
170500096/170498071 [==============================] - 4s 0us/step
trainX: (50000, 32, 32, 3), testX =(10000, 32, 32, 3)
[INFO] compiling model
[INFO] training network..
Epoch 1/40
782/782 [==============================] - 10s 12ms/step - loss: 1.6249 - accuracy: 0.4555 - val_loss: 1.3396 - val_accuracy: 0.5357
Epoch 2/40
782/782 [==============================] - 9s 12ms/step - loss: 1.1462


更新:

在MyBinder、我当地的Juyter笔记本和Colab中对此进行了测试,得出以下结论:

MyBinder和local Notebook并没有将CIFAR培训集分成小批量,或者只是显示培训集中单个数据点的总数。因此,他们显示在每个时期都需要50000个步骤

相反,Google Colab已将CIFAR数据集小批量分为64个小批量,并对模型进行了培训。因此,每个历元的总
步数
5000/64
,等于
782

希望这能消除你的困惑。只是Colab显示了全部的小批量,而Jupyter笔记本显示了集合中实体的总数


PS:您可能希望在共享代码的第34行末尾添加缺少的括号

看起来像是一个Colab特定的问题,我想是的,关于在哪里提问有什么建议吗,因为我知道其他人都面临这个问题,你能提供你使用的其余代码吗?您提供的代码不够,因为它不包含任何培训代码。我已经添加了我的其他部分代码,而且我为train_X和test_X获得了相同的形状“MiniVGGNet”指的是什么?这不是进口的。我想您已经重命名了导入,并且缺少原始导入代码。请告诉我你从哪个图书馆导入的。然后我可以帮助你。请参考更新,并考虑如果回答了你的问题,把这个作为答案。这是非常愚蠢的,我使用GPU第一次,而且时代发展得如此之快,我认为数据还没有完成,无论如何,多谢!我还有一个关于colab的问题,非常感谢您的帮助:[这里]()
from tensorflow.keras.datasets import cifar10
(train_X, train_y), (test_X, test_y) = cifar10.load_data()
train_X = train_X.astype("float") / 255.0
test_X = test_X.astype("float") / 255.0

print(f"train_X: {train_X.shape}, test_X = {test_X.shape}")