File size: 2,001 Bytes
92f0e98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'''
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('datasets/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)
'''

__all__ = [
	'actviz',
	'autoeval',
	'bargraph',
	'broden',
	'customnet',
	'easydict',
	'encoder_loss',
	'encoder_net',
	'evalablate',
	'frechet_distance',
	'fsd',
	'fullablate',
	'imgsave',
	'imgviz',
	'invert',
	'LBFGS',
	'make_z_dataset',
	'modelconfig',
	'multilayer_graph',
	'nethook',
	'oldalexnet',
	'oldresnet152',
	'oldvgg16',
	'optimize_residuals',
	'optimize_z_lbfgs',
	'parallelfolder',
	'pbar',
	'pidfile',
	'plotutil',
	'proggan',
	'renormalize',
	'runningstats',
	'samplegan',
	'sampler',
	'segdata',
	'segmenter',
	'segviz',
	'setting',
	'show',
	'statedict',
	'tally',
	'upsample',
	'workerpool',
	'zdataset',
]