MCPcopy
hub / github.com/jindongwang/transferlearning / perform_inference

Function perform_inference

code/clip/test_clip.py:105–119  ·  view source on GitHub ↗
(model_index, data_index)

Source from the content-addressed store, hash-verified

103 return res, acc
104
105def perform_inference(model_index, data_index):
106 model_pretrain, dataset = CLIP_MODELS[model_index], DATA_FOLDER[data_index]
107 data, labels = load_data(dataset)
108 model, processor = load_model(model_pretrain)
109 res, acc = classify_imagenetr(
110 data, labels, model, processor, device='cuda')
111 m_rep, d_rep = model_pretrain.replace('/', '-'), dataset.replace('/', '-')
112 # if exist some folder
113 if not os.path.exists('clip_res/'):
114 os.makedirs('clip_res/')
115 fname = f'clip_res/{m_rep}_{d_rep}'
116 np.savetxt(fname + '.txt', res, fmt='%d')
117 with open(fname + '.txt', 'w') as fp:
118 fp.write(fname + ',' + str(acc))
119 return res, acc
120
121def gather_res(mid):
122 model_name = CLIP_MODELS[mid]

Callers 1

sweepFunction · 0.85

Calls 4

classify_imagenetrFunction · 0.85
load_dataFunction · 0.70
load_modelFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected