python - pytorch:获取给定 ImageFolder 数据集的类数

标签 python machine-learning deep-learning pytorch

如果我有一个像这样的数据集:

image_datasets['train'] = datasets.ImageFolder(train_dir, transform=train_transforms)

如何以编程方式确定数据集中的类或唯一标签的数量?

最佳答案

如果您的数据类型是张量,那么您可以使用:

import torch  
n_classes = len(torch.unique(Your_Target_Vector))

关于python - pytorch:获取给定 ImageFolder 数据集的类数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55235594/

相关文章:

python - 如何在 matplotlib 中绘制动画矩阵

Python:使用泰勒级数逼近 ln(x)

python - 使用 3 个常量查找所有可能的排列

machine-learning - 将预测数据放入训练数据集中是否有效?

python - 值错误: The two structures don't have the same nested structure

python - 权限错误 : [Errno 13] Permission denied on Windows

python - 如何将残差转换为原始值 Python statsmodels

python - 在风格迁移中使用 L2 标准化 - 不涉及权重?

python - 如何在图构建时获取张量的维度(在 TensorFlow 中)?

Docker - 如何将新的 python 依赖项添加到现有的 docker 镜像?