def build_processors(self): print('Tiki : Initializing : Building - Text Processors') with open('/final/data/pythia.yaml') as f: config = yaml.load(f, Loader=yaml.FullLoader) config = ConfigNode(config) config.training_parameters.evalai_inference = True # Remove warning registry.register('config', config) self.config = config vqa_config = config.task_attributes.vqa.dataset_attributes.vqa2 text_processor_config = vqa_config.processors.text_processor answer_processor_config = vqa_config.processors.answer_processor text_processor_config.params.vocab.vocab_file = '/final/data/vocabulary_100k.txt' answer_processor_config.params.vocab_file = '/final/data/answers_vqa.txt' self.text_processor = VocabProcessor(text_processor_config.params) self.answer_processor = VQAAnswerProcessor( answer_processor_config.params) registry.register('vqa2_text_processor', self.text_processor) registry.register('vqa2_answer_processor', self.answer_processor) registry.register('vqa2_num_final_outputs', self.answer_processor.get_vocab_size())
def _init_processors(self): with open(os.path.join(BASE_VQA_DIR_PATH, "model_data/pythia.yaml")) as f: config = yaml.load(f) config = ConfigNode(config) # Remove warning config.training_parameters.evalai_inference = True registry.register("config", config) self.config = config vqa_config = config.task_attributes.vqa.dataset_attributes.vqa2 text_processor_config = vqa_config.processors.text_processor answer_processor_config = vqa_config.processors.answer_processor text_processor_config.params.vocab.vocab_file = os.path.join( BASE_VQA_DIR_PATH, "model_data/vocabulary_100k.txt" ) answer_processor_config.params.vocab_file = os.path.join( BASE_VQA_DIR_PATH, "model_data/answers_vqa.txt" ) # Add preprocessor as that will needed when we are getting questions from user self.text_processor = VocabProcessor(text_processor_config.params) self.answer_processor = VQAAnswerProcessor(answer_processor_config.params) registry.register("vqa2_text_processor", self.text_processor) registry.register("vqa2_answer_processor", self.answer_processor) registry.register( "vqa2_num_final_outputs", self.answer_processor.get_vocab_size() )
def __init__(self, use_constrained=False): super(PythiaCaptioner, self).__init__() # load configuration file with open(config_file) as f: config = yaml.load(f) config = ConfigNode(config) self.use_constrained = use_constrained # TODO: not sure what these two lines really means config.training_parameters.evalai_inference = True registry.register("config", config) self.config = config captioning_config = config.task_attributes.captioning.dataset_attributes.coco text_processor_config = captioning_config.processors.text_processor caption_processor_config = captioning_config.processors.caption_processor text_processor_config.params.vocab.vocab_file = vocab_file caption_processor_config.params.vocab.vocab_file = vocab_file self.text_processor = VocabProcessor(text_processor_config.params) self.caption_processor = CaptionProcessor( caption_processor_config.params) registry.register("coco_text_processor", self.text_processor) registry.register("coco_caption_processor", self.caption_processor) self.model = self._build_model()
def __init__(self, use_constrained=False): super(PythiaCaptioner, self).__init__() # load configuration file with open(config_file) as f: config = yaml.load(f) config = ConfigNode(config) self.use_constrained = use_constrained # the following blocks of code read some configuration # parameter in Pythia config.training_parameters.evalai_inference = True registry.register("config", config) self.config = config captioning_config = config.task_attributes.captioning.dataset_attributes.coco text_processor_config = captioning_config.processors.text_processor caption_processor_config = captioning_config.processors.caption_processor # text_processor and caption_processor are used to pre-process the text text_processor_config.params.vocab.vocab_file = vocab_file caption_processor_config.params.vocab.vocab_file = vocab_file self.text_processor = VocabProcessor(text_processor_config.params) self.caption_processor = CaptionProcessor( caption_processor_config.params) registry.register("coco_text_processor", self.text_processor) registry.register("coco_caption_processor", self.caption_processor) self.model = self._build_model()
def _init_processors(self): with open(model_yaml) as f: config = yaml.load(f) config = ConfigNode(config) # Remove warning config.training_parameters.evalai_inference = True registry.register("config", config) self.config = config captioning_config = config.task_attributes.captioning.dataset_attributes.coco # captioning_config = config.task_attributes.captioning.dataset_attributes.youcookII text_processor_config = captioning_config.processors.text_processor caption_processor_config = captioning_config.processors.caption_processor # print("DEBUG captioning_config:", captioning_config) # print("DEBUG text_processor_config:", text_processor_config) # print("DEBUG caption_processor_config:", caption_processor_config) text_processor_config.params.vocab.vocab_file = "content/model_data/vocabulary_captioning_thresh5.txt" caption_processor_config.params.vocab.vocab_file = "content/model_data/vocabulary_captioning_thresh5.txt" self.text_processor = VocabProcessor(text_processor_config.params) self.caption_processor = CaptionProcessor(caption_processor_config.params) # print("DEBUG text_processor:", self.text_processor) # print("DEBUG caption_processor:", self.caption_processor) registry.register("coco_text_processor", self.text_processor) registry.register("coco_caption_processor", self.caption_processor)
def __init__(self): config_file = 'model_data/butd.yaml' vocab_file = 'model_data/vocabulary_captioning_thresh5.txt' with open(config_file) as f: config = yaml.load(f) config = ConfigNode(config) captioning_config = config.task_attributes.captioning.dataset_attributes.coco text_processor_config = captioning_config.processors.text_processor text_processor_config.params.vocab.vocab_file = vocab_file text_processor = VocabProcessor(text_processor_config.params) self.vocab = text_processor.vocab
def init_processors(caption_config: Dict, butd_config: Dict): """Build the caption and text processors. """ captioning_config = butd_config.task_attributes.captioning \ .dataset_attributes.coco text_processor_config = captioning_config.processors.text_processor caption_processor_config = captioning_config.processors \ .caption_processor vocab_file_path = caption_config["text_caption_processor_vocab_txt"] text_processor_config.params.vocab.vocab_file = vocab_file_path caption_processor_config.params.vocab.vocab_file = vocab_file_path text_processor = VocabProcessor(text_processor_config.params) caption_processor = CaptionProcessor(caption_processor_config.params) registry.register("coco_text_processor", text_processor) registry.register("coco_caption_processor", caption_processor) return caption_processor, text_processor
def _init_processors(self): with open("model_data/butd.yaml") as f: config = yaml.load(f) config = ConfigNode(config) config.training_parameters.evalai_inference = True registry.register("config", config) self.config = config captioning_config = config.task_attributes.captioning.dataset_attributes.coco text_processor_config = captioning_config.processors.text_processor caption_processor_config = captioning_config.processors.caption_processor text_processor_config.params.vocab.vocab_file = "model_data/vocabulary_captioning_thresh5.txt" caption_processor_config.params.vocab.vocab_file = "model_data/vocabulary_captioning_thresh5.txt" self.text_processor = VocabProcessor(text_processor_config.params) self.caption_processor = CaptionProcessor(caption_processor_config.params) registry.register("coco_text_processor", self.text_processor) registry.register("coco_caption_processor", self.caption_processor)
#!/usr/bin/env python3 import yaml from pythia.utils.configuration import ConfigNode from pythia.tasks.processors import VocabProcessor, VQAAnswerProcessor from torchvision import models if __name__ == '__main__': resnet152 = models.resnet152(pretrained=True) with open('/final/data/pythia.yaml') as f: config = yaml.load(f, Loader=yaml.FullLoader) config = ConfigNode(config) vqa_config = config.task_attributes.vqa.dataset_attributes.vqa2 text_processor_config = vqa_config.processors.text_processor answer_processor_config = vqa_config.processors.answer_processor text_processor_config.params.vocab.vocab_file = '/final/data/vocabulary_100k.txt' answer_processor_config.params.vocab_file = '/final/data/answers_vqa.txt' text_processor = VocabProcessor(text_processor_config.params) answer_processor = VQAAnswerProcessor(answer_processor_config.params)