update = []


# shared variables
learning_rate = shared(float32(lr.init))
if use.mom: 
    momentum = shared(float32(mom.momentum))
    drop.p_vid = shared(float32(drop.p_vid_val) )
    drop.p_hidden = shared(float32(drop.p_hidden_val))


idx_mini = T.lscalar(name="idx_mini") # minibatch index
idx_micro = T.lscalar(name="idx_micro") # microbatch index
x = ndtensor(len(tr.in_shape))(name = 'x') # video input
y = T.ivector(name = 'y') # labels
x_ = _shared(empty(tr.in_shape))
y_ = _shared(empty(tr.batch_size))
y_int32 = T.cast(y_,'int32')


L1 = _shared(0)
L2 = _shared(0)


### useless fake, but DataLoader_with_skeleton_normalisation would require that
x_skeleton = ndtensor(len(tr._skeleon_in_shape))(name = 'x_skeleton') # video input
x_skeleton_ = _shared(empty(tr._skeleon_in_shape))

# load the skeleton normalisation --Lio didn't normalise video input, but should we?
import cPickle
f = open('CNN_normalization.pkl','rb')
示例#2
0
    src = "/mnt/wd/chalearn/preproc"
    res_dir_ = "/home/lpigou/chalearn_wudi/try"

loader = DataLoader(src,
                    tr.batch_size)  # Lio changed it to read from HDF5 files

####################################################################
####################################################################
print "\n%s\n\tbuilding\n%s" % (('-' * 30, ) * 2)
####################################################################
####################################################################

idx_mini = T.lscalar(name="idx_mini")  # minibatch index
idx_micro = T.lscalar(name="idx_micro")  # microbatch index
x = ndtensor(len(tr.in_shape))(name='x')  # video input
x_ = _shared(empty(tr.in_shape))
y_ = _shared(empty((tr.batch_size, )))
y_int32 = T.cast(y_, 'int32')
y = T.ivector(name='y')  # labels

conv_shapes = []
for i in xrange(net.n_stages):
    k, p, v = array(net.kernels[i]), array(net.pools[i]), array(
        tr.video_shapes[i])
    conv_s = tuple(v - k + 1)
    conv_shapes.append(conv_s)
    tr.video_shapes.append(tuple((v - k + 1) / p))
    print "stage", i
    print "  conv", tr.video_shapes[i], "->", conv_s
    print "  pool", conv_s, "->", tr.video_shapes[i + 1], "x", net.maps[i + 1]
