plt.semilogy(train_costs)
    plt.show(block=False)
    fig.savefig('./eval/' + eval_prefix + '/' + eval_prefix + '_cost.png')

    fig = plt.figure()
    plt.semilogy(val_errs)
    plt.show(block=False)
    fig.savefig('./eval/' + eval_prefix + '/' + eval_prefix + '_errs.png')

    # save results
    poseNet.save("./eval/{}/net_{}.pkl".format(eval_prefix, eval_prefix))
    # poseNet.load("./eval/{}/net_{}.pkl".format(eval_prefix,eval_prefix))

    # add prior to network
    cfg = HiddenLayerParams(inputDim=(batchSize, train_gt3D_embed.shape[1]),
                            outputDim=(batchSize,
                                       numpy.prod(train_gt3D.shape[1:])),
                            activation=None)
    pcalayer = HiddenLayer(rng,
                           poseNet.layers[-1].output,
                           cfg,
                           copyLayer=None,
                           layerNum=len(poseNet.layers))
    pcalayer.W.set_value(pca.components_)
    pcalayer.b.set_value(pca.mean_)
    poseNet.layers.append(pcalayer)
    poseNet.output = pcalayer.output
    poseNet.cfgParams.numJoints = train_gt3D.shape[1]
    poseNet.cfgParams.nDims = train_gt3D.shape[2]
    poseNet.cfgParams.outputDim = pcalayer.cfgParams.outputDim
    poseNet.save("./eval/{}/network_prior.pkl".format(eval_prefix))
