Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from brain-score/ignore-local-path
Browse files Browse the repository at this point in the history
when possible, ignore local part of stimuli paths to align across machines
  • Loading branch information
mschrimpf authored Jul 20, 2019
2 parents 70520eb + 30a5ca8 commit fcde853
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions model_tools/activations/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import copy
import os

import functools
import logging
from collections import OrderedDict
Expand Down Expand Up @@ -108,7 +110,6 @@ def _get_activations_batched(self, paths, layers, batch_size):
layer_activations = None
for batch_start in tqdm(range(0, len(paths), batch_size), unit_scale=batch_size, desc="activations"):
batch_end = min(batch_start + batch_size, len(paths))
self._logger.debug('Batch %d->%d/%d', batch_start, batch_end, len(paths))
batch_inputs = paths[batch_start:batch_end]
batch_activations = self._get_batch_activations(batch_inputs, layer_names=layers, batch_size=batch_size)
for hook in self._batch_activations_hooks.copy().values(): # copy to avoid handle re-enabling messing with the loop
Expand Down Expand Up @@ -217,9 +218,21 @@ def apply_change(layer_values):
return results


def lstrip_local(path):
parts = path.split(os.sep)
try:
start_index = parts.index('.brainio')
except ValueError: # not in list -- perhaps custom directory
return path
path = os.sep.join(parts[start_index:])
return path


def attach_stimulus_set_meta(assembly, stimulus_set):
stimulus_paths = [stimulus_set.get_image(image_id) for image_id in stimulus_set['image_id']]
assert all(assembly['stimulus_path'].values == stimulus_paths)
stimulus_paths = [lstrip_local(path) for path in stimulus_paths]
assembly_paths = [lstrip_local(path) for path in assembly['stimulus_path'].values]
assert (np.array(assembly_paths) == np.array(stimulus_paths)).all()
assembly['stimulus_path'] = stimulus_set['image_id'].values
assembly = assembly.rename({'stimulus_path': 'image_id'})
for column in stimulus_set.columns:
Expand Down

0 comments on commit fcde853

Please sign in to comment.