MCPcopy Create free account
hub / github.com/CSAILVision/gandissect / run_command

Function run_command

netdissect/aceoptimize.py:73–162  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

71 run_command(args)
72
73def run_command(args):
74 verbose_progress(True)
75 progress = default_progress()
76 classname = args.classname # 'door'
77 layer = args.layer # 'layer4'
78 num_eval_units = 20
79
80 assert os.path.isfile(os.path.join(args.outdir, 'dissect.json')), (
81 "Should be a dissection directory")
82
83 if args.variant is None:
84 args.variant = 'ace'
85
86 if args.l2_lambda != 0.005:
87 args.variant = '%s_reg%g' % (args.variant, args.l2_lambda)
88
89 cachedir = os.path.join(args.outdir, safe_dir_name(layer), args.variant,
90 classname)
91
92 if pidfile_taken(os.path.join(cachedir, 'lock.pid'), True):
93 sys.exit(0)
94
95 # Take defaults for model constructor etc from dissect.json settings.
96 with open(os.path.join(args.outdir, 'dissect.json')) as f:
97 dissection = EasyDict(json.load(f))
98 if args.model is None:
99 args.model = dissection.settings.model
100 if args.pthfile is None:
101 args.pthfile = dissection.settings.pthfile
102 if args.segmenter is None:
103 args.segmenter = dissection.settings.segmenter
104 # Default segmenter class
105 if args.segmenter is None:
106 args.segmenter = ("netdissect.segmenter.UnifiedParsingSegmenter(" +
107 "segsizes=[256], segdiv='quad')")
108
109 if (not args.no_cache and
110 os.path.isfile(os.path.join(cachedir, 'snapshots', 'epoch-%d.npy' % (
111 args.train_epochs - 1))) and
112 os.path.isfile(os.path.join(cachedir, 'report.json'))):
113 print('%s already done' % cachedir)
114 sys.exit(0)
115
116 os.makedirs(cachedir, exist_ok=True)
117
118 # Instantiate generator
119 model = create_instrumented_model(args, gen=True, edit=True,
120 layers=[args.layer])
121 if model is None:
122 print('No model specified')
123 sys.exit(1)
124 # Instantiate segmenter
125 segmenter = autoimport_eval(args.segmenter)
126 labelnames, catname = segmenter.get_label_and_category_names()
127 classnum = [i for i, (n, c) in enumerate(labelnames) if n == classname][0]
128 num_classes = len(labelnames)
129 with open(os.path.join(cachedir, 'labelnames.json'), 'w') as f:
130 json.dump(labelnames, f, indent=1)

Callers 1

mainFunction · 0.70

Calls 15

verbose_progressFunction · 0.90
default_progressFunction · 0.90
safe_dir_nameFunction · 0.90
pidfile_takenFunction · 0.90
EasyDictClass · 0.90
autoimport_evalFunction · 0.90
initial_ablationFunction · 0.85

Tested by

no test coverage detected