def build():
    use.load = True  # we load the CNN parameteres here
    x = ndtensor(len(tr.in_shape))(name='x')  # video input
    x_ = _shared(empty(tr.in_shape))

    conv_shapes = []
    for i in xrange(net.n_stages):
        k, p, v = array(net.kernels[i]), array(net.pools[i]), array(
            tr.video_shapes[i])
        conv_s = tuple(v - k + 1)
        conv_shapes.append(conv_s)
        tr.video_shapes.append(tuple((v - k + 1) / p))
        print "stage", i
        print "  conv", tr.video_shapes[i], "->", conv_s
        print "  pool", conv_s, "->", tr.video_shapes[i + 1], "x", net.maps[i +
                                                                            1]

    # number of inputs for MLP = (# maps last stage)*(# convnets)*(resulting video shape) + trajectory size
    n_in_MLP = net.maps[-1] * net.n_convnets * prod(tr.video_shapes[-1])
    print 'MLP:', n_in_MLP, "->", net.hidden, "->", net.n_class, ""

    if use.depth:
        if net.n_convnets == 2:
            out = [x[:, :, 0, :, :, :], x[:, :,
                                          1, :, :, :]]  # 2 nets: body and hand

    # build 3D ConvNet
    layers = []  # all architecture layers
    insp = []
    for stage in xrange(net.n_stages):
        for i in xrange(len(out)):  # for body and hand
            # normalization
            if use.norm and stage == 0:
                gray_norm = NormLayer(out[i][:, 0:1],
                                      method="lcn",
                                      use_divisor=use.norm_div).output
                gray_norm = std_norm(gray_norm, axis=[-3, -2, -1])
                depth_norm = var_norm(out[i][:, 1:])
                out[i] = T.concatenate([gray_norm, depth_norm], axis=1)
            elif use.norm:
                out[i] = NormLayer(out[i],
                                   method="lcn",
                                   use_divisor=use.norm_div).output
                out[i] = std_norm(out[i], axis=[-3, -2, -1])
            # convolutions
            out[i] *= net.scaler[stage][i]
            layers.append(
                ConvLayer(
                    out[i],
                    **conv_args(stage, i, batch, net, use, tr.rng,
                                tr.video_shapes)))
            out[i] = layers[-1].output
            out[i] = PoolLayer(out[i],
                               net.pools[stage],
                               method=net.pool_method).output
            if tr.inspect: insp.append(T.mean(out[i]))

    # flatten all convnets outputs
    for i in xrange(len(out)):
        out[i] = std_norm(out[i], axis=[-3, -2, -1])
    out = [out[i].flatten(2) for i in range(len(out))]
    vid_ = T.concatenate(out, axis=1)

    # dropout
    if use.drop:
        drop.p_vid = shared(float32(drop.p_vid_val))
        drop.p_hidden = shared(float32(drop.p_hidden_val))
        drop.p_vid.set_value(float32(0.))  # dont use dropout when testing
        drop.p_hidden.set_value(float32(0.))  # dont use dropout when testing
        vid_ = DropoutLayer(vid_, rng=tr.rng, p=drop.p_vid).output

    # MLP
    # ------------------------------------------------------------------------------
    # fusion
    if net.fusion == "early":
        out = vid_
        # hidden layer
        Wh, bh = load_params(use)  # This is test, wudi added this!
        layers.append(
            HiddenLayer(out,
                        W=Wh,
                        b=bh,
                        n_in=n_in_MLP,
                        n_out=net.hidden,
                        rng=tr.rng,
                        W_scale=net.W_scale[-2],
                        b_scale=net.b_scale[-2],
                        activation=relu))
        out = layers[-1].output

    if tr.inspect:
        insp = T.stack(insp[0], insp[1], insp[2], insp[3], insp[4], insp[5],
                       T.mean(out))
    else:
        insp = T.stack(0, 0)

    if use.drop: out = DropoutLayer(out, rng=tr.rng, p=drop.p_hidden).output
    #maxout
    # softmax layer
    Ws, bs = load_params(use)  # This is test, wudi added this!
    layers.append(
        LogRegr(out,
                W=Ws,
                b=bs,
                rng=tr.rng,
                activation=lin,
                n_in=net.hidden,
                W_scale=net.W_scale[-1],
                b_scale=net.b_scale[-1],
                n_out=net.n_class))
    """
    layers[-1] : softmax layer
    layers[-2] : hidden layer (video if late fusion)
    layers[-3] : hidden layer (trajectory, only if late fusion)
    """
    # prediction
    y_pred = layers[-1].y_pred
    p_y_given_x = layers[-1].p_y_given_x
    ####################################################################
    ####################################################################
    print "\n%s\n\tcompiling\n%s" % (('-' * 30, ) * 2)
    ####################################################################
    ####################################################################
    # compile functions
    # ------------------------------------------------------------------------------
    print 'compiling test_model'

    eval_model = function([], [y_pred, p_y_given_x],
                          givens={x: x_},
                          on_unused_input='ignore')

    return eval_model, x_
micro_updates = []
last_upd = []
update = []

# shared variables
learning_rate = shared(float32(lr.init))
if use.mom:
    momentum = shared(float32(mom.momentum))
    drop.p_vid = shared(float32(drop.p_vid_val))
    drop.p_hidden = shared(float32(drop.p_hidden_val))

idx_mini = T.lscalar(name="idx_mini")  # minibatch index
idx_micro = T.lscalar(name="idx_micro")  # microbatch index
x = ndtensor(len(tr.in_shape))(name='x')  # video input
y = T.ivector(name='y')  # labels
x_ = _shared(empty(tr.in_shape))
y_ = _shared(empty(tr.batch_size))
y_int32 = T.cast(y_, 'int32')

L1 = _shared(0)
L2 = _shared(0)

### useless fake, but DataLoader_with_skeleton_normalisation would require that
x_skeleton = ndtensor(len(tr._skeleon_in_shape))(
    name='x_skeleton')  # video input
x_skeleton_ = _shared(empty(tr._skeleon_in_shape))

# load the skeleton normalisation --Lio didn't normalise video input, but should we?
import cPickle
f = open('CNN_normalization.pkl', 'rb')
CNN_normalization = cPickle.load(f)
lt = localtime()
res_dir = res_dir_+"/try/"+str(lt.tm_year)+"."+str(lt.tm_mon).zfill(2)+"." \
            +str(lt.tm_mday).zfill(2)+"."+str(lt.tm_hour).zfill(2)+"."\
            +str(lt.tm_min).zfill(2)+"."+str(lt.tm_sec).zfill(2)
os.makedirs(res_dir)

# we need to parse an absolute path for HPC to load
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('path')
args = parser.parse_args()
load_path = args.path
######################################################################
net_convnet3d_grbm_early_fusion = convnet3d_grbm_early_fusion(res_dir, load_path)
net_convnet3d_grbm_early_fusion.load_params(os.path.join(load_path,'paramsbest.zip'))
x_ = _shared(empty(tr.in_shape))
x_skeleton_ = _shared(empty(tr._skeleon_in_shape))
p_y_given_x = net_convnet3d_grbm_early_fusion.prediction_function(x_, x_skeleton_)
#############################
# load normalisation constant given load_path
Mean_skel, Std_skel, Mean_CNN, Std_CNN = net_convnet3d_grbm_early_fusion.load_normalisation_constant(load_path)


for file_count, file in enumerate(samples):
    condition = (file_count > -1)   
    if condition:   #wudi only used first 650 for validation !!! Lio be careful!
        save_path= os.path.join(data, file)
        print file
        time_start = time()
        # we load precomputed feature set or recompute the whole feature set
        if os.path.isfile(save_path):
    def build_finetune_functions(self, x_, y_int32, x_skeleton_,
                                 learning_rate):
        '''
        This is used to fine tune the network
        '''
        # compute the gradients with respect to the model parameters
        gparams = T.grad(self.cost, self.params)
        # compute list of fine-tuning updates
        mini_updates = []
        micro_updates = []
        update = []
        last_upd = []

        # shared variables

        if use.mom: momentum = shared(float32(mom.momentum))

        def get_update(i):
            return update[i] / (batch.mini / batch.micro)

        for i, (param, gparam) in enumerate(zip(self.params, gparams)):
            # shape of the parameters
            shape = param.get_value(borrow=True).shape
            # init updates := zeros
            update.append(_shared(zeros(shape, dtype=config.floatX)))
            # micro_updates: sum of lr*grad
            micro_updates.append(
                (update[i], update[i] + learning_rate * gparam))
            # re-init updates to zeros
            mini_updates.append((update[i], zeros(shape, dtype=config.floatX)))

            if use.mom:
                last_upd.append(_shared(zeros(shape, dtype=config.floatX)))
                v = momentum * last_upd[i] - get_update(i)
                mini_updates.append((last_upd[i], v))
                if mom.nag:  # nesterov momentum
                    mini_updates.append(
                        (param, param + momentum * v - get_update(i)))
                else:
                    mini_updates.append((param, param + v))
            else:
                mini_updates.append((param, param - get_update(i)))

        def get_batch(_data):
            pos_mini = self.idx_mini * batch.mini
            idx1 = pos_mini + self.idx_micro * batch.micro
            idx2 = pos_mini + (self.idx_micro + 1) * batch.micro
            return _data[idx1:idx2]

        def givens(dataset_):
            return {
                self.x: get_batch(dataset_[0]),
                self.y: get_batch(dataset_[1]),
                self.x_skeleton: get_batch(dataset_[2])
            }

        print 'compiling apply_updates'
        apply_updates = function([],
                                 updates=mini_updates,
                                 on_unused_input='ignore')

        print 'compiling train_model'
        train_model = function(
            [self.idx_mini, self.idx_micro],
            [self.cost, self.errors, self.insp_mean, self.insp_std],
            updates=micro_updates,
            givens=givens((x_, y_int32, x_skeleton_)),
            on_unused_input='ignore')

        print 'compiling test_model'
        test_model = function(
            [self.idx_mini, self.idx_micro],
            [self.cost, self.errors, self.insp_mean, self.insp_std],
            givens=givens((x_, y_int32, x_skeleton_)),
            on_unused_input='ignore')

        return apply_updates, train_model, test_model
def build():
    use.load = True  # we load the CNN parameteres here
    x = ndtensor(len(tr.in_shape))(name = 'x') # video input
    x_ = _shared(empty(tr.in_shape))

    conv_shapes = []
    for i in xrange(net.n_stages):
        k,p,v = array(net.kernels[i]), array(net.pools[i]), array(tr.video_shapes[i])
        conv_s = tuple(v-k+1)
        conv_shapes.append(conv_s)
        tr.video_shapes.append(tuple((v-k+1)/p))
        print "stage", i
        print "  conv",tr.video_shapes[i],"->",conv_s
        print "  pool",conv_s,"->",tr.video_shapes[i+1],"x",net.maps[i+1]

    # number of inputs for MLP = (# maps last stage)*(# convnets)*(resulting video shape) + trajectory size
    n_in_MLP = net.maps[-1]*net.n_convnets*prod(tr.video_shapes[-1]) 
    print 'MLP:', n_in_MLP, "->", net.hidden, "->", net.n_class, ""

    if use.depth:
        if net.n_convnets==2: 
            out = [x[:,:,0,:,:,:], x[:,:,1,:,:,:]] # 2 nets: body and hand

    # build 3D ConvNet
    layers = [] # all architecture layers
    insp = []
    for stage in xrange(net.n_stages):
        for i in xrange(len(out)): # for body and hand
            # normalization
            if use.norm and stage==0: 
                gray_norm = NormLayer(out[i][:,0:1], method="lcn",
                    use_divisor=use.norm_div).output
                gray_norm = std_norm(gray_norm,axis=[-3,-2,-1])
                depth_norm = var_norm(out[i][:,1:])
                out[i]  = T.concatenate([gray_norm,depth_norm],axis=1)
            elif use.norm:
                out[i] = NormLayer(out[i], method="lcn",use_divisor=use.norm_div).output
                out[i] = std_norm(out[i],axis=[-3,-2,-1])
            # convolutions  
            out[i] *= net.scaler[stage][i]
            layers.append(ConvLayer(out[i], **conv_args(stage, i, batch, net, use, tr.rng, tr.video_shapes)))
            out[i] = layers[-1].output
            out[i] = PoolLayer(out[i], net.pools[stage], method=net.pool_method).output
            if tr.inspect: insp.append(T.mean(out[i]))

    # flatten all convnets outputs
    for i in xrange(len(out)): out[i] = std_norm(out[i],axis=[-3,-2,-1])
    out = [out[i].flatten(2) for i in range(len(out))]
    vid_ = T.concatenate(out, axis=1)

    # dropout
    if use.drop: 
        drop.p_vid = shared(float32(drop.p_vid_val) )
        drop.p_hidden = shared(float32(drop.p_hidden_val))
        drop.p_vid.set_value(float32(0.))  # dont use dropout when testing
        drop.p_hidden.set_value(float32(0.))  # dont use dropout when testing
        vid_ = DropoutLayer(vid_, rng=tr.rng, p=drop.p_vid).output

    # MLP
    # ------------------------------------------------------------------------------
    # fusion
    if net.fusion == "early":
        out = vid_
        # hidden layer
        Wh, bh = load_params(use)  # This is test, wudi added this!
        layers.append(HiddenLayer(out, W = Wh, b =bh, n_in=n_in_MLP, n_out=net.hidden, rng=tr.rng, 
            W_scale=net.W_scale[-2], b_scale=net.b_scale[-2], activation=relu))
        out = layers[-1].output

    if tr.inspect: insp = T.stack(insp[0],insp[1],insp[2],insp[3],insp[4],insp[5], T.mean(out))
    else: insp =  T.stack(0,0)

    if use.drop: out = DropoutLayer(out, rng=tr.rng, p=drop.p_hidden).output
    #maxout
    # softmax layer
    Ws, bs = load_params(use) # This is test, wudi added this!
    layers.append(LogRegr(out, W = Ws, b = bs, rng=tr.rng, activation=lin, n_in=net.hidden, 
        W_scale=net.W_scale[-1], b_scale=net.b_scale[-1], n_out=net.n_class))
    """
    layers[-1] : softmax layer
    layers[-2] : hidden layer (video if late fusion)
    layers[-3] : hidden layer (trajectory, only if late fusion)
    """
    # prediction
    y_pred = layers[-1].y_pred
    p_y_given_x = layers[-1].p_y_given_x
    ####################################################################
    ####################################################################
    print "\n%s\n\tcompiling\n%s"%(('-'*30,)*2)
    ####################################################################
    #################################################################### 
    # compile functions
    # ------------------------------------------------------------------------------
    print 'compiling test_model'

    eval_model = function([], [y_pred, p_y_given_x], 
        givens={x:x_},
        on_unused_input='ignore')

    return eval_model, x_
#############################
# load normalisation constant given load_path
#Mean_skel, Std_skel, Mean_CNN, Std_CNN = net_convnet3d_grbm_early_fusion.load_normalisation_constant(load_path)
f = open('/home/zhiquan/fancy/meterials/temp/SK_normalization.pkl', 'rb')
SK_normalization = cPickle.load(f)
Mean_skel = SK_normalization['Mean1']
Std_skel = SK_normalization['Std1']

####################################################################
# DBN for skeleton modules
####################################################################
# ------------------------------------------------------------------------------
# symbolic variables
x_skeleton = ndtensor(len(tr._skeleon_in_shape))(
    name='x_skeleton')  # video input
x_skeleton_ = _shared(empty(tr._skeleon_in_shape))

dbn = GRBM_DBN(numpy_rng=random.RandomState(123), n_ins=891, \
                hidden_layers_sizes=[2000, 2000, 1000], n_outs=101, input_x=x_skeleton, label=y )
# we load the pretrained DBN skeleton parameteres here
load_path = '/idiap/user/dwu/chalearn/result/try/36.7% 2015.07.09.17.53.10'
dbn.load_params_DBN(os.path.join(load_path, 'paramsbest.zip'))

test_model = function([],
                      dbn.logLayer.p_y_given_x,
                      givens={x_skeleton: x_skeleton_},
                      on_unused_input='ignore')

for file_count, file in enumerate(samples):
    condition = (file_count > -1)
    if condition:  #wudi only used first 650 for validation !!! Lio be careful!
示例#9
0
#args = parser.parse_args()
#load_path = args.path

load_path = '/remote/idiap.svm/user.active/dwu/chalearn/result/try/CNN_normalisation_53.0% 2015.06.23.12.17.31/'
######################################################################
import cPickle
f = open('CNN_normalization.pkl', 'rb')
CNN_normalization = cPickle.load(f)
Mean_CNN = CNN_normalization['Mean_CNN']
Std_CNN = CNN_normalization['Std_CNN']

# customized data loader for both video module and skeleton module
#loader = DataLoader_with_skeleton_normalisation(src, tr.batch_size, Mean_CNN, Std_CNN) # Lio changed it to read from HDF5 files
# we load the CNN parameteres here
x = ndtensor(len(tr.in_shape))(name='x')  # video input
x_ = _shared(empty(tr.in_shape))

use.load = True
use.fast_conv = True
video_cnn = conv3d_chalearn(x, use, lr, batch, net, reg, drop, mom, tr,
                            res_dir, load_path)

