Exemplo n.º 1
0
                        use_locking=False, name='Adam').\
            minimize(loss)

    init = tf.global_variables_initializer()
    saver = tf.train.Saver()
    t00 = datetime.datetime.now()

    with tf.Session() as sess:
        sess.run(init)
        if renetFile:
            saver.restore(sess, renetFile)

        str1 = ''
        for a in range(iterations):

            tr_pre_data = tr.prepare()
            tr_loss, tr_median = run_data_stack_avg2(tr_pre_data, input_dic,
                                                     sess, xy, stack)

            te_pre_data = te.prepare()
            te_loss, te_median = run_data_stack_avg2(te_pre_data, input_dic,
                                                     sess, xy, stack)

            t1 = datetime.datetime.now()

            t1 = datetime.datetime.now()
            str = "it: {0:.2f} {1:.2f} ".format(
                a * loop / 1000.0, (t1 - t00).total_seconds() / 3600.0)
            for s in range(stack + 1):
                str += " {0:.3f} {1:.3f} {2:.3f} {3:.3f} ".format(
                    tr_loss[s], te_loss[s], tr_median[s], te_median[s])
Exemplo n.º 2
0
        sess.run(init)

        if test is not None:
            saver.restore(sess, cfg.netFile)
            mul = -1
            if len(sys.argv) > 2:
                mul = int(sys.argv[2])
            run_test(input_dic, sess, xy, te, cfg, mul)

        if cfg.renetFile:
            saver.restore(sess, cfg.renetFile)

        str1 = ''
        for a in range(iterations):

            tr_pre_data = tr0.prepare()
            tr_loss, tr_median = run_data(tr_pre_data, input_dic, sess, xy,
                                          'tr', cfg)

            te_pre_data = te.prepare()
            te_loss, te_median = run_data(te_pre_data, input_dic, sess, xy,
                                          'te', cfg)

            t1 = datetime.datetime.now()
            str = "it: {0:.3f} {1:.3f} {2:4.2e}".\
                format(a*loop/1000.0, (t1 - t00).total_seconds()/3600.0, lr)
            s = -1
            while True:
                s += len(tr_loss) / 2
                str += " {0:.3f} {1:.3f} {2:.3f} {3:.3f} ".format(
                    tr_loss[s], te_loss[s], tr_median[s], te_median[s])
Exemplo n.º 3
0
    #                use_locking=False, name='Adam').\
    #    minimize(ls[0])

    init = tf.global_variables_initializer()
    saver = tf.train.Saver()
    t00 = datetime.datetime.now()

    with tf.Session() as sess:
        sess.run(init)
        if cfg.renetFile:
            saver.restore(sess, cfg.renetFile)

        str1 = ''
        for a in range(iterations):

            tr_pre_data = tr0.prepare()
            tr_loss, tr_median = run_data_stack_avg3(tr_pre_data, input_dic,
                                                     sess, xy, 'tr', att)

            te_pre_data = te.prepare()
            te_loss, te_median = run_data_stack_avg3(te_pre_data, input_dic,
                                                     sess, xy, 'te', att)

            t1 = datetime.datetime.now()
            str = "it: {0:.3f} {1:.3f}".format(
                a * loop / 1000.0, (t1 - t00).total_seconds() / 3600.0)
            s = 0
            while True:
                # for s in range(0, feature_len+1, 5  ):
                if s > cfg.feature_len:
                    s = cfg.feature_len
Exemplo n.º 4
0
            if len(sys.argv) > 2:
                mul = int(sys.argv[2])
            saver.restore(sess, cfg.netFile)
            run_test(input_dic, sess, xy, te, cfg, mul)

        if cfg.renetFile:
            saver.restore(sess, cfg.renetFile)

        str1 = ''
        for a in range(iterations):

            t1 = datetime.datetime.now()
            str = "it: {0:.3f} {1:.3f} {2:4.2e}".\
                format(a*loop/1000.0, (t1 - t00).total_seconds()/3600.0, lr)

            tr_pre_data = tr0.prepare()
            tr_loss, tr_median = run_data_0(tr_pre_data, input_dic, sess, xy,
                                            'tr', cfg)

            te_pre_data = te.prepare()
            te_loss, te_median = run_data_0(te_pre_data, input_dic, sess, xy,
                                            'te', cfg)

            s = -1
            while True:
                s += len(tr_loss) / 2
                str += " {0:.3f} {1:.3f} {2:.3f} {3:.3f} ".format(
                    tr_loss[s], te_loss[s], tr_median[s], te_median[s])
                if s == len(tr_loss) - 1:
                    break
Exemplo n.º 5
0
    cfg = Config(config_file)

    tr = DataSet(cfg.tr_data, cfg.memory_size, cfg.feature_len)
    te = DataSet(cfg.te_data, cfg.memory_size, cfg.feature_len)
    tr.set_net_type(cfg.net_type)
    te.set_net_type(cfg.net_type)
    tr.set_t_scale(cfg.t_scale)
    te.set_t_scale(cfg.t_scale)
    tr.set_num_output(cfg.num_output)
    te.set_num_output(cfg.num_output)
    att = te.sz[1]

    D_in = cfg.feature_len * att
    D_out = cfg.num_output

    tr_pre_data = tr.prepare(multi=1)
    for b in tr_pre_data:
        d = torch.from_numpy(b[0]).type(torch.FloatTensor)
        t = torch.from_numpy(b[1]).type(torch.FloatTensor)

    te_pre_data = te.prepare(multi=1)
    for b in te_pre_data:
        de = torch.from_numpy(b[0]).type(torch.FloatTensor)
        te = torch.from_numpy(b[1]).type(torch.FloatTensor)

    H = 200

    # Create random Tensors to hold input and outputs.
    #d = torch.randn(N, D_in, device=device, dtype=dtype)
    #t = torch.randn(N, D_out, device=device, dtype=dtype)
Exemplo n.º 6
0
    xy = {}
    for a in range(base + 1):
        xy[a] = net.layers['output{}'.format(a)]

    init = tf.global_variables_initializer()
    saver = tf.train.Saver()
    t00 = datetime.datetime.now()
    multi = -1

    with tf.Session() as sess:
        saver.restore(sess, renetFile)

        rst_dic = {}
        truth_dic = {}
        for _ in range(loop):
            te_pre_data = te.prepare(rd=False, multi=multi)
            for b in te_pre_data:

                length = b[0].shape[1] / base
                feed = {}  # inputs['input0']: b[0][:, :length]}
                for a in range(base):
                    feed[input_dic['input{}'.format(a)]] = b[0][:, length *
                                                                a:length *
                                                                (a + 1)]
                result = []
                for a in range(base + 1):
                    r = sess.run(xy[a], feed_dict=feed)
                    result.append(r)
                result = np.array(result)
                for a in range(len(b[2])):
                    if not b[2][a] in rst_dic: