コード例 #1
0
ファイル: train.py プロジェクト: fsodogandji/nn-c3d
from chainer.functions.loss import mean_squared_error
from chainer import serializers

import c3d_data as data
import c3d_net as net

parser = argparse.ArgumentParser(description="3-layer NNs to train C3D fatures")
parser.add_argument("--initmodel", "-m", default="", help="Initialize the model from given file")
parser.add_argument("--resume", "-r", default="", help="Resume the optimization from snapshot")
parser.add_argument("--gpu", "-g", default=-1, type=int, help="GPU ID (negative value indicates CPU)")
args = parser.parse_args()

# Prepare dataset
print "Loading dataset..."
c3d_data = data.load_feature()
c3d_data = data.shuffle_video(c3d_data)

c3d_data["data"] = c3d_data["data"].astype(np.float32)
c3d_data["target"] = c3d_data["target"].astype(np.int32)

N = 6000
x_train, x_test = np.split(c3d_data["data"], [N])
y_train, y_test = np.split(c3d_data["target"], [N])
N_test = y_test.size

# 3-layer nets
model = L.Classifier(net.C3DNet())
if args.gpu >= 0:
    cuda.get_device(args.gpu).use()
    model.to_gpu()
xp = np if args.gpu < 0 else cuda.cupy
コード例 #2
0
ファイル: train.py プロジェクト: romanticegg/nn-c3d
__author__ = 'kazuto1011'

import sys, cv2, six, time
import numpy as np
import tensorflow as tf
import tensorflow.python.platform

import c3d_data

print 'Preparing dataset...'
dataset = c3d_data.load_feature()
dataset = c3d_data.shuffle_video(dataset)

dataset['data'] = dataset['data'].astype(np.float32)
dataset['target'] = dataset['target'].astype(np.float32)

N_TRAIN = 6000
x_train, x_test = np.split(dataset['data'], [N_TRAIN])
y_train, y_test = np.split(dataset['target'], [N_TRAIN])

def inference(feature, keep_prob):
    def weight_variable(shape):
        initial = tf.truncated_normal(shape, stddev=0.1)
        return tf.Variable(initial)

    def bias_variable(shape):
        initial = tf.constant(0.1, shape=shape)
        return tf.Variable(initial)

    with tf.name_scope('fc6') as scope:
        h_fc6 = tf.nn.dropout(tf.nn.relu(feature), keep_prob)
コード例 #3
0
ファイル: train_mod.py プロジェクト: fsodogandji/nn-c3d
__author__ = 'kazuto1011'

import sys, cv2, six, time
import numpy as np
import tensorflow as tf
import tensorflow.python.platform

import c3d_data

print 'Preparing dataset...'
dataset = c3d_data.load_feature()
dataset = c3d_data.shuffle_video(dataset)

dataset['data'] = dataset['data'].astype(np.float32)
dataset['target'] = dataset['target'].astype(np.float32)

N_TRAIN = 6000
x_train, x_test = np.split(dataset['data'], [N_TRAIN])
y_train, y_test = np.split(dataset['target'], [N_TRAIN])

def inference(feature, keep_prob):
    def weight_variable(shape):
        initial = tf.truncated_normal(shape, stddev=0.1)
        return tf.Variable(initial)

    def bias_variable(shape):
        initial = tf.constant(0.1, shape=shape)
        return tf.Variable(initial)

    with tf.name_scope('fc6') as scope:
        h_fc6 = tf.nn.dropout(tf.nn.relu(feature), keep_prob)
コード例 #4
0
parser.add_argument('--net',
                    '-n',
                    choices=('simple', 'parallel'),
                    default='simple',
                    help='Network type')
parser.add_argument('--gpu',
                    '-g',
                    default=-1,
                    type=int,
                    help='GPU ID (negative value indicates CPU)')
args = parser.parse_args()

# Prepare dataset
print 'Loading dataset...'
c3d_data = data.load_feature()
c3d_data = data.shuffle_video(c3d_data)

c3d_data['data'] = c3d_data['data'].astype(np.float32)
c3d_data['target'] = c3d_data['target'].astype(np.int32)

N = 6000
x_train, x_test = np.split(c3d_data['data'], [N])
y_train, y_test = np.split(c3d_data['target'], [N])
N_test = y_test.size

# 3-layer nets
if args.net == 'simple':
    model = L.Classifier(net.C3DNet())
    if args.gpu >= 0:
        cuda.get_device(args.gpu).use()
        model.to_gpu()