如何无法使MNIST数据集Pytorch C++
我正在尝试跟随此但是我需要在0到255之间加载MNIST数据集。 ?
我的代码是:
int main(int argc, char* argv[]) {
const int64_t batch_size = 1;
// MNIST Dataset
auto train_dataset = torch::data::datasets::MNIST("./mnist")
.map(torch::data::transforms::Stack<>());
// Number of samples in the training set
auto num_train_samples = train_dataset.size().value();
cout << "Number of training samples: " << num_train_samples << endl;
// Data loaders
auto train_loader = torch::data::make_data_loader<torch::data::samplers::RandomSampler>(
std::move(train_dataset), batch_size);
for (auto& batch : *train_loader) {
auto data = batch.data.view({batch_size, -1}).to(device);
auto record = data[0].clone();
cout << "Max value: " << max(record) << endl;
cout << "Min value: " << max(record) << endl;
break;
}
}
我下载的MNIST数据集是原来的代码,来自 site 。
预先感谢您的帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经查看了源文件,看来Pytorch MNIST数据集类别执行255的部门以在[0,1]范围内返回张量。因此,您将必须将批次乘以255。
归一化转换不是罪魁祸首。它用于改变数据的平均值和差异
I have looked at the source file and it appears that pytorch mnist dataset class performs the division by 255 to return only tensors within the [0,1] range. So you will have to multiply the batches by 255 yourself.
The normalize transform was not the culprit. It is used to change the mean and variance of your data