Beispiel #2
0
    def __init__(self,
                 type=0,
                 nChan=1,
                 wIn=128,
                 hIn=128,
                 batchSize=128,
                 numJoints=16,
                 nDims=3,
                 resizeFactor=2):
        '''
       Init the parametrization

        :type typeID: int
        :param typeID: type of descr network
        '''

        super(ScaleNetParams, self).__init__()

        self.batch_size = batchSize
        self.numJoints = numJoints
        self.nDims = nDims

        if type == 1:
            self.numInputs = 3
            self.inpConv = 3
            self.inputDim = [(batchSize, nChan, hIn, wIn),
                             (batchSize, nChan, hIn // resizeFactor,
                              wIn // resizeFactor),
                             (batchSize, nChan, hIn // resizeFactor**2,
                              wIn // resizeFactor**2)]
            # Try small configuration
            self.layers.append(
                ConvPoolLayerParams(
                    inputDim=(batchSize, nChan, hIn, wIn),  # w,h,nChannel
                    nFilters=8,
                    filterDim=(5, 5),
                    poolsize=(4, 4),
                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(5, 5),
                                    poolsize=(2, 2),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(
                    inputDim=(batchSize, nChan, hIn // resizeFactor,
                              wIn // resizeFactor),  # w,h,nChannel
                    nFilters=8,
                    filterDim=(5, 5),
                    poolsize=(2, 2),
                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(5, 5),
                                    poolsize=(2, 2),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(
                    inputDim=(batchSize, nChan, hIn // resizeFactor**2,
                              wIn // resizeFactor**2),  # w,h,nChannel
                    nFilters=8,
                    filterDim=(5, 5),
                    poolsize=(2, 2),
                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(5, 5),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))
            lout = 0
            for j in range(self.numInputs):
                idx = (j + 1) * self.inpConv - 1
                lout += self.layers[idx].outputDim[1] * self.layers[
                    idx].outputDim[2] * self.layers[idx].outputDim[3]

            self.layers.append(
                HiddenLayerParams(inputDim=(batchSize, lout),
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                HiddenLayerParams(inputDim=self.layers[-1].outputDim,
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                HiddenLayerParams(
                    inputDim=self.layers[-1].outputDim,
                    outputDim=(batchSize, numJoints * nDims),
                    activation=None))  # last one is linear for regression

            self.outputDim = self.layers[-1].outputDim
        else:
            raise NotImplementedError("not implemented")
Beispiel #3
0
    def __init__(self, rng, inputVar=None, cfgParams=None):
        """
        @see https://github.com/KaimingHe/resnet-1k-layers/blob/master/resnet-pre-act.lua
        :type cfgParams: DescriptorNetParams
        """
        import theano.tensor as T

        self._params_filter = []
        self._weights_filter = []

        if cfgParams is None:
            raise Exception("Cannot create a Net without config parameters (ie. cfgParams==None)")

        if inputVar is None:
            inputVar = T.tensor4('x')  # input variable
        elif isinstance(inputVar, str):
            raise NotImplementedError()

        self.inputVar = inputVar
        self.cfgParams = cfgParams

        # create network
        self.layers = []

        batchSize = cfgParams.batch_size

        # create structure
        if cfgParams.type == 0:
            # Try ResNet similar configuration
            depth = 47
            assert (depth - 2) % 9 == 0, 'depth should be 9n+2 (e.g., 164 or 1001)'
            n = (depth - 2) / 9

            nStages = [32, 64, 128, 256, 256]

            self.layers.append(ConvPoolLayer(rng, self.inputVar,
                                             ConvPoolLayerParams(inputDim=self.cfgParams.inputDim, nFilters=nStages[0],
                                                                 filterDim=(5, 5), stride=(1, 1),
                                                                 poolsize=(2, 2), border_mode='same', activation=None,
                                                                 init_method='He'),
                                             layerNum=len(self.layers)))  # one conv at the beginning
            rout = self.add_res_layers(rng, self.layers[-1].output, self.layers[-1].cfgParams.outputDim, nStages[1], n, 2)  # Stage 1
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[2], n, 2)  # Stage 2
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[3], n, 2)  # Stage 3
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[4], n, 2)  # Stage 4
            self.layers.append(BatchNormLayer(rng, rout, BatchNormLayerParams(inputDim=self.layers[-1].cfgParams.outputDim), layerNum=len(self.layers)))
            self.layers.append(NonlinearityLayer(rng, self.layers[-1].output, NonlinearityLayerParams(inputDim=self.layers[-1].cfgParams.outputDim, activation=ReLU), layerNum=len(self.layers)))
            # self.layers.append(GlobalAveragePoolLayer(rng, self.layers[-1].output, GlobalAveragePoolLayerParams(inputDim=self.layers[-1].cfgParams.outputDim), layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output.flatten(2),
                                           HiddenLayerParams(# inputDim=self.layers[-1].cfgParams.outputDim,
                                                             inputDim=(self.layers[-1].cfgParams.outputDim[0], numpy.prod(self.layers[-1].cfgParams.outputDim[1:])),
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, self.cfgParams.numJoints*self.cfgParams.nDims),
                                                             activation=None),
                                           layerNum=len(self.layers)))

            self.output = self.layers[-1].output
        elif cfgParams.type == 1:
            # Try ResNet similar configuration
            depth = 47
            assert (depth - 2) % 9 == 0, 'depth should be 9n+2 (e.g., 164 or 1001)'
            n = (depth - 2) / 9

            nStages = [32, 64, 128, 256, 256]

            self.layers.append(ConvPoolLayer(rng, self.inputVar,
                                             ConvPoolLayerParams(inputDim=self.cfgParams.inputDim, nFilters=nStages[0],
                                                                 filterDim=(5, 5), stride=(1, 1),
                                                                 poolsize=(2, 2), border_mode='same', activation=None,
                                                                 init_method='He'),
                                             layerNum=len(self.layers)))  # one conv at the beginning
            rout = self.add_res_layers(rng, self.layers[-1].output, self.layers[-1].cfgParams.outputDim, nStages[1], n, 2)  # Stage 1
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[2], n, 2)  # Stage 2
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[3], n, 2)  # Stage 3
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[4], n, 2)  # Stage 4
            self.layers.append(BatchNormLayer(rng, rout, BatchNormLayerParams(inputDim=self.layers[-1].cfgParams.outputDim), layerNum=len(self.layers)))
            self.layers.append(NonlinearityLayer(rng, self.layers[-1].output, NonlinearityLayerParams(inputDim=self.layers[-1].cfgParams.outputDim, activation=ReLU), layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output.flatten(2),
                                           HiddenLayerParams(inputDim=(self.layers[-1].cfgParams.outputDim[0], numpy.prod(self.layers[-1].cfgParams.outputDim[1:])),
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, 30), activation=None),
                                           layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, self.cfgParams.numJoints*self.cfgParams.nDims),
                                                             activation=None),
                                           layerNum=len(self.layers)))

            self.output = self.layers[-1].output
        elif cfgParams.type == 2:
            # Try ResNet similar configuration
            depth = 47
            assert (depth - 2) % 9 == 0, 'depth should be 9n+2 (e.g., 164 or 1001)'
            n = (depth - 2) / 9

            nStages = [32, 64, 128, 256, 256]

            self.layers.append(ConvPoolLayer(rng, self.inputVar,
                                             ConvPoolLayerParams(inputDim=self.cfgParams.inputDim, nFilters=nStages[0],
                                                                 filterDim=(5, 5), stride=(1, 1),
                                                                 poolsize=(2, 2), border_mode='same', activation=None,
                                                                 init_method='He'),
                                             layerNum=len(self.layers)))  # one conv at the beginning
            rout = self.add_res_layers(rng, self.layers[-1].output, self.layers[-1].cfgParams.outputDim, nStages[1], n, 2)  # Stage 1
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[2], n, 2)  # Stage 2
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[3], n, 2)  # Stage 3
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[4], n, 2)  # Stage 4
            self.layers.append(BatchNormLayer(rng, rout, BatchNormLayerParams(inputDim=self.layers[-1].cfgParams.outputDim), layerNum=len(self.layers)))
            self.layers.append(NonlinearityLayer(rng, self.layers[-1].output, NonlinearityLayerParams(inputDim=self.layers[-1].cfgParams.outputDim, activation=ReLU), layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output.flatten(2),
                                           HiddenLayerParams(inputDim=(self.layers[-1].cfgParams.outputDim[0], numpy.prod(self.layers[-1].cfgParams.outputDim[1:])),
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))

            self.layers.append(DropoutLayer(rng, self.layers[-1].output,
                                            DropoutLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                               outputDim=self.layers[-1].cfgParams.outputDim),
                                            layerNum=len(self.layers)))

            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))

            self.layers.append(DropoutLayer(rng, self.layers[-1].output,
                                            DropoutLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                               outputDim=self.layers[-1].cfgParams.outputDim),
                                            layerNum=len(self.layers)))

            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, self.cfgParams.numJoints*self.cfgParams.nDims),
                                                             activation=None),
                                           layerNum=len(self.layers)))

            self.output = self.layers[-1].output
        elif cfgParams.type == 3:
            # Try ResNet similar configuration
            depth = 47
            assert (depth - 2) % 9 == 0, 'depth should be 9n+2 (e.g., 164 or 1001)'
            n = (depth - 2) / 9

            nStages = [32, 64, 128, 128, 128]

            self.layers.append(ConvPoolLayer(rng, self.inputVar,
                                             ConvPoolLayerParams(inputDim=self.cfgParams.inputDim, nFilters=nStages[0],
                                                                 filterDim=(5, 5), stride=(1, 1),
                                                                 poolsize=(2, 2), border_mode='same', activation=None,
                                                                 init_method='He'),
                                             layerNum=len(self.layers)))  # one conv at the beginning
            rout = self.add_res_layers(rng, self.layers[-1].output, self.layers[-1].cfgParams.outputDim, nStages[1], n, 2)  # Stage 1
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[2], n, 2)  # Stage 2
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[3], n, 2)  # Stage 3
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[4], n, 2)  # Stage 4
            self.layers.append(BatchNormLayer(rng, rout, BatchNormLayerParams(inputDim=self.layers[-1].cfgParams.outputDim), layerNum=len(self.layers)))
            self.layers.append(NonlinearityLayer(rng, self.layers[-1].output, NonlinearityLayerParams(inputDim=self.layers[-1].cfgParams.outputDim, activation=ReLU), layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output.flatten(2),
                                           HiddenLayerParams(inputDim=(self.layers[-1].cfgParams.outputDim[0], numpy.prod(self.layers[-1].cfgParams.outputDim[1:])),
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))

            self.layers.append(DropoutLayer(rng, self.layers[-1].output,
                                            DropoutLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                               outputDim=self.layers[-1].cfgParams.outputDim),
                                            layerNum=len(self.layers)))

            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))

            self.layers.append(DropoutLayer(rng, self.layers[-1].output,
                                            DropoutLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                               outputDim=self.layers[-1].cfgParams.outputDim),
                                            layerNum=len(self.layers)))

            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, self.cfgParams.numJoints*self.cfgParams.nDims),
                                                             activation=None),
                                           layerNum=len(self.layers)))

            self.output = self.layers[-1].output
        elif cfgParams.type == 4:
            # Try ResNet similar configuration
            depth = 47
            assert (depth - 2) % 9 == 0, 'depth should be 9n+2 (e.g., 164 or 1001)'
            n = (depth - 2) / 9

            nStages = [32, 64, 128, 256, 256]

            self.layers.append(ConvPoolLayer(rng, self.inputVar,
                                             ConvPoolLayerParams(inputDim=self.cfgParams.inputDim, nFilters=nStages[0],
                                                                 filterDim=(5, 5), stride=(1, 1),
                                                                 poolsize=(2, 2), border_mode='same', activation=None,
                                                                 init_method='He'),
                                             layerNum=len(self.layers)))  # one conv at the beginning
            rout = self.add_res_layers(rng, self.layers[-1].output, self.layers[-1].cfgParams.outputDim, nStages[1], n, 2)  # Stage 1
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[2], n, 2)  # Stage 2
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[3], n, 2)  # Stage 3
            rout = self.add_res_layers(rng, rout, self.layers[-1].cfgParams.outputDim, nStages[4], n, 2)  # Stage 4
            self.layers.append(BatchNormLayer(rng, rout, BatchNormLayerParams(inputDim=self.layers[-1].cfgParams.outputDim), layerNum=len(self.layers)))
            self.layers.append(NonlinearityLayer(rng, self.layers[-1].output, NonlinearityLayerParams(inputDim=self.layers[-1].cfgParams.outputDim, activation=ReLU), layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output.flatten(2),
                                           HiddenLayerParams(inputDim=(self.layers[-1].cfgParams.outputDim[0], numpy.prod(self.layers[-1].cfgParams.outputDim[1:])),
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))
            self.layers.append(DropoutLayer(rng, self.layers[-1].output,
                                            DropoutLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                               outputDim=self.layers[-1].cfgParams.outputDim),
                                            layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, 1024), activation=ReLU),
                                           layerNum=len(self.layers)))
            self.layers.append(DropoutLayer(rng, self.layers[-1].output,
                                            DropoutLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                               outputDim=self.layers[-1].cfgParams.outputDim),
                                            layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, 30), activation=None),
                                           layerNum=len(self.layers)))
            self.layers.append(HiddenLayer(rng, self.layers[-1].output,
                                           HiddenLayerParams(inputDim=self.layers[-1].cfgParams.outputDim,
                                                             outputDim=(batchSize, self.cfgParams.numJoints*self.cfgParams.nDims),
                                                             activation=None),
                                           layerNum=len(self.layers)))

            self.output = self.layers[-1].output
        else:
            raise NotImplementedError()

        self.load(self.cfgParams.loadFile)
