『MXNet』第六弹_数据处理API(待续)
2021-04-08 03:24
标签:file nump form 处理 lambda item cal rda col 给出ImageFolderDataset类的描述, 实例: 具有特殊方法,def __iter__(self),其实例可以被迭代,也就是每次返回一个batch的数据,在第一维度上切割。 首个定位参数文档如下: 最后生成的X_batch送入net(X_batch)向前传播,y_batch送入loss(output,y_batch)计算loss后反向传播。 https://blog.csdn.net/qq_36165459/article/details/78394322 https://blog.csdn.net/u012759136/article/details/50208733#%E4%BA%8C%E4%BB%8E%E5%8E%9F%E7%94%9F%E6%95%B0%E6%8D%AE%E7%94%9F%E6%88%90lst%E6%96%87%E4%BB%B6 『MXNet』第六弹_数据处理API(待续) 标签:file nump form 处理 lambda item cal rda col 原文地址:https://www.cnblogs.com/hellcat/p/9094806.html一、Gluon数据加载
图片数据(含标签)加载函数:gluon.data.vision.ImageFolderDataset
Init signature: mxnet.gluon.data.vision.datasets.ImageFolderDataset(root, flag=1, transform=None)
Source:
class ImageFolderDataset(dataset.Dataset):
"""A dataset for loading image files stored in a folder structure like::
root/car/0001.jpg
root/car/xxxa.jpg
root/car/yyyb.jpg
root/bus/123.jpg
root/bus/023.jpg
root/bus/wwww.jpg
Parameters
----------
root : str
Path to root directory.
flag : {0, 1}, default 1 # 控制彩色or灰度
If 0, always convert loaded images to greyscale (1 channel).
If 1, always convert loaded images to colored (3 channels).
transform : callable, default None
A function that takes data and label and transforms them:
::
transform = lambda data, label: (data.astype(np.float32)/255, label)
Attributes
----------
synsets : list # 查看类别,实际就是文件名
List of class names. `synsets[i]` is the name for the integer label `i`
items : list of tuples # 生成的数据
List of all images in (filename, label) pairs.
"""
train_imgs = gluon.data.vision.ImageFolderDataset(
data_dir+‘/hotdog/train‘,
transform=lambda X, y: transform(X, y, train_augs))
test_imgs = gluon.data.vision.ImageFolderDataset(
data_dir+‘/hotdog/test‘,
transform=lambda X, y: transform(X, y, test_augs))
print(train_imgs)
print(train_imgs.synsets)
data = gluon.data.DataLoader(train_imgs, 32, shuffle=True)
batch迭代器:gluon.data.DataLoader
dataset : Dataset
Source dataset. Note that numpy and mxnet arrays can be directly used
as a Dataset.
二、MXNet数据加载
文章标题:『MXNet』第六弹_数据处理API(待续)
文章链接:http://soscw.com/index.php/essay/72679.html