Пример #1
0
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
Пример #2
0
class TestConfig(TestCase):
    def setUp(self):
        self.config = Config()

    def test_append_to_log(self):
        self.fail()

    def test_get_log_filename_for_date(self):
        test_datetime = datetime.datetime(2014, 4, 17)
        result_filename = self.config.get_log_filename_for_date(test_datetime, 'c:/')
        self.assertEquals('c:/2014-04-17.log', result_filename)


    def test_get_last_log_line_for_today(self):
        self.fail()
    def test_get_last_log_line_for_file(self):
        last_line = self.config.get_last_log_line_for_file('2013_10_31.log')
        self.assertEquals(u'After timer implemented', last_line)
Пример #3
0
    def test_load(self):

        #Mock open to return the confi_data from file
        with patch.object(builtins,'open',mock_open(read_data=self.config_data)) as m:
            Config.load("test")

        self.assertEqual(Config.search_queries, ["test"])
        self.assertEqual(Config.follow_keywords,["test"])
        self.assertEqual(Config.scan_update_time, 1)
        self.assertEqual(Config.retweet_update_time, 1)
        self.assertEqual(Config.rate_limit_update_time, 1)
        self.assertEqual(Config.min_ratelimit, 1)
        self.assertEqual(Config.min_ratelimit_search, 1)
        self.assertEqual(Config.clear_queue_time, 1)
        self.assertEqual(Config.min_posts_queue, 1)
        self.assertEqual(Config.blocked_users_update_time, 1)
        self.assertEqual(Config.max_follows, 1)
        self.assertEqual(Config.consumer_key, "test")
        self.assertEqual(Config.consumer_secret, "test")
        self.assertEqual(Config.access_token_key, "test")
        self.assertEqual(Config.access_token_secret, "test")
Пример #4
0
    def test_load(self):

        #Mock open to return the confi_data from file
        with patch.object(builtins, 'open',
                          mock_open(read_data=self.config_data)) as m:
            Config.load("test")

        self.assertEqual(Config.search_queries, ["test"])
        self.assertEqual(Config.follow_keywords, ["test"])
        self.assertEqual(Config.scan_update_time, 1)
        self.assertEqual(Config.retweet_update_time, 1)
        self.assertEqual(Config.rate_limit_update_time, 1)
        self.assertEqual(Config.min_ratelimit, 1)
        self.assertEqual(Config.min_ratelimit_search, 1)
        self.assertEqual(Config.clear_queue_time, 1)
        self.assertEqual(Config.min_posts_queue, 1)
        self.assertEqual(Config.blocked_users_update_time, 1)
        self.assertEqual(Config.max_follows, 1)
        self.assertEqual(Config.consumer_key, "test")
        self.assertEqual(Config.consumer_secret, "test")
        self.assertEqual(Config.access_token_key, "test")
        self.assertEqual(Config.access_token_secret, "test")
Пример #5
0
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()
Пример #6
0
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'])
Пример #7
0
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)
Пример #8
0
def load_config(DOMAIN):
    CONFIG_PATH = "config/" + DOMAIN
    global config
    config = Config()
    config.load_from_file(CONFIG_PATH)
    return config, DEVICE
Пример #9
0
        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)
Пример #10
0
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]]
Пример #11
0
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']))
Пример #12
0
    with open(model_path, "rb") as f:
        # 恢复模型
        output_graph_def.ParseFromString(f.read())
        tf.import_graph_def(output_graph_def, name="")

        with tf.Session() as sess:
            tf.global_variables_initializer().run()
            # 获得名字为x_input、output的tensor
            image_input = sess.graph.get_tensor_by_name("image_input:0")
            print("image_input shape:", image_input.get_shape())

            keep_prob = sess.graph.get_tensor_by_name("keep_prob:0")
            kernel_res = sess.graph.get_tensor_by_name("kernel_res:0")
            output = sess.graph.get_tensor_by_name("output:0")

            config = Config()
            kernel = restore_kernel(config)
            # img_value = np.array([img_value])
            img_list = []
            for i in range(16):
                img_path = img_dir + class_index + "/" + str(i + 1) + ".jpg"
                img_value = img_prepare(img_path)
                img_list.append(img_value)

            result = sess.run(output,
                              feed_dict={
                                  image_input: img_list,
                                  keep_prob: 1.0,
                                  kernel_res: kernel
                              })  # 利用训练好的模型预测结果
            print('模型预测结果为:\n', result)
Пример #13
0
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)}))
Пример #14
0
 def setUp(self):
     self.config = Config()
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: