def main(img_dir, img_name, classes): config = Config() config.batch_size = 1 config.num_classes = 2 result = {} for index in classes: result[index] = predict(img_dir + img_name, index, config) print(result) return result
class api: scope = "https://www.googleapis.com/auth/spreadsheets" store = file.Storage("token.json") creds = store.get() if not creds or creds.invalid: flow = client.flow_from_clientsecrets('credentials.json', scope) creds = tools.run_flow(flow, store) service = build('sheets', 'v4', http=creds.authorize(Http())) conf = Config() sheets = Sheets(conf.spreadsheet_ID, conf.google_API_key) sheet_id = conf.sheet_id sheet_names = sheets.sheet_names value_request = service.spreadsheets().values()
server_config = { "port": 5001, "reader": WebNLGDataReader, "planner": NaivePlanner( WeightedProductOfExperts([ RelationDirectionExpert, GlobalDirectionExpert, SplittingTendenciesExpert, RelationTransitionsExpert ])) } dataset_name = server_config["reader"].DATASET main_config = Config(reader=server_config["reader"], planner=server_config["planner"]) base_path = os.path.dirname(os.path.abspath(__file__)) def server(pipeline_res, host, port, debug=True): app = Flask(__name__) CORS(app) # @app.route('/', methods=['GET']) # @app.route('/index.html', methods=['GET']) # def root(): # print("got to root") # return app.send_static_file('static/index.html') @app.route('/graphs', methods=['GET'])
import sys sys.path.insert(0, '../../filling_level/vggish/') # nopep8 from main import Config, run_kfold, get_cmd_args from time import localtime, strftime # import argparse if __name__ == "__main__": # Reproduce the best experiment # if True, will use the pre-trained model and make predictions, if False, will train the model use_pretrained = True exp_name = 200903163404 cfg = Config() cfg.load_from(path=f'./predictions/{exp_name}/cfg.txt') # replacing the time with the old_time + current_time such that there is no collision if use_pretrained: cfg.init_time = exp_name else: cfg.init_time = f'{cfg.init_time}_{strftime("%y%m%d%H%M%S", localtime())}' # Expected average of Best Metrics on Each Valid Set: 0.912957 @ 200903163404 run_kfold(cfg, use_pretrained, get_cmd_args().predict_on_private) # Experiment with other parameters # cfg = Config() # cfg.assign_variable('task', 'ftype') # cfg.assign_variable('output_dim', 4) # cfg.assign_variable('model_type', 'GRU') # cfg.assign_variable('bi_dir', False) # cfg.assign_variable('device', 'cuda:0') # cfg.assign_variable('data_root', '../../filling_level/vggish/vggish_features') # cfg.assign_variable('batch_size', 64) # cfg.assign_variable('input_dim', 128)
def load_config(DOMAIN): CONFIG_PATH = "config/" + DOMAIN global config config = Config() config.load_from_file(CONFIG_PATH) return config, DEVICE
for idx in range(len(rev_outputs[1][0])): print('*' * 20, 'pos sample', '*' * 20, file=fw) print('[gold]', gold_text[1][idx], file=fw) print('[raw 1.0]', raw_output[1][idx], file=fw) for i, r in enumerate(ratios): print(f'[rev {1-r: .1f}]', rev_outputs[1][i][idx], file=fw) print('[ref ]', ref_text[1][idx], file=fw) print('*' * 20, '********', '*' * 20, file=fw) model_F.train() if __name__ == '__main__': config = Config() config.save_folder = config.save_path + '/' + str(time.strftime('%b%d%H%M%S', time.localtime())) os.makedirs(config.save_folder) os.makedirs(config.save_folder + '/ckpts') print('Save Path:', config.save_folder) train_iters, dev_iters, test_iters, vocab = load_dataset(config) # print(len(vocab)) # for batch in test_iters: # text = tensor2text(vocab, batch[0]) # print('\n'.join(text)) # print(batch.label) # break model_F = StyleTransformer(config, vocab).to(config.device)
image_validate=image_all[index_validate] yield_validate=yield_all[index_validate] s = 'H-32|C-9|lstm_h-128|B-2|dense-64|lstm_conv_filters-64|model_type-conv_lstm|keep_prob-0.5|L-1|conv_type-valid|dataset-standard' # s = { # 'H': 32, # 'model_type': 'lstm', # 'C': 9, # 'B': 2 # } c = Config(s) model = LSTM(c, regression=True) os.environ['CUDA_VISIBLE_DEVICES'] = '0' # Or whichever device you would like to use gpu_options = tf.GPUOptions(allow_growth=True) saver = tf.train.Saver() with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, allow_soft_placement=True)) as sess: sess.run(tf.global_variables_initializer()) batch_size = 2 for epoch in range(10): i = 0 epoch_loss = 0 while i + batch_size < len(image_all): lengths = [len(x) for x in image_all[i: i + batch_size]]
from db_adapters import InfluxDBAdapter from main import Config adapter = InfluxDBAdapter(Config('conf.ini')) for service in adapter.get_service_statuses(): print("Service %s was down approximately %d seconds which are %.1f" "%% of total uptime" % (service['service'], service['srv_downtime'], (100.0 * service['srv_downtime']) / service['total_uptime'])) for address in adapter.get_instance_statuses(): print("Address %s was unreachable approximately %.1f second which are " "%.1f %% of total uptime" % (address['address'], address['failed'], (100.0 * address['failed']) / address['total_time']))
PlanPipeline = Pipeline() PlanPipeline.enqueue("train-planner", "Train Planner", TrainPlannerPipeline) PlanPipeline.enqueue("test-corpus", "Pre-process test data", TestingPreProcessPipeline) ExperimentsPipeline = Pipeline() ExperimentsPipeline.enqueue("pre-process", "Pre-process training data", TrainingPreProcessPipeline) # Train all planners # # Naive Planner ExperimentsPipeline.enqueue( "naive-planner", "Train Naive Planner", PlanPipeline.mutate( {"config": Config(reader=WebNLGDataReader, planner=naive_planner)})) # # Neural Planner ExperimentsPipeline.enqueue( "neural-planner", "Train Neural Planner", PlanPipeline.mutate( {"config": Config(reader=WebNLGDataReader, planner=neural_planner)})) # REG # # Bert REG ExperimentsPipeline.enqueue( "naive-reg", "Train Naive Referring Expressions Generator", REGPipeline.mutate({"config": Config(reg=NaiveREG)})) # # Naive REG ExperimentsPipeline.enqueue( "bert-reg", "Train BERT Referring Expressions Generator", REGPipeline.mutate({"config": Config(reg=BertREG)}))
from __future__ import annotations import math import datetime as dt import numpy as np from abc import ABC, abstractmethod, abstractproperty from constants import * from interfaces import GeneratorInterface from main import Config CONFIG = Config().setup() class IdGenerator(GeneratorInterface): def __init__(self, m: int, a: int, c: int, seed: int) -> None: self.modulus = m self.multiplier = a self.increment = c self.seed = seed def generate_value(self) -> int: self.seed = (self.multiplier * self.seed + self.increment) % self.modulus return self.seed class SideGenerator(GeneratorInterface): def __init__(self, m: int, a: int, c: int) -> None: