『MXNet』第六彈_數據處理API(待續)
阿新 • • 發佈:2018-05-27
convert lena PE color bus AS array 維度 shuff
一、Gluon數據加載
圖片數據(含標簽)加載函數:gluon.data.vision.ImageFolderDataset
給出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)
<mxnet.gluon.data.vision.datasets.ImageFolderDataset object at 0x7fbed5641c18> [‘hotdog‘, ‘not-hotdog‘]
batch叠代器:gluon.data.DataLoader
具有特殊方法,def __iter__(self),其實例可以被叠代,也就是每次返回一個batch的數據,在第一維度上切割。
首個定位參數文檔如下:
dataset : Dataset Source dataset. Note that numpy and mxnet arrays can be directly used as a Dataset.
最後生成的X_batch送入net(X_batch)向前傳播,y_batch送入loss(output,y_batch)計算loss後反向傳播。
二、MXNet數據加載
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(待續)