本文整理匯總了Python中data.collate_fn方法的典型用法代碼示例。如果您正苦於以下問題:Python data.collate_fn方法的具體用法?Python data.collate_fn怎麽用?Python data.collate_fn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類data
的用法示例。
在下文中一共展示了data.collate_fn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_f30k_dataloader
# 需要導入模塊: import data [as 別名]
# 或者: from data import collate_fn [as 別名]
def test_f30k_dataloader():
data_name = "f30k"
data_path = "./data/f30k"
vocab_path = "./vocab/"
vocab = pickle.load(open(os.path.join(vocab_path,
'%s_vocab.pkl' % data_name), 'rb'))
roots, ids = data.get_paths(data_path, data_name, False)
transform = transforms.Compose([transforms.RandomSizedCrop(224),
transforms.ToTensor()])
print (roots, ids)
train_loader = data.get_loader_single(data_name, "train", # !!!
roots["train"]["img"],
roots["train"]["cap"],
vocab, transform, ids=ids["train"],
batch_size=16, shuffle=False,
num_workers=1,
collate_fn=data.collate_fn,
distributed=False)
print ("f30k dataloader output:", train_loader.dataset.img_num)
#for (id, x) in enumerate(train_loader):
#if id > 0 : break
#print (id, x)