def read(folder):
    log.info('Reading pretrained network from {}'.format(folder))
    saver = Saver(folder)
    ckpt_info = saver.get_ckpt_info()
    model_opt = ckpt_info['model_opt']
    ckpt_fname = ckpt_info['ckpt_fname']
    model_id = ckpt_info['model_id']
    m = model.get_model(model_opt)
    cnn_nlayers = len(model_opt['cnn_filter_size'])
    mlp_nlayers = 1
    timespan = 1
    weights = {}
    sess = tf.Session()
    saver.restore(sess, ckpt_fname)

    output_list = []
    for net, nlayers in zip(['cnn', 'mlp'], [cnn_nlayers, mlp_nlayers]):
        for ii in xrange(nlayers):
            for w in ['w', 'b']:
                key = '{}_{}_{}'.format(net, w, ii)
                log.info(key)
                output_list.append(key)
            if net == 'cnn':
                for tt in xrange(timespan):
                    for w in ['beta', 'gamma']:
                        key = '{}_{}_{}_{}'.format(net, ii, tt, w)
                        log.info(key)
                        output_list.append(key)

    output_var = []
    for key in output_list:
        output_var.append(m[key])

    output_var_value = sess.run(output_var)

    for key, value in zip(output_list, output_var_value):
        weights[key] = value
        log.info(key)
        log.info(value.shape)

    return weights
示例#2
0
def read(folder):
    log.info('Reading pretrained network from {}'.format(folder))
    saver = Saver(folder)
    ckpt_info = saver.get_ckpt_info()
    model_opt = ckpt_info['model_opt']
    ckpt_fname = ckpt_info['ckpt_fname']
    model_id = ckpt_info['model_id']
    m = model.get_model(model_opt)
    cnn_nlayers = len(model_opt['cnn_filter_size'])
    mlp_nlayers = 1
    timespan = 1
    weights = {}
    sess = tf.Session()
    saver.restore(sess, ckpt_fname)

    output_list = []
    for net, nlayers in zip(['cnn', 'mlp'], [cnn_nlayers, mlp_nlayers]):
        for ii in xrange(nlayers):
            for w in ['w', 'b']:
                key = '{}_{}_{}'.format(net, w, ii)
                log.info(key)
                output_list.append(key)
            if net == 'cnn':
                for tt in xrange(timespan):
                    for w in ['beta', 'gamma']:
                        key = '{}_{}_{}_{}'.format(net, ii, tt, w)
                        log.info(key)
                        output_list.append(key)

    output_var = []
    for key in output_list:
        output_var.append(m[key])

    output_var_value = sess.run(output_var)

    for key, value in zip(output_list, output_var_value):
        weights[key] = value
        log.info(key)
        log.info(value.shape)

    return weights
示例#3
0
    plt.tight_layout(pad=2.0, w_pad=0.0, h_pad=0.0)
    plt.savefig(fname, dpi=150)
    plt.close('all')


def preprocess(x1, x2, y):
    """Preprocess training data."""
    return (x1.astype('float32') / 255,
            x2.astype('float32') / 255,
            y.astype('float32'))


if __name__ == '__main__':
    restore_folder = sys.argv[1]
    saver = Saver(restore_folder)
    ckpt_info = saver.get_ckpt_info()
    model_opt = ckpt_info['model_opt']
    data_opt = ckpt_info['data_opt']
    ckpt_fname = ckpt_info['ckpt_fname']
    step = ckpt_info['step']
    model_id = ckpt_info['model_id']

    log.info('Building model')
    m = get_model(model_opt)

    log.info('Loading dataset')
    dataset = get_dataset(data_opt)

    sess = tf.Session()
    saver.restore(sess, ckpt_fname)