def __init__(self, splits=Defaults.splits, train_size=None, test_size=None, split_coord=Defaults.split_coord, stratification_coord=Defaults.stratification_coord, unique_split_values=Defaults.unique_split_values, random_state=Defaults.random_state): super().__init__() if train_size is None and test_size is None: train_size = self.Defaults.train_size self._stratified_split = StratifiedShuffleSplit( n_splits=splits, train_size=train_size, test_size=test_size, random_state=random_state) self._shuffle_split = ShuffleSplit(n_splits=splits, train_size=train_size, test_size=test_size, random_state=random_state) self._split_coord = split_coord self._stratification_coord = stratification_coord self._unique_split_values = unique_split_values self._logger = logging.getLogger(fullname(self))
def __init__(self, smooth_reg_weight=0.1, sparse_reg_weight=0.01, group_sparsity_weight=0.01, output_nonlin_smooth_weight=-1, b_norm=True, batch_size=256, _decay_rate=[300, 375, 400], max_epochs=440, init_lr=1e-4, *args, **kwargs): self.smooth_reg_weight = smooth_reg_weight self.sparse_reg_weight = sparse_reg_weight self.group_sparsity_weight = group_sparsity_weight self.b_norm = b_norm self._batch_size = batch_size self._decay_rate = _decay_rate self._max_epochs = max_epochs self._lr = init_lr assert output_nonlin_smooth_weight == -1, "Adding non lin not supported" self._graph = None self._lr_ph = None self._opt = None self._logger = logging.getLogger(fullname(self))
def __init__(self, order_dimensions=Defaults.order_dimensions, alignment_dim=Defaults.alignment_dim, repeat=Defaults.repeat): self._order_dimensions = order_dimensions self._alignment_dim = alignment_dim self._repeat = repeat self._logger = logging.getLogger(fullname(self))
def __init__(self, identifier, target_model_param, stimuli_model_param): self.current_task = None self.identifier = identifier self.target_model = target_model_param['target_model'] self.stimuli_model = stimuli_model_param['stimuli_model'] self.target_layer = target_model_param['target_layer'] self.stimuli_layer = stimuli_model_param['stimuli_layer'] self.search_image_size = stimuli_model_param['search_image_size'] self._logger = logging.getLogger(fullname(self))
def __init__(self, model_identifier, activations_model, layers, visual_degrees): """ :param model_identifier: this is separate from the container name because it only refers to the combination of (model, preprocessing), i.e. no mapping. """ self.model_identifier = model_identifier self._layer_scoring = LayerScores(model_identifier=model_identifier, activations_model=activations_model, visual_degrees=visual_degrees) self.layers = layers self._logger = logging.getLogger(fullname(self))
def __init__(self, *args, split_coord=Split.Defaults.split_coord, stratification_coord=Split.Defaults.stratification_coord, **kwargs): self._split_coord = split_coord self._stratification_coord = stratification_coord self._split = Split(*args, split_coord=split_coord, stratification_coord=stratification_coord, **kwargs) self._logger = logging.getLogger(fullname(self))
def __init__(self, get_activations, reset, identifier=False): """ :param identifier: an activations identifier for the stored results file. False to disable saving. :param reset: function to signal that a coherent stream of sentences is over. """ self._logger = logging.getLogger(fullname(self)) self.identifier = identifier self.get_activations = get_activations self.reset = reset self._stimulus_set_hooks = {} self._activations_hooks = {}
def _find_model_weights(model_name): _logger = logging.getLogger(fullname(TFSlimModel._find_model_weights)) framework_home = os.path.expanduser(os.getenv('CM_HOME', '~/.candidate_models')) weights_path = os.getenv('CM_TSLIM_WEIGHTS_DIR', os.path.join(framework_home, 'model-weights', 'slim')) model_path = os.path.join(weights_path, model_name) if not os.path.isdir(model_path): _logger.debug(f"Downloading weights for {model_name} to {model_path}") os.makedirs(model_path) s3.download_folder(f"slim/{model_name}", model_path) fnames = glob.glob(os.path.join(model_path, '*.ckpt*')) assert len(fnames) > 0, f"no checkpoint found in {model_path}" restore_path = fnames[0].split('.ckpt')[0] + '.ckpt' return restore_path
def _find_model_json(model_name): _logger = logging.getLogger(fullname(TFUtilsModel._find_model_json)) framework_home = os.path.expanduser(os.getenv('CM_HOME', '~/.candidate_models')) json_path = os.getenv('CM_TFUTILS_JSON_DIR', os.path.join(framework_home, 'model-jsons', 'tfutils')) model_path = os.path.join(json_path, model_name) if not os.path.isdir(model_path): _logger.debug(f"Downloading json for {model_name} to {model_path}") os.makedirs(model_path) s3.download_folder(f"model-jsons/{model_name}", model_path, bucket='brain-score-tfutils-models', region='us-west-1') fnames = glob.glob(os.path.join(model_path, '*.json*')) assert len(fnames) > 0, f"no json found in {model_path}" tnn_json = fnames[0].split('.json')[0] + '.json' return tnn_json
def __init__(self, splits=Split.Defaults.splits, split_coord=Split.Defaults.split_coord, stratification_coord=Split.Defaults.stratification_coord, train_size=None, test_size=None, seed=Split.Defaults.random_state): self._split_coord = split_coord self._stratification_coord = stratification_coord self._split = Split(splits=splits, split_coord=split_coord, stratification_coord=stratification_coord, train_size=train_size, test_size=test_size, random_state=seed) self._logger = logging.getLogger(fullname(self))
def __init__(self, splits=Split.Defaults.splits, train_size=None, test_size=None, split_coord=Split.Defaults.split_coord, stratification_coord=Split.Defaults.stratification_coord, unique_split_values=Split.Defaults.unique_split_values, random_state=Split.Defaults.random_state): super().__init__() self._split = Split(splits=splits, split_coord=split_coord, stratification_coord=stratification_coord, unique_split_values=unique_split_values, train_size=train_size, test_size=test_size, random_state=random_state) self._logger = logging.getLogger(fullname(self))
def __init__(self, ceil_score=None, assembly_name=None, identifier_suffix=""): self.human_score = Score([ceil_score, np.nan], coords={'aggregation': ['center', 'error']}, dims=['aggregation']) self._version = 1 self._identifier = 'klab.Zhang2018.ObjSearch-' + identifier_suffix self.parent = 'visual_search', self.paper_link = 'https://doi.org/10.1038/s41467-018-06217-x' self._assemblies = brainscore.get_assembly(assembly_name) self._stimuli = self._assemblies.stimulus_set self.fix = [[640, 512], [365, 988], [90, 512], [365, 36], [915, 36], [1190, 512], [915, 988]] self.max_fix = 6 self.data_len = 300 self._logger = logging.getLogger(fullname(self))
def __init__( self, init_lr=1e-4, max_epochs=40, zscore_feats=True, train_batch_size=64, eval_batch_size=240, activation=None, fc_weight_decay=0.463, # 1/(C_svc * num_objectome_imgs) = 1/(1e-3 * 2160), # based on https://stats.stackexchange.com/questions/216095/how-does-alpha-relate-to-c-in-scikit-learns-sgdclassifier fc_dropout=1.0, tol=1e-4, log_rate=5, gpu_options=None): """ mapping function class. :param train_batch_size: train batch size :param eval_batch_size: prediction batch size :param activation: what activation to use if any :param init_lr: initial learning rate :param zscore_feats: whether to zscore model features :param tol: tolerance - stops the optimization if reaches below tol :param fc_weight_decay: regularization coefficient for fully connected layers (inverse of sklearn C) :params fc_dropout: dropout parameter for fc layers :param log_rate: rate of logging the loss values (in epochs) """ self._train_batch_size = train_batch_size self._eval_batch_size = eval_batch_size self._zscore_feats = zscore_feats self._lr = init_lr self._tol = tol self._activation = activation self._fc_weight_decay = fc_weight_decay self._fc_dropout = fc_dropout self._max_epochs = max_epochs self._log_rate = log_rate self._gpu_options = gpu_options self._graph = None self._lr_ph = None self._opt = None self._scaler = None self._logger = logging.getLogger(fullname(self))
def __init__(self, ceil_score=None, assembly_name=None, identifier_suffix=""): self._logger = logging.getLogger(fullname(self)) self.human_score = Score([ceil_score, np.nan], coords={'aggregation': ['center', 'error']}, dims=['aggregation']) self._version = 1 self._identifier = 'klab.Zhang2018.VisualSearch-' + identifier_suffix self.parent = 'visual_search' self.paper_link = 'https://doi.org/10.1038/s41467-018-06217-x' self._assemblies = brainscore.get_assembly(assembly_name) self._stimuli = self._assemblies.stimulus_set self.max_fix = self._assemblies.fixation.values.shape[0] - 2 self.num_sub = np.max(self._assemblies.subjects.values) self.data_len = int(self._assemblies.presentation.values.shape[0] / self.num_sub) self.ior_size = 100
def __init__(self, splits=Defaults.splits, train_size=None, test_size=None, split_coord=Defaults.split_coord, stratification_coord=Defaults.stratification_coord, kfold=False, unique_split_values=Defaults.unique_split_values, random_state=Defaults.random_state): super().__init__() if train_size is None and test_size is None: train_size = self.Defaults.train_size if kfold: assert (train_size is None or train_size == self.Defaults.train_size) and test_size is None if stratification_coord: self._split = StratifiedKFold(n_splits=splits, shuffle=True, random_state=random_state) else: self._split = KFold(n_splits=splits, shuffle=True, random_state=random_state) else: if stratification_coord: self._split = StratifiedShuffleSplit(n_splits=splits, train_size=train_size, test_size=test_size, random_state=random_state) else: self._split = ShuffleSplit(n_splits=splits, train_size=train_size, test_size=test_size, random_state=random_state) self._split_coord = split_coord self._stratification_coord = stratification_coord self._unique_split_values = unique_split_values self._logger = logging.getLogger(fullname(self))
def __init__(self, init_lr=0.01, max_epochs=40, tol=0.1, batch_size=50, ls=.1, ld=.1, decay_rate=25, inits: Union[None, dict] = None, log_rate=10, gpu_options=None): """ mapping function class. :param batch_size: batch size :param init_lr: initial learning rate :param ls: regularization coefficient for spatial parameters (spatial convolution) :param ld: regularization coefficient for depth parameters (depth convolution) :param tol: tolerance - stops the optimization if reaches below tol :param max_epochs: maximum number of epochs to train :param inits: initial values for the mapping function parameters. A dictionary containing any of the following keys ['s_w', 'd_w', 'bias'] :param log_rate: rate of logging the loss values :param decay_rate: rate of decay for learning rate (#epochs) """ self._ld = ld self._ls = ls self._tol = tol self._batch_size = batch_size self._lr = init_lr self._max_epochs = max_epochs self._inits = inits self._log_rate = log_rate self._decay_rate = decay_rate self._gpu_options = gpu_options self._graph = None self._lr_ph = None self._opt = None self._logger = logging.getLogger(fullname(self))
def __init__(self, model_identifier, activations_model): self.model_identifier = model_identifier self._activations_model = activations_model self._logger = logging.getLogger(fullname(self))
def __init__(self, dividers=()): super(CartesianProduct, self).__init__() self._dividers = dividers or () self._logger = logging.getLogger(fullname(self))
def __init__(self, collapse_distractors, normalize=False, repetitions=2): super().__init__() self._collapse_distractors = collapse_distractors self._normalize = normalize self._repetitions = repetitions self._logger = logging.getLogger(fullname(self))
def __init__(self, model_identifier, activations_model, visual_degrees): self.model_identifier = model_identifier self._activations_model = activations_model self._visual_degrees = visual_degrees self._logger = logging.getLogger(fullname(self))