Exemplo n.º 1
0
    norm = norm * 0.1
    # 均值加 0.5,保证大部分的梯度值为正
    norm = norm + 0.5
    # 把 0,1 以外的梯度值分别设置为 0 和 1
    norm = norm.clip(0, 1)
    return norm


if __name__ == '__main__':
    ssd = SSD()
    model = get_ssd("train", 3)  # ssd.net
    model.load_state_dict(
        torch.load(
            "F:/Iris_SSD_small/ssd-pytorch-master/logs/Epoch50-Loc0.0260-Conf0.1510.pth",
            map_location=torch.device('cuda')))
    ssd.net = model.eval()
    ssd.net = torch.nn.DataParallel(ssd.net)
    # ssd.net = ssd.net.cpu()  # ****

    # criterion = MultiBoxLoss(3, 0.5, True, 0, True, 3, 0.5,False, True)
    model = ssd.net.module
    imgPath = '1.bmp'
    image = Image.open(imgPath)
    image.show()
    image_size = image.size
    image = image.convert('RGB')
    # r_image = ssd.detect_image(image)
    # r_image.show()

    # -------------------------------------------- #
    norm = norm * 0.1
    # 均值加 0.5,保证大部分的梯度值为正
    norm = norm + 0.5
    # 把 0,1 以外的梯度值分别设置为 0 和 1
    norm = norm.clip(0, 1)
    return norm


if __name__ == '__main__':
    ssd = SSD()
    model = get_ssd("train", 3)  # ssd.net
    model.load_state_dict(
        torch.load(
            "F:/Iris_SSD_small/ssd-pytorch-master/logs/Epoch50-Loc0.0260-Conf0.1510.pth",
            map_location=torch.device('cuda')))
    ssd.net = model.eval()
    ssd.net = torch.nn.DataParallel(ssd.net)
    ssd.net = ssd.net.cpu()  # ****

    # criterion = MultiBoxLoss(3, 0.5, True, 0, True, 3, 0.5,False, True)
    model = ssd.net.module
    imgPath = '1.bmp'
    image = Image.open(imgPath)
    image.show()

    image = image.convert('RGB')
    # r_image = ssd.detect_image(image)
    # r_image.show()

    # -------------------------------------------- #