目標檢測數據集(皮卡丘)


合成的數據集

%matplotlib inline
import gluonbook as gb
from mxnet import gluon, image
from mxnet.gluon import utils as gutils
import os

def _download_pikachu(data_dir):
    root_url = ('https://apache-mxnet.s3-accelerate.amazonaws.com/'
                'gluon/dataset/pikachu/')
    dataset = {'train.rec': 'e6bcb6ffba1ac04ff8a9b1115e650af56ee969c8',
               'train.idx': 'dcf7318b2602c06428b9988470c731621716c393',
               'val.rec': 'd6c33f799b4d058e82f2cb5bd9a976f69d72d520'}
    for k, v in dataset.items():
        gutils.download(root_url + k, os.path.join(data_dir, k), sha1_hash=v)


def load_data_pikachu(batch_size, edge_size=256):  # edge_size:輸出圖像的寬和高。
    data_dir = './data/pikachu'
    _download_pikachu(data_dir)
    train_iter = image.ImageDetIter(
        path_imgrec=os.path.join(data_dir, 'train.rec'),
        path_imgidx=os.path.join(data_dir, 'train.idx'),
        batch_size=batch_size,
        data_shape=(3, edge_size, edge_size),  # 輸出圖像的形狀。
        shuffle=True,  # 以隨機順序讀取數據集。
        rand_crop=1,  # 隨機裁剪的概率為 1。
        min_object_covered=0.95, max_attempts=200)
    val_iter = image.ImageDetIter(
        path_imgrec=os.path.join(data_dir, 'val.rec'), batch_size=batch_size,
        data_shape=(3, edge_size, edge_size), shuffle=False)
    return train_iter, val_iter


batch_size,edge_size = 32,256
train_iter, _ = load_data_pikachu(batch_size,edge_size)
batch = train_iter.next()

batch.data[0].shape
batch.label[0].shape

imgs = (batch.data[0][0:10].transpose((0,2,3,1))) / 255
axes = gb.show_images(imgs,2,5).flatten()
print(len(axes))
for ax, label in zip(axes, batch.label[0][0:10]):
    print(label)
    gb.show_bboxes(ax, [label[0][1:5] * edge_size], colors=['w'])

batch.data[0].shape

還是同之前的批量數據一樣(批量大小,通道,高,寬)

batch.label[0].shape

(批量大小,m,5)m : 單個圖像中最多含有的邊界框個數,5 :(是否是非法邊界框(0~1))

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM