コード例 #1
0
def getAdministratorInfo():
    new = False  #boolean to allow for using new/load old data
    socketChat = False  #boolean to allow for socket convo

    adminIn = input(
        "Would you like to train the agent on new data/create a new agent? (y/n) "
    )
    #adminIn = 'y'

    if adminIn == 'y':
        new = True

    if new:
        data.read()
        config.createModel()
        model.create(config.training, config.output)
        print("Model created")
    else:
        data.load()
        config.createModel()
        model.load()
        print("Model loaded")

    socket = input(
        "Would you like to watch a conversation with another chatbot? (y/n) ")

    if socket == 'y':
        socketChat = True

    if socketChat:
        config.socketchat = True
    else:
        config.socketchat = False
コード例 #2
0
 def __init__(self):
     super().__init__()
     self.cache = CacheML(self.disk)
     self.ts = 0
     self.accbmps_proc = {}
     self.accbmp = AccBmp()
     model.load()
コード例 #3
0
ファイル: controller.py プロジェクト: jsarraga/week1
def login():
    model.load()
    account = view.get_acct()
    pin = view.get_pin()
    if pin == model.pin_check(account, pin):
        mainmenu(account)
    else:
        view.bad_input()
コード例 #4
0
def run():
    model.load()
    while True:
        user_account = login_menu(
        )  # returns the logged in user or None for quit
        if user_account == None:  # login menu returns None if 'quit' is selected
            break
        else:
            main_menu(
                user_account
            )  # when the user exits the main menu they will go back to login
コード例 #5
0
ファイル: controller.py プロジェクト: jsarraga/week1
def create_account():
    while True:
        model.load()
        view.create_account()
        account = random.randint(1, 10000)
        first_name = view.first_name()
        last_name = view.last_name()
        create_pin = view.create_pin()
        model.create_acct(account, first_name, last_name, create_pin)
        view.new_account(account)
        model.save()
        return
コード例 #6
0
def eval(args):
  # load model
  model = get_model(args, 0, args.r, from_ckpt=True, train=False)
  model.load(args.logname) # from default checkpoint

  if args.wav_file_list:
    with open(args.wav_file_list) as f:
      for line in f:
        try:
          print line.strip()
          upsample_wav(line.strip(), args, model)
        except EOFError:
          print 'WARNING: Error reading file:', line.strip()
コード例 #7
0
def run():
    model.load()

    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    bytes2boxes_pb2_grpc.add_Bytes2BoxesServicer_to_server(
        Bytes2Boxes(), server)
    server.add_insecure_port('[::]:%i' % args.port)
    server.start()
    print('started image2boxes service on port %i' % args.port)
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)
コード例 #8
0
 def create_model(self):
     import model, rnn
     if 'model_path' in self.train_info and os.path.exists(
             self.train_info['model_path']):
         model = model.AudioModel(rnn.BatchRNNLayers, config=None)
         model.load(self.train_info['model_path'])
     else:
         model = model.AudioModel(rnn.BatchRNNLayers,
                                  config=self.args.__dict__)
     if torch.cuda.is_available():
         if self.args.gpu == -1:
             model = torch.nn.DataParallel(model).cuda()
         else:
             model = model.cuda()
     return model
コード例 #9
0
def run():
    # Load the model.
    model.load(args.pretrained_model_path)
    # Initialize the server.
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    image2faces_pb2_grpc.add_Image2FacesServicer_to_server(
        Image2Faces(), server)
    server.add_insecure_port('[::]:%i' % args.port)
    server.start()
    print('started image2faces service on port %i' % args.port)
    # Start infinite loop.
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)
コード例 #10
0
ファイル: main.py プロジェクト: vickydaiya/Genessay
def generate_text(input_keywords):
    path = os.getcwd()
    parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
    parser.add_argument('--data-dir',
                        type=str,
                        default=path,
                        help='data directory containing input.txt')
    parser.add_argument('--seed',
                        type=str,
                        default=input_keywords,
                        help='seed string for sampling')
    parser.add_argument('--length',
                        type=int,
                        default=int(1.5 * len(input_keywords)),
                        help='length of the sample to generate'
                        )  #change the '8' to change number of words
    parser.add_argument('--diversity',
                        type=float,
                        default=0.01,
                        help='Sampling diversity')
    args, unknown = parser.parse_known_args()
    model = load(args.data_dir)
    del args.data_dir
    sentence = model.sample(**vars(args))
    return sentence
コード例 #11
0
ファイル: platane.py プロジェクト: lbovet/platane
def show_unit_tasks(path, parameters, env):
    group_container = parameters['groups']
    group_path = model.parent(path)+'/'+group_container
    groups = model.load(group_path)
    person_groups = {}
    for g in groups: 
        model.traverse(group_path+'/'+g, lambda (path, task, d): collect_persons(g, path, person_groups), all_nodes=True )    
    persons = set()
    for group in person_groups.values():
        for p in group:
            persons.add(p)        
    dates, slots, s = prepare_people_tasks( persons ) 
    schedules = {}
    for i in s:
        schedules[i[0]]=i
    group_schedules = []    
    for g in person_groups.keys():        
        group_sched = [ g, len(slots)*[0.0], 0, 0, {'url': group_path+'/'+g+'/planning/'} ]
        for _, person in person_groups[g]:
            group_sched[1] = [ group_sched[1][i] + schedules[person][1][i] for i in range(0,len(slots)) ]  
            group_sched[2] += schedules[person][2]
            group_sched[3] += schedules[person][3]
        n = len(person_groups[g])*1.0    
        group_sched[1] = [ i/n for i in group_sched[1] ]
        group_sched[2] /= n
        group_sched[3] /= n
        group_schedules.append(group_sched)    
    return visualize.render(dates, slots, sorted(group_schedules), variables={'qs':urlparse.parse_qs(env['QUERY_STRING']), 'context':'/', 'path':path, 'sum':True, 'url': path+'/', 'refreshable': False }), "text/html"    
コード例 #12
0
 def test_normal(self):
     mdl = model.load('models/oneanim', 60)
     self.assertIsNotNone(mdl['default'])
     anim = mdl['default']
     self.assertTrue(anim.loop)
     self.assertEquals(anim.ticks_per_frame, 20)
     self.assertEquals(len(anim.frames), 3)
コード例 #13
0
def receive(theModel, src, tag):
    weights = model.save(theModel)  # will be overwritten
    for i in range(len(weights)):
        dist.recv(tensor=weights[i], src=src, tag=tag * 100 + i)
    theModel = model.load(weights, theModel)
    print("Model received from", src)
    return theModel
コード例 #14
0
def test_model_on_static_examples(model_fname, training_examples_fname, m=0):
  modelInstance = model.load(model_fname)

  # n = model9x9['n']
  W = modelInstance['W']
  b = modelInstance['b']

  trainingExamples = training.read_training_examples(m, fname=training_examples_fname)

  if m == 0:
    m = trainingExamples['X'].shape[1]

  for i in range(1000):
    # i = round(np.random.rand() * m)
    x = trainingExamples['X'].T[i]
    nextPosition = position.transform_vector_into_position(x)

    position.print_position(nextPosition)

    print(' predicted ')

    x = position.transform_position_into_vector(nextPosition)
    movement = model.predict(W, b, x)
    position.print_movement(movement)

    print(' expected ')

    y = trainingExamples['Y'].T[i]
    position.print_movement(y.reshape(9, 1))

    raw_input("Press Enter to continue...")
コード例 #15
0
ファイル: view.py プロジェクト: ra1993/banking_terminal
def show_loginmenu():  #When the user logs in, and is prompted what todo
    account = input('Enter Account #: ')
    pin_num = input("Enter Pin #: ")
    # check if account number is in the json file
    if not account.isnumeric():
        print("Invalid input. Account Number must have numeric values")
        return
        if not pin_num.isnumeric():
            print("Invalid input. Pin # must have numeric values!")
            return
    data = model.load()
    if account in data and pin_num in data[account][
            "pin_num"]:  #checks account num and pin number in data
        print("Please choose an option:")
        print("1. Withdraw")
        print("2. Deposit")
        print("3. Check Balance")
        print("4. Exit")
        option = input()
        while option not in ['1', '2', '3', '4']:
            option = input(
                "Sorry, that's an invalid option! Please choose 1, 2 or 3: ")

        if option == '1':
            model.withdraw(account)
        elif option == '2':
            model.deposit(account)
        elif option == '3':
            model.balance(account)
        elif option == '4':
            return
コード例 #16
0
def main():
    dictionary = data.Corpus(args.data,
                             cuda=args.cuda,
                             yield_sentences=True,
                             rng=None).dictionary

    if False:
        # Old way of loading a model
        with open(args.model, 'rb') as f:
            mdl = torch.load(f)
        print(mdl)
    else:
        mdl = model.load(args.model)
    mdl.softmax = nn.Softmax()
    mdl = mdl.cuda() if args.cuda else mdl.cpu()
    mdl.eval()
    sampler = Sampler(dictionary, mdl)

    seed_texts = []
    if args.seed_text != '':
        seed_texts += [args.seed_text]
    if args.seed_file:
        with codecs.open(args.seed_file, 'r', 'utf-8') as f:
            seed_texts += [line.strip() for line in f]
    if seed_texts == []:
        seed_texts += ['']

    for seed_text in seed_texts:
        if args.print_seed_text:
            print(seed_text)
        if not args.seed_without_eos:
            seed_text = '<eos> ' + seed_text + ' <eos>'

        constraints = eval(args.constraint_list)
        tokenizer_fn = lambda s: dictionary.words_to_ids(
            data.tokenize(s, add_bos=False, add_eos=False), cuda=args.cuda)
        for c in constraints:
            if type(c) is SeedTextDictConstraint:
                c.set_seed_text(seed_text, tokenizer_fn, dictionary)

        if args.num_words:
            # Generate N words
            out_file = sys.stdout
            out_string = sampler.string(seed_text,
                                        args.prefix_text,
                                        args.num_words,
                                        constraints=constraints)
            for i, word in enumerate(out_string):
                out_file.write(word + ('\n' if i % 20 == 19 else ' '))
            if i % 20 != 19:
                print('')
        else:
            # Beam search on sentences
            for batch in sampler.sentences(seed_text,
                                           args.prefix_text,
                                           constraints=constraints):
                for sent_tokens in batch:
                    #print( "len = %d, %s" % (len(sent_tokens), ' '.join(sent_tokens)) )
                    print(' '.join(sent_tokens))
コード例 #17
0
def run():
    model.load()

    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
                         options=[('grpc.max_send_message_length',
                                   _MAX_MESSAGE_LENGTH),
                                  ('grpc.max_receive_message_length',
                                   _MAX_MESSAGE_LENGTH)])
    image2pose_pb2_grpc.add_Image2PoseServicer_to_server(Image2Pose(), server)
    server.add_insecure_port('[::]:%i' % args.port)
    server.start()
    print('started image2pose service on port %i' % args.port)
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        server.stop(0)
コード例 #18
0
def train_model_scenario_3(n, model_fname, training_examples_fname, m=0, alpha=0.001, beta=0.9, iterations=10000):
  debug = False

  modelInstance = model.load(model_fname)
  W = modelInstance['W']
  b = modelInstance['b']
  # (W, b) = model.initializeWeights(n)
  vdW = np.zeros(W.shape)
  vdb = np.zeros(b.shape)
  ex = training.read_training_examples(m, fname=training_examples_fname)

  X = ex['X']
  # assert X.shape == (9, 500)

  Y = ex['Y']
  # assert Y.shape == (9, 500)


  # L is a number of NN layers
  # (L = 3 for a model 9x18x18x9)
  L = len(n) - 1
  assert len(W) == L


  for i in range(0, iterations):
    # (dW, db) = model.calcGradients(W, b, X, Y)
    (dW, db, _) = model.back_propagation(n, W, b, X, Y)

    vdW = beta * vdW + (1 - beta) * dW
    vdb = beta * vdb + (1 - beta) * db

    # model.updateWeights(W, dW, b, db, alpha)
    W = W - alpha * vdW
    b = b - alpha * vdb

    if i % 30 == 0:
      print('iteration ' + str(i))
      (aL, _) = model.forward_propagation(W, b, X)
      cost = model.cost_function(Y, aL)
      # cost = model.costFunction(Y, A[L])
      # print('alpha')
      # print(alpha)
      print('cost')
      print(cost)

    if debug:
      if i > 0 and i % 3000 == 0:
        is_back_prop_correct = model.check_back_propagation(n, W, b, X, Y)

        if not is_back_prop_correct:
          print("BP is not correct")
          exit()
    if i % 1000 == 0:
      model.save(n, W, b, model_fname)

  print('------ end -------')

  model.save(n, W, b, model_fname)
