File size: 2,215 Bytes
8f87579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''
Netdissect package.

To run dissection:

1. Load up the convolutional model you wish to dissect, and wrap it
   in an InstrumentedModel.  Call imodel.retain_layers([layernames,..])
   to analyze a specified set of layers.
2. Load the segmentation dataset using the BrodenDataset class;
   use the transform_image argument to normalize images to be
   suitable for the model, or the size argument to truncate the dataset.
3. Write a function to recover the original image (with RGB scaled to
   [0...1]) given a normalized dataset image; ReverseNormalize in this
   package inverts transforms.Normalize for this purpose.
4. Choose a directory in which to write the output, and call
   dissect(outdir, model, dataset).

Example:

    from netdissect import InstrumentedModel, dissect
    from netdissect import BrodenDataset, ReverseNormalize

    model = InstrumentedModel(load_my_model())
    model.eval()
    model.cuda()
    model.retain_layers(['conv1', 'conv2', 'conv3', 'conv4', 'conv5'])
    bds = BrodenDataset('dataset/broden1_227',
            transform_image=transforms.Compose([
                transforms.ToTensor(),
                transforms.Normalize(IMAGE_MEAN, IMAGE_STDEV)]),
            size=1000)
    dissect('result/dissect', model, bds,
            recover_image=ReverseNormalize(IMAGE_MEAN, IMAGE_STDEV),
            examples_per_unit=10)
'''

from .dissection import dissect, ReverseNormalize
from .dissection import ClassifierSegRunner, GeneratorSegRunner
from .dissection import ImageOnlySegRunner
from .broden import BrodenDataset, ScaleSegmentation, scatter_batch
from .segdata import MultiSegmentDataset
from .nethook import InstrumentedModel
from .zdataset import z_dataset_for_model, z_sample_for_model, standard_z_sample
from . import actviz
from . import progress
from . import runningstats
from . import sampler

__all__ = [
    'dissect', 'ReverseNormalize',
    'ClassifierSegRunner', 'GeneratorSegRunner', 'ImageOnlySegRunner',
    'BrodenDataset', 'ScaleSegmentation', 'scatter_batch',
    'MultiSegmentDataset',
    'InstrumentedModel',
    'z_dataset_for_model', 'z_sample_for_model', 'standard_z_sample'
    'actviz',
    'progress',
    'runningstats',
    'sampler'
]