<jupyter_start><jupyter_text>개발환경- pytorch=1.10- opencv=4.5.4- numpy=1.21.4<jupyter_code>from unet_a2c import *
import cv2
import numpy as np
import os
import torch
from tqdm.notebook import tqdm<jupyter_output><empty_output><jupyter_text>validation dataset 경로 입력 한 폴더에 png, npy 파일 같이 배치<jupyter_code>VALIDATION_PATH='./test_image/A2C/'
# DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
DEVICE = 'cpu'
W_SIZE = 600
H_SIZE = 400
BATCH_SIZE = 1
output_path = './outputs/A2C/'<jupyter_output><empty_output><jupyter_text>데이터셋 준비 및 모델 로딩<jupyter_code>file_list_val = os.listdir(VALIDATION_PATH)
npy_list_val = list()
png_list_val = list()

for name in file_list_val:
    if name[-4:]=='.png':
        png_list_val.append(name)
    elif name[-4:]=='.npy':
        npy_list_val.append(name)

dataset_val = list()
for name in png_list_val:
    common_name = name[:-4]
    # npy_obj = np.load(VALIDATION_PATH+common_name+'.npy')
    # print(npy_obj)
    # break
    # npy_obj = cv2.resize(npy_obj, (W_SIZE,H_SIZE)).reshape(1,H_SIZE,W_SIZE)*255
    # npy_obj = cv2.resize(npy_obj, (W_SIZE,H_SIZE)).reshape(1,H_SIZE,W_SIZE)*255
    png_obj = cv2.imread(VALIDATION_PATH+common_name+'.png', 0)
    h, w = png_obj.shape
    png_obj = cv2.resize(png_obj, (W_SIZE,H_SIZE)).reshape(1,H_SIZE,W_SIZE)
    # dataset_val.append((png_obj, npy_obj))
    dataset_val.append((png_obj,(h,w, name)))

test_dataset = dataset_val
test_loader = torch.utils.data.DataLoader(
    test_dataset,
    batch_size=BATCH_SIZE,
    shuffle=False,
)
BEST_MODEL_PATH = 'best_model_A2C.pth'
unet = DoubleUNet(1,1).to(DEVICE)
unet.load_state_dict(torch.load(BEST_MODEL_PATH))
unet.eval()<jupyter_output><empty_output><jupyter_text>validation set predict 종합된 DSC , JI 수치 출력<jupyter_code>TP_collect = list()
LABEL_TRUE_SUM_collect = list()
PREDICTI_TRUE_SUM_collect = list()
outputs = list()
for img, (h, w, name) in tqdm(test_loader):
    img = img.to(DEVICE)
    # label_test = label.float().to(DEVICE)
                
    outputs_test,  adap_outputs, adap_label = unet(img.float(), img.float())
    tmp = outputs_test.detach().numpy().squeeze().squeeze()
    ret = cv2.resize(tmp, (int(w),int(h)))
    ret = np.round(ret).astype(int)
    cv2.imwrite(output_path+str(name[0]), ret*255)
    outputs.append(ret)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1448900388098318, 'fraction_numerical': 0.02026735661923243, 'mean_word_length': 4.9948320413436695, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '79118', 'license': 'Apache-2.0', 'n_tokens_mistral': 1019, 'n_tokens_neox': 1023, 'n_words': 149, 'path': '202112 heart_datathon_heart_AC2_AC$_JI/confirm_A2C_toMask.ipynb', 'repo_name': 'ijhan21/Hackathon', 'size': '2319'}