Ejemplo n.º 1
0
def main():

    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    model = inceptionv1(pretrained=True)
    model.to(device).eval()

    CPPN = False

    SPATIAL_DECORRELATION = True
    CHANNEL_DECORRELATION = True

    if CPPN:
        # CPPN parameterization
        param_f = lambda: param.cppn(224)
        opt = lambda params: torch.optim.Adam(params, 5e-3)
        # Some objectives work better with CPPN than others
        obj = "mixed4d_3x3_bottleneck_pre_relu_conv:139"
    else:
        param_f = lambda: param.image(
            224, fft=SPATIAL_DECORRELATION, decorrelate=CHANNEL_DECORRELATION)
        opt = lambda params: torch.optim.Adam(params, 5e-2)
        obj = "mixed4a:476"

    render.render_vis(model, obj, param_f, opt)
Ejemplo n.º 2
0
from lucent.modelzoo import inceptionv1
import torch
import torchvision.models
from PIL import Image
from lucent.optvis import transform
from torch import nn
from torchvision.transforms import transforms

from consts import IMAGENET_MEAN
from consts import IMAGENET_STD

MODEL_LOADERS = {
    "inception_v3":
    lambda: torchvision.models.inception_v3(pretrained=True, aux_logits=False),
    "inception_v1":
    lambda: inceptionv1(pretrained=True),
}


def load_model(model_name: str) -> nn.Module:
    """
    Load a pretrained torchvision model.
    """
    assert model_name in MODEL_LOADERS, f"Model {model_name} cannot be loaded"

    model = MODEL_LOADERS[model_name]()
    model.eval()
    return model


def track_activations(model: nn.Module) -> Dict[str, torch.Tensor]:
Ejemplo n.º 3
0
def test_inceptionv1_import_layer_repr():
    model = inceptionv1()
    layer_names = util.get_model_layers(model, getLayerRepr=True)
    for layer_name in important_layer_names:
        assert layer_names[layer_name] == 'CatLayer()'
Ejemplo n.º 4
0
def test_inceptionv1_graph_import():
    model = inceptionv1()
    layer_names = util.get_model_layers(model)
    for layer_name in important_layer_names:
        assert layer_name in layer_names
Ejemplo n.º 5
0
def inceptionv1_model():
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    model = inceptionv1().to(device).eval()
    return model
Ejemplo n.º 6
0
def inceptionv1_model():
    model = inceptionv1().to(device).eval()
    return model