Beispiel #4
0
    def __init__(self,
                 type=0,
                 n_chan=3,
                 w_in=128,
                 h_in=128,
                 batchSize=128,
                 output_dim=16):
        """
        Init the parametrization

        :type type: int
        :param type: type of network
        """

        super(PoseRegNetParams, self).__init__()

        self.batch_size = batchSize
        self.output_dim = output_dim
        self.inputDim = (batchSize, n_chan, h_in, w_in)

        if type == 0:  # tiny - BB8

            self.layers.append(
                ConvPoolLayerParams(inputDim=(batchSize, n_chan, h_in, w_in),
                                    nFilters=32,
                                    filterDim=(5, 5),
                                    poolsize=(4, 4),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=32,
                                    filterDim=(5, 5),
                                    poolsize=(2, 2),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=50,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            l3out = self.layers[-1].outputDim
            self.layers.append(
                HiddenLayerParams(inputDim=(l3out[0],
                                            l3out[1] * l3out[2] * l3out[3]),
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                HiddenLayerParams(inputDim=self.layers[-1].outputDim,
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                HiddenLayerParams(inputDim=self.layers[-1].outputDim,
                                  outputDim=(batchSize, output_dim),
                                  activation=None))

            self.outputDim = self.layers[-1].outputDim
        elif type == 1:
            # VGG - architecure
            self.layers.append(
                ConvPoolLayerParams(inputDim=(batchSize, n_chan, h_in, w_in),
                                    nFilters=64,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=64,
                                    filterDim=(3, 3),
                                    poolsize=(2, 2),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=128,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=128,
                                    filterDim=(3, 3),
                                    poolsize=(2, 2),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=256,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=256,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=256,
                                    filterDim=(3, 3),
                                    poolsize=(2, 2),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=512,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=512,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=512,
                                    filterDim=(3, 3),
                                    poolsize=(2, 2),
                                    activation=ReLU))

            # Last 3 conv. layers of VGG-16 archituecture are removed from BB8,
            # because of having smaller input patches
            '''
            self.layers.append(ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                                   nFilters=512,
                                                   filterDim=(3, 3),
                                                   poolsize=(1, 1),
                                                   activation=ReLU))

            self.layers.append(ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                                   nFilters=512,
                                                   filterDim=(3, 3),
                                                   poolsize=(1, 1),
                                                   activation=ReLU))

            self.layers.append(ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                                   nFilters=512,
                                                   filterDim=(3, 3),
                                                   poolsize=(2, 2),
                                                   activation=ReLU))
            '''

            l3out = self.layers[-1].outputDim
            self.layers.append(
                HiddenLayerParams(inputDim=(l3out[0],
                                            l3out[1] * l3out[2] * l3out[3]),
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                HiddenLayerParams(inputDim=self.layers[-1].outputDim,
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                HiddenLayerParams(
                    inputDim=self.layers[-1].outputDim,
                    outputDim=(batchSize, output_dim),
                    activation=None))  # last one is linear for regression

            self.outputDim = self.layers[-1].outputDim
        else:
            raise NotImplementedError("not implemented")
Beispiel #5
0
    def __init__(self,
                 type=0,
                 nChan=1,
                 wIn=128,
                 hIn=128,
                 batchSize=128,
                 numJoints=16,
                 nDims=3):
        """
        Init the parametrization

        :type type: int
        :param type: type of descr network
        """

        super(PoseRegNetParams, self).__init__()

        self.batch_size = batchSize
        self.numJoints = numJoints
        self.nDims = nDims
        self.inputDim = (batchSize, nChan, hIn, wIn)

        if type == 0:
            # Try DeepPose CNN similar configuration
            self.layers.append(
                ConvPoolLayerParams(
                    inputDim=(batchSize, nChan, hIn, wIn),  # w,h,nChannel
                    nFilters=8,
                    filterDim=(5, 5),
                    poolsize=(4, 4),
                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(5, 5),
                                    poolsize=(2, 2),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            l3out = self.layers[-1].outputDim
            self.layers.append(
                HiddenLayerParams(inputDim=(l3out[0],
                                            l3out[1] * l3out[2] * l3out[3]),
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                DropoutLayerParams(inputDim=self.layers[-1].outputDim,
                                   outputDim=self.layers[-1].outputDim))

            self.layers.append(
                HiddenLayerParams(inputDim=self.layers[-1].outputDim,
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                DropoutLayerParams(inputDim=self.layers[-1].outputDim,
                                   outputDim=self.layers[-1].outputDim))

            self.layers.append(
                HiddenLayerParams(inputDim=self.layers[-1].outputDim,
                                  outputDim=(batchSize, numJoints * nDims),
                                  activation=None))

            self.outputDim = self.layers[-1].outputDim
        elif type == 11:
            # Try DeepPose CNN similar configuration
            self.layers.append(
                ConvPoolLayerParams(
                    inputDim=(batchSize, nChan, hIn, wIn),  # w,h,nChannel
                    nFilters=8,
                    filterDim=(5, 5),
                    poolsize=(4, 4),
                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(5, 5),
                                    poolsize=(2, 2),
                                    activation=ReLU))

            self.layers.append(
                ConvPoolLayerParams(inputDim=self.layers[-1].outputDim,
                                    nFilters=8,
                                    filterDim=(3, 3),
                                    poolsize=(1, 1),
                                    activation=ReLU))

            l3out = self.layers[-1].outputDim
            self.layers.append(
                HiddenLayerParams(inputDim=(l3out[0],
                                            l3out[1] * l3out[2] * l3out[3]),
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                DropoutLayerParams(inputDim=self.layers[-1].outputDim,
                                   outputDim=self.layers[-1].outputDim))

            self.layers.append(
                HiddenLayerParams(inputDim=self.layers[-1].outputDim,
                                  outputDim=(batchSize, 1024),
                                  activation=ReLU))

            self.layers.append(
                DropoutLayerParams(inputDim=self.layers[-1].outputDim,
                                   outputDim=self.layers[-1].outputDim))

            self.layers.append(
                HiddenLayerParams(inputDim=self.layers[-1].outputDim,
                                  outputDim=(batchSize, 30),
                                  activation=None))

            self.layers.append(
                HiddenLayerParams(inputDim=self.layers[-1].outputDim,
                                  outputDim=(batchSize, numJoints * nDims),
                                  activation=None))

            self.outputDim = self.layers[-1].outputDim
        else:
            raise NotImplementedError("not implemented")