(model_index, data_index)
| 103 | return res, acc |
| 104 | |
| 105 | def 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 | |
| 121 | def gather_res(mid): |
| 122 | model_name = CLIP_MODELS[mid] |
no test coverage detected