Open cycos83 opened 4 years ago
infer 함수 부분입니다!
`def _infer(model, root_path, test_loader=None): """Local inference function for NSML infer.
Args:
model: instance. Any model is available.
root_path: string. Automatically set by NSML.
test_loader: instance. Data loader is defined in `data_local_loader.py`.
Returns:
predictions_str: list of string.
['img_1,1,0,1,0,1,0,0,0', 'img_2,0,1,0,0,1,0,0,0', ...]
"""
use_cuda = torch.cuda.is_available()
use_float16 = False
threshold = 0.3
iou_threshold = 0.3
model.eval()
if test_loader is None:
test_loader = data_loader(root=os.path.join(root_path))
list_of_fids = []
list_of_preds = []
for idx, (image, fid) in enumerate(tqdm(test_loader)):
print(idx)
image = image.cuda()
if use_cuda:
model = model.cuda()
if use_float16:
model = model.half()
with torch.no_grad():
features, regression, classification, anchors = model(image)
regressBoxes = BBoxTransform()
clipBoxes = ClipBoxes()
out = postprocess(image,
anchors, regression, classification,
regressBoxes, clipBoxes,
threshold, iou_threshold)
out_class = []
for n in range(len(image)):
temp_out_class = out[n]['class_ids']
out_class.append(temp_out_class)
tmp_list = [0, 0, 0, 0, 0, 0, 0, 0]
for i in range(len(temp_out_class)):
for j in range(len(tmp_list)):
if out_class[n][i] == j:
tmp_list[j] = 1
list_of_preds.append(tmp_list)
list_of_fids.extend(fid)
############################################################################
list_of_fids = np.array(list_of_fids)
list_of_preds = np.array(list_of_preds)
predictions_str = []
for idx, fid in enumerate(list_of_fids):
test_str = fid
for pred in list_of_preds[idx]:
test_str += ',{}'.format(pred)
predictions_str.append(test_str)
predictions_str = np.array(predictions_str)
return predictions_str`
안녕하세요, track 3의 모델을 submit하면 main.py의 infer 함수의 첫번째 for 문 (for idx, (image, fid) in enumerate(tqdm(test_loader)):) 이 한번만 돌고 끝납니다. 그래서 모든 테스트 데이터가 아니라 한 배치만큼의 데이터에 대해서만 모델이 판단하고 끝나버립니다. test_loader 부분은 수정한 곳이 없는데, 무엇이 문제인가요?