기술/Computer Vision

랜덤 샘플 이미지

@torch.no_grad()
def inference(weight, name, img):
    if img is None:
        img = np.random.randint(0, 255, size=(112, 112, 3), dtype=np.uint8)
    else:
        img = cv2.imread(img)
        img = cv2.resize(img, (112, 112))

    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    img = np.transpose(img, (2, 0, 1))
    img = torch.from_numpy(img).unsqueeze(0).float()
    img.div_(255).sub_(0.5).div_(0.5)
    net = get_model(name, fp16=False)
    net.load_state_dict(torch.load(weight))
    net.eval()
    feat = net(img).numpy()
    print(feat)

'기술 > Computer Vision' 카테고리의 다른 글

self-supervised learning  (0) 2022.01.17
conv1d, conv2d, conv3d  (0) 2021.11.01
image normalize, inverse normalize  (0) 2021.09.16
tensor image to numpy image, numpy image to tensor image  (0) 2021.09.16
컴퓨터비전 방법론들  (0) 2021.08.01