out = video_cnn.out
layers = []  # all architecture layers
# softmax layer
if use.load:
    W, b = load_params(use, load_path)
    print W.shape, b.shape
    layers.append(
        LogRegr(out,
                rng=tr.rng,
    def build_finetune_functions(self, x_, y_int32, x_skeleton_, learning_rate):
        '''
        This is used to fine tune the network
        '''
         # compute the gradients with respect to the model parameters
        gparams = T.grad(self.cost, self.params)
        # compute list of fine-tuning updates
        mini_updates = []
        micro_updates = []
        update = []
        last_upd = []

        # shared variables
        
        if use.mom: momentum = shared(float32(mom.momentum))
        def get_update(i): return update[i]/(batch.mini/batch.micro)

        for i, (param, gparam) in enumerate(zip(self.params, gparams)):
            # shape of the parameters
            shape = param.get_value(borrow=True).shape
            # init updates := zeros
            update.append(_shared(zeros(shape, dtype=config.floatX)))
            # micro_updates: sum of lr*grad
            micro_updates.append((update[i], update[i] + learning_rate*gparam))
            # re-init updates to zeros
            mini_updates.append((update[i], zeros(shape, dtype=config.floatX)))

            if use.mom:
                last_upd.append(_shared(zeros(shape, dtype=config.floatX)))
                v = momentum * last_upd[i] - get_update(i)
                mini_updates.append((last_upd[i], v))
                if mom.nag: # nesterov momentum
                    mini_updates.append((param, param + momentum*v - get_update(i)))
                else:
                    mini_updates.append((param, param + v))
            else:    
                mini_updates.append((param, param - get_update(i)))


        def get_batch(_data): 
            pos_mini = self.idx_mini*batch.mini
            idx1 = pos_mini + self.idx_micro*batch.micro
            idx2 = pos_mini + (self.idx_micro+1)*batch.micro
            return _data[idx1:idx2]

        def givens(dataset_):
            return {self.x: get_batch(dataset_[0]),
                    self.y: get_batch(dataset_[1]),
                    self.x_skeleton: get_batch(dataset_[2])}

        print 'compiling apply_updates'
        apply_updates = function([], 
            updates=mini_updates, 
            on_unused_input='ignore')

        print 'compiling train_model'
        train_model = function([self.idx_mini, self.idx_micro], [self.cost, self.errors, self.insp_mean, self.insp_std], 
            updates=micro_updates, 
            givens=givens((x_, y_int32, x_skeleton_)), 
            on_unused_input='ignore')

        print 'compiling test_model'
        test_model = function([self.idx_mini, self.idx_micro], [self.cost, self.errors, self.insp_mean, self.insp_std], 
            givens=givens((x_, y_int32, x_skeleton_)),
            on_unused_input='ignore')

        return apply_updates, train_model, test_model
#args = parser.parse_args()
#load_path = args.path

load_path='/remote/idiap.svm/user.active/dwu/chalearn/result/try/CNN_normalisation_53.0% 2015.06.23.12.17.31/'
######################################################################
import cPickle
f = open('CNN_normalization.pkl','rb')
CNN_normalization = cPickle.load(f)
Mean_CNN = CNN_normalization ['Mean_CNN']
Std_CNN = CNN_normalization['Std_CNN']

# customized data loader for both video module and skeleton module
#loader = DataLoader_with_skeleton_normalisation(src, tr.batch_size, Mean_CNN, Std_CNN) # Lio changed it to read from HDF5 files
# we load the CNN parameteres here
x = ndtensor(len(tr.in_shape))(name = 'x') # video input
x_ = _shared(empty(tr.in_shape))


use.load=True
use.fast_conv=True
video_cnn = conv3d_chalearn(x, use, lr, batch, net, reg, drop, mom, tr, res_dir, load_path)

out = video_cnn.out
layers = [] # all architecture layers
# softmax layer
if use.load:
    W, b = load_params(use, load_path)
    print W.shape, b.shape
    layers.append(LogRegr(out, rng=tr.rng, n_in=net.hidden_vid, W=W, b=b,
        W_scale=net.W_scale[-1], b_scale=net.b_scale[-1], n_out=net.n_class))
else:
elif pc=="lio":
    src = "/mnt/wd/chalearn/preproc"
    res_dir_ = "/home/lpigou/chalearn_wudi/try"

lt = localtime()
res_dir = res_dir_+"/try/"+str(lt.tm_year)+"."+str(lt.tm_mon).zfill(2)+"." \
            +str(lt.tm_mday).zfill(2)+"."+str(lt.tm_hour).zfill(2)+"."\
            +str(lt.tm_min).zfill(2)+"."+str(lt.tm_sec).zfill(2)
os.makedirs(res_dir)

######################################################################
net_convnet3d_grbm_early_fusion = convnet3d_grbm_early_fusion(res_dir, load_path)

net_convnet3d_grbm_early_fusion.load_params(os.path.join(load_path,'paramsbest.zip'))

x_ = _shared(empty(tr.in_shape))
y_ = _shared(empty(tr.batch_size))
y_int32 = T.cast(y_,'int32')
x_skeleton_ = _shared(empty(tr._skeleon_in_shape))

#############################
# load normalisation constant given load_path
Mean_skel, Std_skel, Mean_CNN, Std_CNN = net_convnet3d_grbm_early_fusion.load_normalisation_constant(load_path)
loader = DataLoader_with_skeleton_normalisation(src, tr.batch_size, \
                         Mean_CNN, Std_CNN, Mean_skel, Std_skel) # Lio changed it to read from HDF5 files
######################################################################
print "\n%s\n\tcompiling\n%s"%(('-'*30,)*2)
learning_rate = shared(float32(lr.init))
apply_updates, train_model, test_model = net_convnet3d_grbm_early_fusion.build_finetune_functions(x_, y_int32, x_skeleton_,learning_rate)

# shared variables
learning_rate = shared(float32(lr.init))
if use.mom: 
    momentum = shared(float32(mom.momentum))
    drop.p_vid = shared(float32(drop.p_vid_val) )
    drop.p_hidden = shared(float32(drop.p_hidden_val))

# symbolic variables
# in shape: #frames * gray/depth * body/hand * 4 maps
x = ndtensor(len(tr.in_shape))(name = 'x') # video input
# x = T.TensorVariable(CudaNdarrayType([False] * len(in_shape))) # video input
y = T.ivector(name = 'y') # labels
idx_mini = T.lscalar(name="idx_mini") # minibatch index
idx_micro = T.lscalar(name="idx_micro") # microbatch index
x_ = _shared(empty(tr.in_shape))
y_ = _shared(empty((tr.batch_size,)))
y_int32 = T.cast(y_,'int32')

# print parameters
# ------------------------------------------------------------------------------
for c in (use, lr, batch, net, reg, drop, mom, tr):
    write(c.__name__+":", res_dir)
    _s = c.__dict__
    del _s['__module__'], _s['__doc__']
    for key in _s.keys(): 
        val = str(_s[key])
        if val.startswith("<static"): val = str(_s[key].__func__.__name__)
        if val.startswith("<Cuda"): continue
        if val.startswith("<Tensor"): continue
        write("  "+key+": "+val, res_dir)
示例#14
0
    res_dir_ = "/home/lpigou/chalearn_wudi/try"

lt = localtime()
res_dir = res_dir_+"/try/"+str(lt.tm_year)+"."+str(lt.tm_mon).zfill(2)+"." \
            +str(lt.tm_mday).zfill(2)+"."+str(lt.tm_hour).zfill(2)+"."\
            +str(lt.tm_min).zfill(2)+"."+str(lt.tm_sec).zfill(2)
os.makedirs(res_dir)

######################################################################
net_convnet3d_grbm_early_fusion = convnet3d_grbm_early_fusion(
    res_dir, load_path)

net_convnet3d_grbm_early_fusion.load_params(
    os.path.join(load_path, 'paramsbest.zip'))

x_ = _shared(empty(tr.in_shape))
y_ = _shared(empty(tr.batch_size))
y_int32 = T.cast(y_, 'int32')
x_skeleton_ = _shared(empty(tr._skeleon_in_shape))

#############################
# load normalisation constant given load_path
Mean_skel, Std_skel, Mean_CNN, Std_CNN = net_convnet3d_grbm_early_fusion.load_normalisation_constant(
    load_path)
loader = DataLoader_with_skeleton_normalisation(src, tr.batch_size, \
                         Mean_CNN, Std_CNN, Mean_skel, Std_skel) # Lio changed it to read from HDF5 files
######################################################################
print "\n%s\n\tcompiling\n%s" % (('-' * 30, ) * 2)
learning_rate = shared(float32(lr.init))
apply_updates, train_model, test_model = net_convnet3d_grbm_early_fusion.build_finetune_functions(
    x_, y_int32, x_skeleton_, learning_rate)
    src = "/mnt/wd/chalearn/preproc"
    res_dir_ = "/home/lpigou/chalearn_wudi/try"


loader = DataLoader(src, tr.batch_size) # Lio changed it to read from HDF5 files

####################################################################
####################################################################
print "\n%s\n\tbuilding\n%s"%(('-'*30,)*2)
####################################################################
#################################################################### 

idx_mini = T.lscalar(name="idx_mini") # minibatch index
idx_micro = T.lscalar(name="idx_micro") # microbatch index
x = ndtensor(len(tr.in_shape))(name = 'x') # video input
x_ = _shared(empty(tr.in_shape))
y_ = _shared(empty((tr.batch_size,)))
y_int32 = T.cast(y_,'int32')
y = T.ivector(name = 'y') # labels

conv_shapes = []
for i in xrange(net.n_stages):
    k,p,v = array(net.kernels[i]), array(net.pools[i]), array(tr.video_shapes[i])
    conv_s = tuple(v-k+1)
    conv_shapes.append(conv_s)
    tr.video_shapes.append(tuple((v-k+1)/p))
    print "stage", i
    print "  conv",tr.video_shapes[i],"->",conv_s
    print "  pool",conv_s,"->",tr.video_shapes[i+1],"x",net.maps[i+1]

# number of inputs for MLP = (# maps last stage)*(# convnets)*(resulting video shape) + trajectory size