コード例 #19
0
def spy_on_training_process(model_fname):
  model_instance = model.load(model_fname)

  n = model_instance['n']
  W = model_instance['W']
  b = model_instance['b']
  
  vdW = np.zeros(W.shape)
  vdb = np.zeros(b.shape)

  alpha0 = 0.3
  beta=0.9
  iterations = 100000
  decay_rate = 4.0 / iterations

  pos_trains = 0
  x_to_investigate = None

  for i in range(0, iterations):
    make_movement_fn = lambda x: model.predict2(W, b, x)

    ex = make_training_examples(make_movement_fn)

    X = ex['X']
    Y = ex['Y']

    x = X[:, 0].reshape(9, 1)

    if x_to_investigate == None:
      x_to_investigate = x
      position_to_investigate = x_to_investigate.reshape(3, 3)

    if (x == x_to_investigate).all():
      position.print_position(position_to_investigate)
      (_, _, aLbefore) = model.predict3(W, b, x_to_investigate)

    (dW, db, _) = model.back_propagation(n, W, b, X, Y)

    alpha = alpha0 / (1.0 + decay_rate * i)

    vdW = beta * vdW + (1 - beta) * dW
    vdb = beta * vdb + (1 - beta) * db

    W = W - alpha * dW
    b = b - alpha * db

    if i > 0 and i % 1000 == 0:
      model.save(n, W, b, model_fname)
      print('========saved=======')

    if (x == x_to_investigate).all():
      pos_trains += 1
      position.print_position(position_to_investigate)
      (_, _, aLafter) = model.predict3(W, b, x_to_investigate)
      print('\niteration: %d, position trained times: %d' % (i, pos_trains))
      y = Y[:, 0].reshape(9, 1)
      table = np.concatenate((aLbefore, aLafter, y), axis = 1)
      print(table)
コード例 #20
0
ファイル: app.py プロジェクト: MakhmoodSodikov/naive_faq_bot
def hello_world():
    print('request received')
    model = load()
    content = request.get_json()
    query = content['query']
    # TODO try-except blocks to check that everything is correct
    print('returning ans')
    output = {'answer': infer(model, query)}
    return jsonify(output)
コード例 #21
0
def process(self, image_array):
    model = model.load('my_model.h5')
    digit = prep.crop_image(image_array)
    digit = prep.crop_image(digit)
    digit = prep.center_image(digit)
    digit = prep.resize_image(digit)
    digit = prep.min_max_scaler(digit)
    digit = prep.reshape_array(digit)
    digit = model.predict(digit)
    return digit
コード例 #22
0
def handle(env, start_response, handler, m=None):
    path = get_path(env)
    if len(path) > 0 and not path[-1] == '/':
        start_response('302 Redirect',
                       [('Location', model.normalize(path) + "/")])
        return
    path = model.normalize(path)
    try:
        d = model.describe(path)
        qs = urlparse.parse_qs(env['QUERY_STRING'])
        if not m and 'cache' in d:
            if 'r' in qs and qs['r'][0] == '1':
                if d['cache'] == 'normal':
                    model.invalidate_cache(path)
                if d['cache'] == 'parent':
                    model.invalidate_cache(model.parent(path))
        if d and d['type'] == 'render' and env['REQUEST_METHOD'] == 'GET':
            parameters = {}
            if 'parameters' in d:
                parameters = d['parameters']
            content, mime = render_handlers[d['function']](path, parameters,
                                                           env)
            start_response('200 OK', [('Content-Type', mime),
                                      ('Content-Length', str(len(content)))])
            return content
        if not m:
            m = model.load(path)
        content, redirect = handler(path, d, m, env)
        if redirect:
            redirect = model.normalize(redirect)
            close = ''
            if 'c' in qs:
                if qs['c'][0] == '0':
                    close = '?c=1'
                if qs['c'][0] == '1':
                    close = '?c=2'
            start_response('302 Redirect',
                           [('Location', redirect + "/" + close)])
            return
        else:
            start_response('200 OK',
                           [('Content-Type', 'text/html;charset=utf-8'),
                            ('Content-Length', str(len(content)))])
            return content
    except model.NotFoundException as e:
        import traceback
        traceback.print_exc()
        raise restlite.Status, '404 Not Found'
    except model.ParseException as e:
        d = {}
        d.update({'e': e.errors})
        d.update(e.attributes)
        start_response('302 Redirect', [('Location', model.normalize(path) +
                                         "/?" + urllib.urlencode(d, True))])
        return
