def __init__(self, directory, parts=None): world_size = tuple( next( clevr_util.images_iter(directory=directory, parts=parts, mode='train')).shape[:2]) self.question_size = 0 unique_answers = set() vocabulary = set() for _, question, _, answer in clevr_util.questions_iter( directory=directory, parts=parts, mode='train'): self.question_size = max(self.question_size, len(question)) vocabulary.update(question) assert len(answer) == 1 unique_answers.add(answer[0]) vocabularies = dict(language=sorted(vocabulary)) self.answers = sorted(unique_answers) self.answers.append('[UNKNOWN]') self.num_answers = len(self.answers) super(CLEVR, self).__init__(world_size=world_size, vectors=dict(question=self.question_size), vocabularies=vocabularies) self.clevr = { mode: clevr_util.clevr(directory=directory, parts=parts, mode=mode) for mode in ('train', 'validation', 'test') }
def __init__(self, directory, parts=None, pixel_noise_stddev=0.0): parts = parts.split(',') values = dict(world='world', world_model='model', question='alternatives(language)', question_length='alternatives(int)', question_model='alternatives(model)', answer='alternatives(language)', answer_length='alternatives(int)', alternatives='int') world_size = tuple( next( clevr_util.images_iter(directory=directory, parts=parts, mode='train')).shape[:2]) self.question_size = 0 self.answer_size = 0 vocabulary = set() for _, question, _, answer in clevr_util.questions_iter( directory=directory, parts=parts, mode='train'): self.question_size = max(self.question_size, len(question)) self.answer_size = max(self.answer_size, len(answer)) vocabulary.update(question) vocabulary.update(answer) vocabularies = dict(language=sorted(vocabulary)) super(CLEVR, self).__init__(values=values, world_size=world_size, pixel_noise_stddev=pixel_noise_stddev, vectors=dict(question=self.question_size, answer=self.answer_size), vocabularies=vocabularies) self.clevr = { mode: clevr_util.clevr(directory=directory, parts=parts, mode=mode) for mode in ('train', 'validation', 'test') }
def __init__(self, directory, parts=None): world_size = tuple(next(clevr_util.images_iter(directory=directory, parts=parts, mode='train')).shape[:2]) self.question_size = 0 self.answer_size = 0 vocabulary = set() for _, question, _, answer in clevr_util.questions_iter(directory=directory, parts=parts, mode='train'): self.question_size = max(self.question_size, len(question)) self.answer_size = max(self.answer_size, len(answer)) vocabulary.update(question) vocabulary.update(answer) vocabularies = dict(language=sorted(vocabulary)) super(CLEVR, self).__init__(world_size=world_size, vectors=dict(question=self.question_size, answer=self.answer_size), vocabularies=vocabularies) self.clevr = {mode: clevr_util.clevr(directory=directory, parts=parts, mode=mode) for mode in ('train', 'validation', 'test')}
def __init__(self, directory, parts=None): world_size = tuple(next(clevr_util.images_iter(directory=directory, parts=parts, mode='train')).shape[:2]) self.question_size = 0 self.answer_size = 0 words = set() for _, question, _, answer in clevr_util.questions_iter(directory=directory, parts=parts, mode='train'): question = util.string2tokens(string=question) answer = util.string2tokens(string=answer) self.question_size = max(self.question_size, len(question)) self.answer_size = max(self.answer_size, len(answer)) words.update(question) words.update(answer) words = sorted(words) super(CLEVRDataset, self).__init__(world_size=world_size, vectors=dict(question=self.question_size, answer=self.answer_size), words=words) self.clevr = {mode: clevr_util.clevr(directory=directory, parts=parts, mode=mode) for mode in ('train', 'validation', 'test')}
def __init__(self, directory, parts=None, pixel_noise_stddev=None): values = dict(world='world', world_model='model', question='alternatives(language)', question_length='alternatives(int)', question_model='alternatives(model)', answer='alternatives(int)', alternatives='int') if parts is not None: parts = parts.split(',') world_size = tuple( next( clevr_util.images_iter(directory=directory, parts=parts, mode='train')).shape[:2]) self.question_size = 0 unique_answers = set() vocabulary = set() for _, question, _, answer in clevr_util.questions_iter( directory=directory, parts=parts, mode='train'): self.question_size = max(self.question_size, len(question)) vocabulary.update(question) assert len(answer) == 1 unique_answers.add(answer[0]) vocabularies = dict(language=sorted(vocabulary)) self.answers = sorted(unique_answers) self.answers.append('[UNKNOWN]') self.num_answers = len(self.answers) super(ClevrDataset, self).__init__(values=values, world_size=world_size, pixel_noise_stddev=pixel_noise_stddev, vectors=dict(question=self.question_size), vocabularies=vocabularies) self.clevr = { mode: clevr_util.clevr(directory=directory, parts=parts, mode=mode) for mode in ('train', 'validation', 'test') }