예제 #1
0
def run():
    args = get_args()
    config = from_yaml(Config, Path(args.config).read_text())
    state_dict = torch.load(args.model)["state_dict"]
    state_dict = {
        key[6:]: val
        for key, val in state_dict.items() if key.startswith("model.")
    }
    model = EfficientNet.from_name(config.model, num_classes=1)
    print(model.load_state_dict(state_dict))
    model.eval()

    image = cv2.imread(args.target)[:, :, :3]

    images = image.transpose(
        (2, 0, 1))[None, :, :, :].astype(np.float32) / 255.0
    bgr_image = torch.tensor(images)

    images = image.transpose(
        (2, 0, 1))[None, ::-1, :, :].astype(np.float32) / 255.0
    rgb_image = torch.tensor(images)

    with torch.no_grad():
        output = model.forward(bgr_image)
        prediction = ChannelOrder.BGR if output < 0.5 else ChannelOrder.RGB
        print(f"BGR image prediction is {prediction}. Output is {output}")
        output = model.forward(rgb_image)
        prediction = ChannelOrder.BGR if output < 0.5 else ChannelOrder.RGB
        print(f"RGB image prediction is {prediction}. Output is {output}")

    cv2.imshow("BGR", image)
    cv2.imshow("RGB", image[:, :, ::-1])
    cv2.waitKey()
예제 #2
0
def main():
    with open('app.yml') as f:
        yml = f.read()
    cfg = from_yaml(App, yml)
    print(cfg)

    load_env(cfg, prefix='APP')
    print(cfg)
예제 #3
0
def run():
    args = get_args()
    config = from_yaml(Config, Path(args.config).read_text())
    logger = TestTubeLogger(
        save_dir=str(config.save_dir),
        name=config.experiment_name,
        version=config.version,
    )
    app = TrainSystem(config)
    trainer = Trainer(
        min_epochs=50,
        max_epochs=config.epochs,
        auto_lr_find=True,
        auto_scale_batch_size=True,
        logger=logger,
        auto_select_gpus=True,
        gpus=[0],
        num_processes=2,
        precision=16,
        callbacks=[EarlyStopping(monitor="val_loss")],
    )
    trainer.fit(app)
    trainer.test(app)
예제 #4
0
def main():
    with open('swagger.yml') as f:
        yaml = f.read()
    swagger = from_yaml(Swagger, yaml)
    print(swagger)