コード例 #23
0
def test_wrapper(model):
    '''Test your code.'''
    test_set = data.DataSet(FLAGS.root_dir,
                            FLAGS.dataset,
                            'test',
                            FLAGS.batch_size,
                            FLAGS.n_label,
                            data_aug=False,
                            shuffle=False)
    '''TODO: Your code here.'''
    model.load()
    tot_acc = 0.0
    tot_input = 0
    while test_set.has_next_batch():
        test_ims, test_labels = test_set.next_batch()
        _, acc = model.valid(test_ims, test_labels)
        tot_acc += acc * len(test_ims)
        tot_input += len(test_ims)
    acc = tot_acc / tot_input
    print("Test Accuracy= " + "{:.3f}".format(acc))
    print("Test Finished!")
コード例 #24
0
	def run(self):
		# Logic goes here
		model_dirs = os.listdir("model") # Traverse through the models folder and get all model names
		newest = 0
		for model_dir in model_dirs:
			name_val = int(model_dir)
			if name_val > newest:
				newest = name_val

		print "Loading model "+str(newest)
		# newest will now hold the name of the newest model in the directory
		self.cur_model = model.load(newest) # Loading in the model
コード例 #25
0
def train_model_scenario_2(n, model_fname, opponet_model_fname, alpha=0.1, iterations=5000):
  alpha0 = alpha
  decay_rate = 0.01
  modelInstance = model.load(opponet_model_fname)
  W0 = modelInstance['W']
  b0 = modelInstance['b']

  if model_fname == opponet_model_fname:
    W = W0
    b = b0
  else:
    make_movement_fn = lambda x: model.predict2(W0, b0, x)
    (W, b) = model.initialize_weights(n)

  for i in range(0, iterations):
    if model_fname == opponet_model_fname:
      make_movement_fn = lambda x: model.predict2(W, b, x)

    ex = training.make_training_examples(make_movement_fn)

    X = ex['X']
    Y = ex['Y']

    # displayTrainingExamples(X, Y)

    # (dW, db) = model.calcGradients(W, b, X, Y)
    (dW, db, _) = model.back_propagation(n, W, b, X, Y)

    alpha = alpha0 / (1 + decay_rate * i)

    model.update_weights(W, dW, b, db, alpha)

    if i % 100 == 0:
      print('iteration ' + str(i))
      (aL, _) = model.forward_propagation(W, b, X)
      cost = model.cost_function(Y, aL)
      print('cost')
      print(cost)
      print('alpha')
      print(alpha)

    # if i % 1000 == 0:
    #   is_back_prop_correct = model.checkBackPropagation(n, W, b, X, Y)

    #   if not is_back_prop_correct:
    #     print("BP is not correct")
    #     exit()

  print('------ end -------')

  model.save(n, W, b, model_fname)
コード例 #26
0
def load(config, options=None):
    label = None
    description = None
    dataset = None
    model = None
    training = None

    if options is None:
        options = {}

    if 'base' not in options or options['base'] is None:
        options['base'] = os.getcwd()

    if not options['base'].startswith('/'):
        options['base'] = os.path.join(os.getcwd(), options['base'])

    if 'label' in config:
        label = config['label']

    if 'description' in config:
        description = config['description']

    if 'model' in config:
        model = model_utils.load(config['model'], options)

    if 'training' in config:
        training = training_utils.load(config['training'], options)

    if 'dataset' in config:
        dataset = dataset_utils.load(config['dataset'], model, training, options)

    if 'weightsHdf5' in config:
        weights_hdf5 = config['weightsHdf5']

        if not weights_hdf5.startswith('/'):
            weights_hdf5 = os.path.join(options['base'], weights_hdf5)

    project = Project(
        label=label,
        description=description,
        weights_hdf5=weights_hdf5,
        dataset=dataset,
        model=model,
        training=training,
        options=options)

    if 'loadWeights' in options and options['loadWeights']:
        project.model.load_weights_hdf5(project.weights_hdf5)

    return project
