示例#1
0
    ]
    NPY_7CHANNEL_STD = [
        0.05338322, 0.04247037, 0.03543733, 0.00608935, 0.00623353, 0.00691525,
        0.01309933
    ]

    dataset = ResnetTrainDataset(csv_path,
                                 img_path,
                                 dtype,
                                 img_ext=img_ext,
                                 channel_means=NPY_7CHANNEL_MEAN,
                                 channel_stds=NPY_7CHANNEL_STD)

    train_loader, val_loader = generate_train_val_dataloader(
        dataset,
        batch_size=batch_size,
        num_workers=num_workers,
        use_fraction_of_data=use_fraction_of_data,
    )

    ## pretrained resnet
    model = resnet18(pretrained=False)
    ## resize last fully connected layer to match our problem
    model.fc = nn.Linear(model.fc.in_features, 17)
    ## resize the first conv layer to match our problem
    model.conv1 = nn.Conv2d(7,
                            64,
                            kernel_size=7,
                            stride=2,
                            padding=3,
                            bias=False)
    model.type(dtype)
示例#2
0
        from_pickle = int(sys.argv[1])
    except IndexError:
        from_pickle = 1
    ## cpu dtype
    dtype = torch.cuda.FloatTensor
    save_model_path = "conv_6-layer_state_dict.pkl"
    save_mat_path = "conv_6-layer_loss_and_acc.mat"
    csv_path = '../../data/train_v2.csv'
    img_path = '../../data/train-jpg'
    img_ext = '.jpg'

    dataset = AmazonDataset(csv_path, img_path, img_ext, dtype)

    train_loader, val_loader = generate_train_val_dataloader(
        dataset,
        batch_size=128,
        num_workers=0,
        use_fraction_of_data=0.2,
    )

    ## 6 conv layers
    model = nn.Sequential(
        ## 256x256
        nn.Conv2d(4, 16, kernel_size=3, stride=1),
        nn.ReLU(inplace=True),
        nn.BatchNorm2d(16),
        nn.Conv2d(16, 16, kernel_size=3, stride=1),
        nn.ReLU(inplace=True),
        nn.BatchNorm2d(16),
        nn.AdaptiveMaxPool2d(128),
        ## 128x128
        nn.Conv2d(16, 32, kernel_size=3, stride=1),