def get_dnn_cfg(dnn_fname): """ Construct a minimum required NetworkConfig given a model file """ model_data = io.json_load(dnn_fname) cfg = NetworkConfig() cfg.hidden_layers_sizes = [] i = 0 while 'W{}'.format(i) in model_data: W_shape = string_2_array(model_data['W{}'.format(i)]).shape # Currently factored layer can only be the first hidden layer # TODO: change this! if i == 0: if 'side_W{}_0'.format(i) in model_data: factored_cfg = FactoredConfig() j = 0 while 'side_b{}_{}'.format(i, j) in model_data: assert 'side_W{}_{}'.format(i, j) in model_data side_W_shape = string_2_array(model_data['side_W{}_{}'.format(i, j)]).shape if j == 0: factored_cfg.n_in_main = W_shape[0] factored_cfg.n_in_side = side_W_shape[0] # NOTE: this assumes that main and secondary features # are disjoint, but this is not required by the model. # TODO: find a way to relax this assumption. cfg.n_ins = W_shape[0] + side_W_shape[0] factored_cfg.side_layers.append(side_W_shape[1]) j += 1 cfg.factored_cfg = factored_cfg else: cfg.n_ins = W_shape[0] if 'W{}'.format(i + 1) in model_data: cfg.hidden_layers_sizes.append(W_shape[1]) else: cfg.n_outs = W_shape[1] i += 1 return cfg