コード例 #27
0
def show_unit_tasks(path, parameters, env):
    group_container = parameters['groups']
    group_path = model.parent(path) + '/' + group_container
    groups = model.load(group_path)
    person_groups = {}
    for g in groups:
        model.traverse(
            group_path + '/' + g,
            lambda (path, task, d): collect_persons(g, path, person_groups),
            all_nodes=True)
    persons = set()
    for group in person_groups.values():
        for p in group:
            persons.add(p)
    dates, slots, s = prepare_people_tasks(persons)
    schedules = {}
    for i in s:
        schedules[i[0]] = i
    group_schedules = []
    for g in person_groups.keys():
        group_sched = [
            g,
            len(slots) * [0.0], 0, 0, {
                'url': group_path + '/' + g + '/planning/'
            }
        ]
        for _, person in person_groups[g]:
            group_sched[1] = [
                group_sched[1][i] + schedules[person][1][i]
                for i in range(0, len(slots))
            ]
            group_sched[2] += schedules[person][2]
            group_sched[3] += schedules[person][3]
        n = len(person_groups[g]) * 1.0
        group_sched[1] = [i / n for i in group_sched[1]]
        group_sched[2] /= n
        group_sched[3] /= n
        group_schedules.append(group_sched)
    return visualize.render(dates,
                            slots,
                            sorted(group_schedules),
                            variables={
                                'qs': urlparse.parse_qs(env['QUERY_STRING']),
                                'context': '/',
                                'path': path,
                                'sum': True,
                                'url': path + '/',
                                'refreshable': False
                            }), "text/html"
コード例 #28
0
def main():
    parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
    parser.add_argument('--data-dir', type=str, default='data/corona',
                        help='data directory containing input.txt')
    parser.add_argument('--seed', type=str, default=None,
                        help='seed string for sampling')
    parser.add_argument('--length', type=int, default=1000,
                        help='length of the sample to generate')
    parser.add_argument('--diversity', type=float, default=1.0,
                        help='Sampling diversity')
    args = parser.parse_args()

    model = load(args.data_dir)
    del args.data_dir
    model.sample(**vars(args))
コード例 #29
0
ファイル: platane.py プロジェクト: lbovet/platane
def handle(env, start_response, handler, m=None):    
    path = get_path(env)
    if len(path) > 0 and not path[-1] == '/':
        start_response('302 Redirect', [('Location', model.normalize(path)+"/")])            
        return
    path = model.normalize(path)
    try:
        d = model.describe(path)
        qs = urlparse.parse_qs(env['QUERY_STRING'])
        if not m and 'cache' in d:
                if 'r' in qs and qs['r'][0]=='1':
                    if d['cache'] == 'normal':
                        model.invalidate_cache(path)
                    if d['cache'] == 'parent':
                        model.invalidate_cache(model.parent(path))
        if d and d['type'] == 'render' and env['REQUEST_METHOD'] == 'GET':
            parameters = {}
            if 'parameters' in d:
                parameters = d['parameters']
            content, mime = render_handlers[d['function']](path, parameters, env)            
            start_response('200 OK', [('Content-Type', mime), ('Content-Length', str(len(content)))])        
            return content        
        if not m:
            m = model.load(path)
        content, redirect = handler(path, d, m, env)
        if redirect:
            redirect = model.normalize(redirect)
            close=''
            if 'c' in qs:
                if qs['c'][0]=='0':
                    close='?c=1'
                if qs['c'][0]=='1':
                    close='?c=2'
            start_response('302 Redirect', [('Location', redirect+"/"+close)])            
            return
        else:
            start_response('200 OK', [('Content-Type', 'text/html;charset=utf-8'), ('Content-Length', str(len(content)))])        
            return content 
    except model.NotFoundException as e:   
        import traceback
        traceback.print_exc()
        raise restlite.Status, '404 Not Found'    
    except model.ParseException as e:
        d = {}
        d.update( { 'e': e.errors } )
        d.update(e.attributes)
        start_response('302 Redirect', [('Location', model.normalize(path)+"/?"+urllib.urlencode(d, True))])
        return
コード例 #30
0
def show_team_tasks(path, parameters, env):
    people = model.parent(path) + '/people'
    person_list = model.load(people)
    dates, slots, s = prepare_people_tasks([(people, person)
                                            for person in person_list])
    return visualize.render(dates,
                            slots,
                            sorted(s),
                            variables={
                                'qs': urlparse.parse_qs(env['QUERY_STRING']),
                                'context': '/',
                                'path': path,
                                'sum': True,
                                'url': path + '/',
                                'refreshable': True
                            }), "text/html"
