Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cognitive/info_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ def get_examples(self) -> Tuple[List, Dict, Dict]:
}
return task_info_dict, compo, memory_trace_info

def write_trial_instance(self, write_fp: str, img_size=224, fixation_cue=True) -> None:
def write_trial_instance(self, write_fp: str, img_size=224, fixation_cue=True, train = True) -> None:
frames_fp = os.path.join(write_fp, 'frames')
if os.path.exists(frames_fp):
shutil.rmtree(frames_fp)
os.makedirs(frames_fp)

objset = self.frame_info.objset
for i, (epoch, frame) in enumerate(zip(sg.render(objset, img_size), task_info.frame_info)):
for i, (epoch, frame) in enumerate(zip(sg.render(objset, img_size, train = train), self.frame_info)):
if fixation_cue:
if not any('ending' in description for description in frame.description):
sg.add_fixation_cue(epoch)
Expand Down
10 changes: 5 additions & 5 deletions cognitive/stim_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def render_static_obj(canvas, obj, img_size, train=True):
canvas[x_offset:x_end, y_offset:y_end] = shape_net_obj


def render_obj(canvas, obj, img_size):
def render_obj(canvas, obj, img_size, train = True):
"""Render a single object.

Args:
Expand All @@ -819,9 +819,9 @@ def render_obj(canvas, obj, img_size):
img_size: int, image size.
"""
if isinstance(obj, StaticObject):
render_static_obj(canvas, obj, img_size)
render_static_obj(canvas, obj, img_size, train = train)
else:
render_static_obj(canvas, obj.to_static()[0], img_size)
render_static_obj(canvas, obj.to_static()[0], img_size, train = train)


def render_static(objlists, img_size=224, save_name=None):
Expand Down Expand Up @@ -879,7 +879,7 @@ def render_static(objlists, img_size=224, save_name=None):
return movie


def render(objsets, img_size=224, save_name=None):
def render(objsets, img_size=224, save_name=None, train = True):
"""Render a movie by epoch.

Args:
Expand Down Expand Up @@ -907,7 +907,7 @@ def render(objsets, img_size=224, save_name=None):

subset = objset.select_now(epoch_now)
for obj in subset:
render_obj(canvas, obj, img_size)
render_obj(canvas, obj, img_size, train = train)
i_frame += 1

if save_name is not None:
Expand Down
6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ def generate_dataset(
validation_examples -= 1
fname = os.path.join(validation_fname, f'{i}')

info.write_trial_instance(fname, img_size, fixation_cue)
# xlei: pass train/val parameter to write trial_instances
if i < int(total_examples * train):
info.write_trial_instance(fname, img_size, fixation_cue, train = True)
else:
info.write_trial_instance(fname, img_size, fixation_cue, train=False)
i += 1
else:
i = 0
Expand Down