def __init__(self, __C): self.__C = __C print('Loading training set ........') self.dataset = DataSet(__C) # img_feat, ques_ix, ans self.dataset_eval = None if __C.EVAL_EVERY_EPOCH: # EVAL_EVERY_EPOCH = TRUE __C_eval = copy.deepcopy(__C) setattr(__C_eval, 'RUN_MODE', 'val') print('Loading validation set for per-epoch evaluation ........') self.dataset_eval = DataSet(__C_eval)
def __init__(self, __C): self.__C = __C print('Loading dataset ........') self.dataset = DataSet(__C) # If trigger the evaluation after every epoch # Will create a new cfgs with RUN_MODE = 'val' self.dataset_eval = None if __C.EVAL_EVERY_EPOCH: __C_eval = copy.deepcopy(__C) setattr(__C_eval, 'RUN_MODE', 'val') print('Loading eval every epoch dataset ........') self.dataset_eval = DataSet(__C_eval)
def __init__(self, __C): self.__C = __C print('Loading training set ........') #1.1加载训练数据集 self.dataset = DataSet(__C) #1. 执行完load_data,返回此处 #2.1 评估数据集设为None self.dataset_eval = None #EVAL_EVERY_EPOCH:设置为true进行脱机评估 if __C.EVAL_EVERY_EPOCH: __C_eval = copy.deepcopy(__C) #设置RUN_MODE = train setattr(__C_eval, 'RUN_MODE', 'train') #为每个epoch评估加载验证集,因为内存有限,此处我将val改成了train print('Loading validation set for per-epoch evaluation ........') #2.2 加载评估数据集(验证集,在评估方法上调用验证集数据集) self.dataset_eval = DataSet(__C_eval)
def __init__(self, __C): self.__C = __C print('Loading training set ........') self.dataset = DataSet(__C) self.dataset_eval = None if __C.EVAL_EVERY_EPOCH: __C_eval = copy.deepcopy(__C) setattr(__C_eval, 'RUN_MODE', 'val') print('Loading validation set for per-epoch evaluation ........') self.dataset_eval = DataSet(__C_eval) #self.h_classifier = HierarchicClassification(__C) self.writer = SummaryWriter( log_dir=f'./results/tensorboard/{self.__C.VERSION}')
def __init__(self, __C): self.__C = __C print('========== Loading training set ........') if self.__C.RUN_MODE == 'show': i = int(input('input the image id: ')) q = input('input the question: ') # qid = int(input('input the question id: ')) qid = 1 self.dataset = DataSet4Show(__C, i, q, qid) else: self.dataset = DataSet(__C) self.dataset_eval = None if __C.EVAL_EVERY_EPOCH: __C_eval = copy.deepcopy(__C) setattr(__C_eval, 'RUN_MODE', 'val') print( '========== Loading validation set for per-epoch evaluation ........' ) self.dataset_eval = DataSet(__C_eval)
def main(): """Visual Qustion Answering Using Machine Learning and Streamlit """ __C = Cfgs() args = parse_args() args_dict = __C.parse_to_dict(args) cfg_file = "cfgs/{}_model.yml".format(args.MODEL) with open(cfg_file, 'r') as f: yaml_dict = yaml.load(f) args_dict = {**yaml_dict, **args_dict} __C.add_args(args_dict) __C.proc() print('Hyper Parameters:') print(__C) st.title("VQA tool using Streamlit") html_temp = """ <div style="background-color:tomato;padding:10px"> <h2 style="color:white;text-align:center;">ViPyKube ML App </h2> </div> """ st.markdown(html_temp, unsafe_allow_html=True) images = [] st.sidebar.title("Image selection and Question") button = st.sidebar.radio( 'Randomly generate images', ('With predefined questons', 'With custom question')) #while True: img_path_list = [] for x in range(0, 10): name = random.choice(os.listdir('./datasets/coco_extract/images')) print(str(name)) name = './datasets/coco_extract/images/' + name image = Image.open(name) img_path_list.append(name) images.append(image) image_iterator = paginator("Select a sunset page", images) indices_on_page, images_on_page = map(list, zip(*image_iterator)) st.image(images_on_page, width=200, caption=indices_on_page) pick_img = st.sidebar.selectbox("Which image?", [x for x in range(1, len(images))]) imp_path = img_path_list[int(pick_img)] print("chosen image ", imp_path) image = Image.open(imp_path) st.header("Selected Image") st.image(image) img_id = imp_path[44:-4] for ix in range(len(img_id)): if img_id[ix] != "0": img_id = img_id[ix:] print(img_id) break q_list = [] if button == "With predefined questons": pass elif button == "With custom question": question = st.sidebar.text_input("What is your question?") q_list = [{ "image_id": int(img_id), "question": question, "question_id": 1 }] start_eval = st.sidebar.button('Get the answer!') if start_eval: print('Loading testing set ........') dataset = DataSet(__C, q_list, imp_path[31:], img_id) eval(__C, dataset, valid=True)