コード例 #31
0
def ANNCertainty(start="2019-04-01",
                 stop="2019-05-01",
                 fromPickle=False,
                 clean=True,
                 load_model=False):
    if clean: filename = "ANNCertainty"
    else: filename = "ANNCertainty-uncleaned"
    if fromPickle:
        print("Loaded", filename)
        return pickle.load(open(config.DATA_PATH + "" + filename, "rb"))
    else:
        print("Making Met-ANM dataset for certaintyPlot", filename)
        met_df = pp.getMetData(start, stop).set_index("forecast_time")
        anm_df = pp.getSingleDataframe(start,
                                       "2019-05-31",
                                       fromPickle=True,
                                       clean=clean)

        df = anm_df.join(met_df, how="inner")

        if load_model:
            ere_wtnn = m.load(filename=filename)
        else:
            df_train = pp.getEdayData()
            df_full = pp.getSingleDataframe(fromPickle=True, clean=clean)
            df_train = df_full.join(df_train, how="inner")
            ere_wtnn = m.train_and_save_simple(
                df_train[["Wind Mean (M/S)", "weekday", "hour"]].values,
                df_train[["Curtailment"]].values,
                kfold=False,
                filename=filename)

        print("Doing ERE WT-FFNN predictions...")
        df["ere_wtnn_prediction"] = [
            ere_wtnn.predict([[d[["wind_speed", "weekday",
                                  "hour"]].values]])[0][0]
            for i, d in df.iterrows()
        ]
        df["ere_wtnn_prediction_correct"] = [
            int(round(d["ere_wtnn_prediction"]) == d["Curtailment"]) * 100
            for i, d in df.iterrows()
        ]

        print(df["ere_wtnn_prediction_correct"].mean())

        pickle.dump(df, open(config.DATA_PATH + "" + filename, "wb"))
        return df
コード例 #32
0
def main(argv):
    ap = ArgumentParser(prog="snow-patrol daemon")
    ap.add_argument("-v",
                    "--verbose",
                    default=False,
                    action="store_true",
                    help="Turn on verbose logging.")
    ap.add_argument("config_path")
    ap.add_argument("--dry-run", action="store_true", default=False)
    aargs = ap.parse_args(argv)
    log_file = ".%s.%s.log" % (os.path.splitext(
        os.path.basename(__file__))[0], os.path.basename(aargs.config_path))
    setup_logging(log_file, aargs.verbose, False, True, True)
    config = model.load(aargs.config_path)
    logging.debug("Running under: %s" % config)
    run_continuously(config, aargs.dry_run)
    return 0
コード例 #33
0
def main():

	
	# Training data consits of 60000 images and 60000 labels
	# Testing data consists of 10000 images and 10000 labels

	# Each image consits of 784 (28x28) pixels each of which contains a value from
	# 0 to 255.0 which corresponds to its darkness or lightness.

	# Each input needs to be a list of numpy arrays to be valid.
	# Load all of the data
	
	print "Loading data..."
	test_images = data.load_data(LIMITED)
	train_images = data.load_data(LIMITED, "train-images.idx3-ubyte", "train-labels.idx1-ubyte")

	print "Normalizing data..."
	X_train, Y_train = data.convert_image_data(train_images)
	X_test, Y_test = data.convert_image_data(test_images)
	X_train = np.array(X_train)
	Y_train = np.array(Y_train)
	X_test = np.array(X_test)
	Y_test = np.array(Y_test)

	if LOAD == False:
		print "Building the model..."
		_model = model.build()
	else:
		print "Loading the model..."
		elements = os.listdir("model")
		if len(elements) == 0:
			print "No models to load."
		else:
			_model = model.load(elements[len(elements)-1])

	if TRAIN == True:
		print "Training the model..."
		model.train(_model, X_train, Y_train, X_test, Y_test)

	if VISUALIZE:
		model.visualize(_model, test_images, VISUALIZE_TO_FILE)

	if TRAIN == True:
		print "Saving the model..."
		model.save(_model)
コード例 #34
0
def test_position(model_fname):
  print('\ntest model: %s' % (model_fname))
  model_instance = model.load(model_fname)
  W = model_instance['W']
  b = model_instance['b']


  x = np.array([
    -1,-1, 0,
     0, 1, 0,
     0, 0, 0,
  ]).reshape(9, 1)

  print('\n')
  position.print_position(position.transform_vector_into_position(x))

  (aL, _) = model.forward_propagation(W, b, x)
  print("aL")
  print(aL)
  movement = model.predict(W, b, x)
  position.print_movement(movement)
