コード例 #1
0
    else:
        valid_dataset = Loader(
            hdf5_clean=args.valid_hdf_path + 'valid_clean.hdf',
            hdf5_attack=args.valid_hdf_path + 'valid_attack.hdf',
            max_nb_frames=args.n_frames,
            n_cycles=args.valid_n_cycles)
    valid_loader = torch.utils.data.DataLoader(
        valid_dataset,
        batch_size=args.valid_batch_size,
        shuffle=False,
        worker_init_fn=set_np_randomseed)
else:
    valid_loader = None

if args.model == 'lstm':
    model = model_.cnn_lstm(nclasses=args.n_classes)
elif args.model == 'resnet':
    model = model_.ResNet(nclasses=args.n_classes)
elif args.model == 'resnet_pca':
    model = model_.ResNet_pca(nclasses=args.n_classes)
elif args.model == 'lcnn_9':
    model = model_.lcnn_9layers(nclasses=args.n_classes)
elif args.model == 'lcnn_29':
    model = model_.lcnn_29layers_v2(nclasses=args.n_classes)
elif args.model == 'lcnn_9_pca':
    model = model_.lcnn_9layers_pca(nclasses=args.n_classes)
elif args.model == 'lcnn_29_pca':
    model = model_.lcnn_29layers_v2_pca(nclasses=args.n_classes)
elif args.model == 'lcnn_9_icqspec':
    model = model_.lcnn_9layers_icqspec(nclasses=args.n_classes)
elif args.model == 'lcnn_9_prodspec':
コード例 #2
0
    ) else False

    if args.cp_path is None:
        raise ValueError(
            'There is no checkpoint/model path. Use arg --cp-path to indicate the path!'
        )

    if os.path.isfile(args.out_path):
        os.remove(args.out_path)
        print(args.out_path + ' Removed')

    if args.cuda:
        device = get_freer_gpu()

    if args.model_la == 'lstm':
        model_la = model_.cnn_lstm()
    elif args.model_la == 'resnet':
        model_la = model_.ResNet()
    elif args.model_la == 'resnet_pca':
        model_la = model_.ResNet_pca()
    elif args.model_la == 'lcnn_9':
        model_la = model_.lcnn_9layers()
    elif args.model_la == 'lcnn_29':
        model_la = model_.lcnn_29layers_v2()
    elif args.model_la == 'lcnn_9_pca':
        model_la = model_.lcnn_9layers_pca()
    elif args.model_la == 'lcnn_29_pca':
        model_la = model_.lcnn_29layers_v2_pca()
    elif args.model_la == 'lcnn_9_icqspec':
        model_la = model_.lcnn_9layers_icqspec()
    elif args.model_la == 'lcnn_9_prodspec':
コード例 #3
0
import os
import model
import tensorflow as tf
import input_data

data = input_data.read_data_sets('MNIST_data', one_hot=True)

# 定义模型
with tf.variable_scope('cnn_lstm'):
    x = tf.placeholder(tf.float32, [None, 784], name='x')
    y, variables = model.cnn_lstm(x)

# 训练
y_ = tf.placeholder('float', [None, 10])
cross_entropy = tf.reduce_mean(
    tf.nn.softmax_cross_entropy_with_logits(logits=y, labels=y_))
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
correct_pred = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))

saver = tf.train.Saver(variables)

with tf.Session() as sess:
    merged_summary_op = tf.summary.merge_all()
    summary_write = tf.summary.FileWriter('tmp/mnist_log/1', sess.graph)
    summary_write.add_graph(sess.graph)
    sess.run(tf.global_variables_initializer())

    for i in range(20000):
        batch = data.train.next_batch(50)
        if i % 100 == 0:
コード例 #4
0
        raise ValueError(
            'There is no checkpoint/model path. Use arg --cp-path to indicate the path!'
        )

    if os.path.isfile(args.out_path):
        os.remove(args.out_path)
        print(args.out_path + ' Removed')

    print('Cuda Mode is: {}'.format(args.cuda))
    print('Selected model is: {}'.format(args.model))

    if args.cuda:
        device = get_freer_gpu()

    if args.model == 'lstm':
        model = model_.cnn_lstm()
    elif args.model == 'resnet':
        model = model_.ResNet()
    elif args.model == 'resnet_pca':
        model = model_.ResNet_pca()
    elif args.model == 'lcnn_9':
        model = model_.lcnn_9layers()
    elif args.model == 'lcnn_29':
        model = model_.lcnn_29layers_v2()
    elif args.model == 'lcnn_9_pca':
        model = model_.lcnn_9layers_pca()
    elif args.model == 'lcnn_29_pca':
        model = model_.lcnn_29layers_v2_pca()
    elif args.model == 'lcnn_9_icqspec':
        model = model_.lcnn_9layers_icqspec()
    elif args.model == 'lcnn_9_prodspec':
コード例 #5
0
ファイル: dp_train.py プロジェクト: Zh-cy/DeepVO
        else:
            x = layers.Bidirectional(
                layers.LSTM(1000,
                            return_sequences=True,
                            dropout=args.dropout,
                            recurrent_dropout=args.recurrent_dropout))(x)
            x = layers.Bidirectional(
                layers.LSTM(1000,
                            return_sequences=True,
                            dropout=args.dropout,
                            recurrent_dropout=args.recurrent_dropout))(x)
            x = layers.Dense(256, activation='relu')(x)
        out = layers.Dense(6)(x)
        lstm_model = models.Model([lstm_i1, lstm_i2], out)
    else:
        lstm_model = model.cnn_lstm(lstm_i1, lstm_i2)
else:
    cnn_model = model.flownetS_no_weight(args.img_height, args.img_width)
    l = cnn_model.layers
    imgs = layers.concatenate([lstm_i1, lstm_i2], axis=2)
    x = layers.TimeDistributed(l[1])(imgs)
    for i in range(2, 27):
        x = layers.TimeDistributed(l[i])(x)
    x = layers.TimeDistributed(layers.Flatten())(x)
    if not args.bidirectional:
        x = layers.LSTM(1000,
                        return_sequences=True,
                        dropout=args.dropout,
                        recurrent_dropout=args.recurrent_dropout)(x)
        x = layers.LSTM(1000,
                        return_sequences=True,