本文整理匯總了Python中data.get_loaders方法的典型用法代碼示例。如果您正苦於以下問題:Python data.get_loaders方法的具體用法?Python data.get_loaders怎麽用?Python data.get_loaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類data
的用法示例。
在下文中一共展示了data.get_loaders方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_CAMP_model
# 需要導入模塊: import data [as 別名]
# 或者: from data import get_loaders [as 別名]
def test_CAMP_model(config_path):
print("OK!")
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
parser = argparse.ArgumentParser()
#config_path = "./experiments/f30k_cross_attention/config_test.yaml"
with open(config_path) as f:
opt = yaml.load(f)
opt = EasyDict(opt['common'])
vocab = pickle.load(open(os.path.join(opt.vocab_path,
'%s_vocab.pkl' % opt.data_name), 'rb'))
opt.vocab_size = len(vocab)
train_logger = LogCollector()
print("----Start init model----")
CAMP = model.CAMP(opt)
CAMP.logger = train_logger
if opt.resume is not None:
ckp = torch.load(opt.resume)
CAMP.load_state_dict(ckp["model"])
CAMP.train_start()
print("----Model init success----")
"""
fake_img = torch.randn(16, 36, opt.img_dim)
fake_text = torch.ones(16, 32).long()
fake_lengths = torch.Tensor([32] * 16)
fake_pos = torch.ones(16, 32).long()
fake_ids = torch.ones(16).long()
CAMP.train_emb(fake_img, fake_text, fake_lengths,
instance_ids=fake_ids)
print("----Test train_emb success----")
"""
train_loader, val_loader = data.get_loaders(
opt.data_name, vocab, opt.crop_size, 128, 4, opt)
test_loader = data.get_test_loader("test", opt.data_name, vocab, opt.crop_size, 128, 4, opt)
CAMP.val_start()
img_embs, cap_embs, cap_masks = encode_data(
CAMP, test_loader, opt.log_step, logging.info)
(r1, r5, r10, medr, meanr), (r1i, r5i, r10i, medri, meanri), score_matrix= i2t(img_embs, cap_embs, cap_masks, measure=opt.measure,
model=CAMP, return_ranks=True)
logging.info("Image to text: %.1f, %.1f, %.1f, %.1f, %.1f" %
(r1, r5, r10, medr, meanr))
logging.info("Text to image: %.1f, %.1f, %.1f, %.1f, %.1f" %
(r1i, r5i, r10i, medri, meanri))