Exemplo n.º 1
0
 def block(in_filters, out_filters, k, downsample):
     if not downsample:
         k_first = 3
         skip_stride = 1
         k_skip = 1
     else:
         k_first = 4
         skip_stride = 2
         k_skip = 2
     return [
         Dense(
             nn.Conv2d(in_filters,
                       out_filters,
                       k_first,
                       stride=skip_stride,
                       padding=1)),
         nn.ReLU(),
         Dense(
             nn.Conv2d(in_filters,
                       out_filters,
                       k_skip,
                       stride=skip_stride,
                       padding=0), None,
             nn.Conv2d(out_filters, out_filters, k, stride=1, padding=1)),
         nn.ReLU()
     ]
Exemplo n.º 2
0
def averaging_model(models, output_size=10):
    modules = []
    modules.append(Dense(nn.Sequential()))
    model_layer_counts = []
    for i, model in enumerate(models):
        model_modules = list(model.modules())[1:]
        model_layer_counts.append(len(model_modules))
        modules.append(
            Dense(*([nn.Sequential()] + [None] * (len(modules) - 1))))
        for model_module in model_modules:
            modules.append(model_module)
    combine_modules = []
    combine_modules.append(get_copy_layer(output_size))
    for model_layer_count in model_layer_counts[1:]:
        combine_modules += [None] * model_layer_count
        combine_modules.append(get_copy_layer(output_size))

    modules.append(Dense(*combine_modules))
    modules.append(get_average_layer(output_size, len(models)))

    avg_model = DenseSequential(*modules)
    return avg_model
Exemplo n.º 3
0
def har_resnet_model():
    model = DenseSequential(Dense(nn.Linear(561, 561)), nn.ReLU(),
                            Dense(nn.Sequential(), None, nn.Linear(561, 561)),
                            nn.ReLU(), nn.Linear(561, 6))
    return model