コード例 #35
0
ファイル: platane.py プロジェクト: lbovet/platane
def show_team_tasks(path, parameters, env):    
    people = model.parent(path)+'/people'
    person_list = model.load(people)
    dates, slots, s = prepare_people_tasks(  [ ( people, person) for person in person_list ] )
    return visualize.render(dates, slots, sorted(s), variables={'qs':urlparse.parse_qs(env['QUERY_STRING']), 'context':'/', 'path':path, 'sum':True, 'url': path+'/', 'refreshable': True }), "text/html"
コード例 #36
0
ファイル: sklearn.params.py プロジェクト: michnov/MLyn
#!/usr/bin/env python

import os, sys

lib_path = os.path.abspath(os.environ['TMT_ROOT'] + '/personal/mnovak/ml_framework/lib')
sys.path.append(lib_path)

import model

#from sklearn import tree
#import StringIO, pydot

name = sys.argv.pop(0)
if len(sys.argv) < 2:
    print >> sys.stderr, "Usage: " + name + " <model_path> <params_path>"
    exit()

model = model.Model()
model.load(sys.argv[0])
model.print_params(sys.argv[1])
コード例 #37
0
ファイル: main.py プロジェクト: shawntan/viz-speech
		
		plot_verts.append(verts)
		barpath = path.Path(verts, codes)
		patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5)
		ax.add_patch(patch)

		ax.set_xlim(left[0], right[-1])
		ax.set_ylim(0,1.1)
	def animate(t):
		time_text.set_text("t=%d"%t)
		for sequence,verts in zip(plot,plot_verts):
			n = sequence[t]
			top = bottom + n
			verts[1::5,1] = top
			verts[2::5,1] = top

	ani = animation.FuncAnimation(fig, animate, len(sequence), repeat=False)
	ani.save(filename, fps=15,bitrate=1280)



if __name__ == "__main__":
	predict = model.load(sys.argv[1])
	layers  = predict(load_ark(sys.argv[2]))

	means = [ np.sum(l > 0.5,axis=0)   for l in layers ]
	order = [ np.argsort(-m)[:100] for m in means ]
	plot = [ l[:,o] for l,o in zip(layers,order) ]

	create_animation(plot,sys.argv[3])
コード例 #38
0
ファイル: __init__.py プロジェクト: wanasit/katakana
def load_default_model():
    trained_model_dir = os.path.join(os.path.dirname(__file__), '../trained_models')
    global keras_model, input_encoding, input_decoding, output_encoding, output_decoding
    keras_model, input_encoding, input_decoding, output_encoding, output_decoding = model.load(save_dir=trained_model_dir)
コード例 #39
0
import os, sys, time
import numpy as np
from config import config
import model
from env import Environment

#############################################
config.use_gpu = True
#############################################

config.rl_model = "double_dqn"
config.rl_model = "bootstrapped_double_dqn"
config.rl_final_exploration_step = 20000
config.apply_batchnorm = False

model = model.load()
env = Environment()

max_episode = 2000
total_steps = 0
exploration_rate = config.rl_initial_exploration

dump_freq = 10
episode_rewards = 0
num_optimal_episodes = 0
sum_reward = 0
sum_loss = 0.0
save_freq = 100

bootstrapped = False
if config.rl_model in ["bootstrapped_double_dqn"]:
コード例 #40
0
ファイル: sklearn.test.py プロジェクト: michnov/MLyn
    print str(err) # will print something like "option -a not recognized"
    usage(name)
    sys.exit(2)
ranking = False
for o,a in optlist:
    if o == '--ranking':
        ranking = True
    else:
        assert False, "unhandled option"
if len(args) < 1:
    usage(name)
    sys.exit(2)
model_path = args[0]

model = model.Model()
model.load(model_path) 

#dot_data = StringIO.StringIO()
#tree.export_graphviz(model.model, out_file=dot_data)
#graph = pydot.graph_from_dot_data(dot_data.getvalue()) 
#graph.write_pdf("graph.pdf") 

print >> sys.stderr, "Reading the data..."
in_data = VowpalWabbitData(ranking=ranking)
(X_all, Y, tags_all) = in_data.read(sys.stdin)

print >> sys.stderr, "Making predictions..."
for X in X_all:
    tags = tags_all.pop(0)
    losses = model.predict_loss(X)
    for i in range(0, len(X)):