pt_layer.cpp 2.33 KB
Newer Older
Gustavo Valiente's avatar
Gustavo Valiente committed
1
/*
Gustavo Valiente's avatar
Gustavo Valiente committed
2
 * pocket-tensor (c) 2018 Gustavo Valiente gustavo.valiente.m@gmail.com
Gustavo Valiente's avatar
Gustavo Valiente committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * Kerasify (c) 2016 Robert W. Rose
 *
 * MIT License, see LICENSE file.
 */

#include "pt_layer.h"

#include "pt_parser.h"
#include "pt_dense_layer.h"
#include "pt_conv_1d_layer.h"
#include "pt_conv_2d_layer.h"
#include "pt_locally_connected_1d_layer.h"
#include "pt_flatten_layer.h"
#include "pt_elu_layer.h"
#include "pt_activation_layer.h"
#include "pt_max_pooling_2d_layer.h"
#include "pt_lstm_layer.h"
#include "pt_embedding_layer.h"
#include "pt_batch_normalization_layer.h"
22
#include "pt_leaky_relu_layer.h"
Gustavo Valiente's avatar
Gustavo Valiente committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

namespace pt
{

namespace
{
    enum LayerType
    {
        Dense = 1,
        Conv1D = 2,
        Conv2D = 3,
        LocallyConnected1D = 4,
        Flatten = 6,
        Elu = 7,
        Activation = 8,
        MaxPooling2D = 9,
        Lstm = 10,
        Embedding = 11,
        BatchNormalization = 12,
42
        LeakyRelu = 13
Gustavo Valiente's avatar
Gustavo Valiente committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    };
}

std::unique_ptr<Layer> Layer::create(std::istream& stream)
{
    unsigned int layerID = 0;

    if(! Parser::parse(stream, layerID))
    {
        PT_LOG_ERROR << "Layer ID parse failed" << std::endl;
        return std::unique_ptr<Layer>();
    }

    std::unique_ptr<Layer> layer;

    switch(layerID)
    {

    case Dense:
        layer = DenseLayer::create(stream);
        break;

    case Conv1D:
        layer = Conv1DLayer::create(stream);
        break;

    case Conv2D:
        layer = Conv2DLayer::create(stream);
        break;

    case LocallyConnected1D:
        layer = LocallyConnected1DLayer::create(stream);
        break;

    case Flatten:
        layer.reset(new FlattenLayer());
        break;

    case Elu:
        layer = EluLayer::create(stream);
        break;

    case Activation:
        layer = ActivationLayer::create(stream);
        break;

    case MaxPooling2D:
        layer = MaxPooling2DLayer::create(stream);
        break;

    case Lstm:
        layer = LstmLayer::create(stream);
        break;

    case Embedding:
        layer = EmbeddingLayer::create(stream);
        break;

    case BatchNormalization:
        layer = BatchNormalizationLayer::create(stream);
        break;

105 106 107 108
    case LeakyRelu:
        layer = LeakyReluLayer::create(stream);
        break;

Gustavo Valiente's avatar
Gustavo Valiente committed
109 110 111 112 113 114 115 116 117 118 119 120
    default:
        PT_LOG_ERROR << "Unknown layer ID: " << layerID << std::endl;
    }

    return layer;
}

Layer::~Layer() noexcept
{
}

}