Skip to content

Commit fd77a82

Browse files
committed
fix Layer style as nekit
1 parent 78c627c commit fd77a82

9 files changed

Lines changed: 15 additions & 43 deletions

File tree

app/Graph/build.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
298298

299299
auto input_layer = std::make_shared<it_lab_ai::InputLayer>(it_lab_ai::kNchw,
300300
it_lab_ai::kNchw);
301-
input_layer->setName(it_lab_ai::kInput);
302301
layers.push_back(input_layer);
303302
name_to_layer[input_layer_name] = input_layer;
304303
int current_id = 0;
@@ -374,16 +373,13 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
374373

375374
auto conv_layer = std::make_shared<it_lab_ai::ConvolutionalLayer>(
376375
stride, pads, dilations, tmp_tensor, tmp_bias, impl2, group);
377-
conv_layer->setName(it_lab_ai::kConvolution);
378376
layer = conv_layer;
379377
} else if (layer_type.find("Relu") != std::string::npos ||
380378
layer_type.find("relu") != std::string::npos) {
381379
auto ew_layer = std::make_shared<it_lab_ai::EWLayer>("relu");
382-
ew_layer->setName(it_lab_ai::kElementWise);
383380
layer = ew_layer;
384381
} else if (layer_type.find("Sigmoid") != std::string::npos) {
385382
auto ew_layer = std::make_shared<it_lab_ai::EWLayer>("sigmoid");
386-
ew_layer->setName(it_lab_ai::kElementWise);
387383
layer = ew_layer;
388384

389385
} else if (layer_type.find("Dense") != std::string::npos ||
@@ -404,11 +400,9 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
404400
it_lab_ai::Tensor tmp_bias = it_lab_ai::make_tensor(tensor.get_bias());
405401
auto fc_layer =
406402
std::make_shared<it_lab_ai::FCLayer>(tmp_tensor, tmp_bias);
407-
fc_layer->setName(it_lab_ai::kFullyConnected);
408403
layer = fc_layer;
409404
} else if (layer_type.find("Dropout") != std::string::npos) {
410405
auto dropout_layer = std::make_shared<it_lab_ai::DropOutLayer>(0.0);
411-
dropout_layer->setName(it_lab_ai::kDropout);
412406
layer = dropout_layer;
413407
if (comments)
414408
std::cout
@@ -418,7 +412,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
418412
} else if (layer_type == "GlobalAveragePool") {
419413
auto pool_layer = std::make_shared<it_lab_ai::PoolingLayer>(
420414
it_lab_ai::Shape({0, 0}), "average", impl1);
421-
pool_layer->setName(it_lab_ai::kPooling);
422415
layer = pool_layer;
423416
if (comments) {
424417
std::cout << "GlobalAveragePool layer added (will use input spatial "
@@ -503,8 +496,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
503496
<< e.what() << std::endl;
504497
}
505498
}
506-
507-
pool_layer->setName(it_lab_ai::kPooling);
508499
layer = pool_layer;
509500
} else if (layer_type.find("Flatten") != std::string::npos) {
510501
int axis = 1;
@@ -516,7 +507,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
516507
}
517508
}
518509
auto flatten_layer = std::make_shared<it_lab_ai::FlattenLayer>(axis);
519-
flatten_layer->setName(it_lab_ai::kFlatten);
520510
layer = flatten_layer;
521511
} else if (layer_type == "Concat") {
522512
int axis = 0;
@@ -531,7 +521,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
531521
}
532522
}
533523
auto concat_layer = std::make_shared<it_lab_ai::ConcatLayer>(axis);
534-
concat_layer->setName(it_lab_ai::kConcat);
535524
layer = concat_layer;
536525
concat_connected_inputs[layer_name] = std::unordered_set<std::string>();
537526
} else if (layer_type == "Split") {
@@ -564,7 +553,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
564553

565554
auto split_layer =
566555
std::make_shared<it_lab_ai::SplitLayer>(axis, splits);
567-
split_layer->setName(it_lab_ai::kSplit);
568556
layer = split_layer;
569557

570558
split_layers[layer_name] = split_layer;
@@ -619,7 +607,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
619607
ew_operation = "linear";
620608
auto ew_layer =
621609
std::make_shared<it_lab_ai::EWLayer>(ew_operation, value, 0.0F);
622-
ew_layer->setName(it_lab_ai::kElementWise);
623610
layer = ew_layer;
624611
if (comments) {
625612
std::cout << "Created binary " << layer_type << " operation with "
@@ -629,13 +616,11 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
629616
ew_operation = "linear";
630617
auto ew_layer =
631618
std::make_shared<it_lab_ai::EWLayer>(ew_operation, 1.0F, value);
632-
ew_layer->setName(it_lab_ai::kElementWise);
633619
layer = ew_layer;
634620
} else if (layer_type == "Sub") {
635621
ew_operation = "linear";
636622
auto ew_layer = std::make_shared<it_lab_ai::EWLayer>(ew_operation,
637623
1.0F, -value);
638-
ew_layer->setName(it_lab_ai::kElementWise);
639624
layer = ew_layer;
640625
} else {
641626
continue;
@@ -652,7 +637,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
652637
op = it_lab_ai::BinaryOpLayer::Operation::kDiv;
653638

654639
auto bin_layer = std::make_shared<it_lab_ai::BinaryOpLayer>(op);
655-
bin_layer->setName(it_lab_ai::kBinaryOp);
656640
layer = bin_layer;
657641
}
658642
} else if (layer_type == "Gemm") {
@@ -716,7 +700,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
716700

717701
auto fc_layer =
718702
std::make_shared<it_lab_ai::FCLayer>(tmp_tensor, tmp_bias);
719-
fc_layer->setName(it_lab_ai::kFullyConnected);
720703
layer = fc_layer;
721704
} else if (layer_type == "Transpose" ||
722705
layer_type.find("transpose") != std::string::npos) {
@@ -733,7 +716,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
733716

734717
auto transpose_layer =
735718
std::make_shared<it_lab_ai::TransposeLayer>(perm);
736-
transpose_layer->setName(it_lab_ai::kTranspose);
737719
layer = transpose_layer;
738720

739721
if (comments) {
@@ -779,7 +761,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
779761

780762
auto reshape_layer =
781763
std::make_shared<it_lab_ai::ReshapeLayer>(allowzero, shape);
782-
reshape_layer->setName(it_lab_ai::kReshape);
783764
layer = reshape_layer;
784765

785766
} else if (layer_type == "ReduceMean") {
@@ -800,7 +781,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
800781
}
801782
auto reduce_layer = std::make_shared<it_lab_ai::ReduceLayer>(
802783
it_lab_ai::ReduceLayer::Operation::kMean, keepdims, axes);
803-
reduce_layer->setName(it_lab_ai::kReduce);
804784
layer = reduce_layer;
805785
} else if (layer_type == "ReduceSum") {
806786
int64_t keepdims = 0;
@@ -828,7 +808,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
828808
}
829809
auto reduce_layer = std::make_shared<it_lab_ai::ReduceLayer>(
830810
it_lab_ai::ReduceLayer::Operation::kSum, keepdims, axes);
831-
reduce_layer->setName(it_lab_ai::kReduce);
832811
layer = reduce_layer;
833812
} else if (layer_type == "Constant") {
834813
if (layer_data.contains("attributes")) {
@@ -852,7 +831,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
852831
continue;
853832
} else if (layer_type == "MatMul") {
854833
auto matmul_layer = std::make_shared<it_lab_ai::MatmulLayer>();
855-
matmul_layer->setName(it_lab_ai::kMatmul);
856834
layer = matmul_layer;
857835

858836
} else if (layer_type == "Softmax") {
@@ -865,7 +843,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
865843
}
866844
}
867845
auto softmax_layer = std::make_shared<it_lab_ai::SoftmaxLayer>(axis);
868-
softmax_layer->setName(it_lab_ai::kSoftmax);
869846
layer = softmax_layer;
870847

871848
} else if (layer_type == "BatchNormalization") {
@@ -932,7 +909,6 @@ void build_graph(it_lab_ai::Tensor& input, it_lab_ai::Tensor& output,
932909

933910
auto bn_layer = std::make_shared<it_lab_ai::BatchNormalizationLayer>(
934911
scale, bias, mean, var, epsilon, momentum, training_mode);
935-
bn_layer->setName(it_lab_ai::kBatchNormalization);
936912
layer = bn_layer;
937913
} else {
938914
continue;

include/graph/graph.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ class Graph {
6666
V_ = 0;
6767
in_edges_.clear();
6868
}
69-
69+
7070
void setSplitDistribution(
7171
const std::vector<std::vector<std::pair<int, int>>>& split_dist) {
7272
split_distribution_ = split_dist;
7373
}
74-
74+
7575
int getVertexValue(size_t layerID) const {
7676
if (layerID >= arrayV_.size()) {
7777
throw std::invalid_argument("ArrayV does not contain this ID.");
@@ -100,7 +100,7 @@ class Graph {
100100
}
101101
return *layers_[layerID];
102102
}
103-
103+
104104
void setInput(Layer& lay, Tensor& vec) {
105105
lay.setID(0);
106106
layers_.push_back(&lay);

include/layers/BatchNormalizationLayer.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class BatchNormalizationLayer : public Layer {
1212
const Tensor& mean, const Tensor& var,
1313
float epsilon = 1e-5F, float momentum = 0.9F,
1414
bool training_mode = false)
15-
: scale_(scale),
15+
: Layer(kBatchNormalization), scale_(scale),
1616
bias_(bias),
1717
mean_(mean),
1818
var_(var),
@@ -27,8 +27,6 @@ class BatchNormalizationLayer : public Layer {
2727
Tensor get_weights() override { return Tensor(); }
2828
#endif
2929

30-
static std::string get_name() { return "BatchNormalizationLayer"; }
31-
3230
void set_epsilon(float epsilon) { epsilon_ = epsilon; }
3331
void set_momentum(float momentum) { momentum_ = momentum; }
3432
void set_training_mode(bool training_mode) { training_mode_ = training_mode; }

include/layers/ConvLayer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class ConvolutionalLayer : public Layer {
2929
ConvolutionalLayer(size_t step, size_t pads, size_t dilations,
3030
const Tensor& kernel, const Tensor& bias = Tensor(),
3131
ImplType implType = kDefault, size_t group = 1,
32-
bool useLegacyImpl = false): Layer(kConvolution) {
32+
bool useLegacyImpl = false)
33+
: Layer(kConvolution) {
3334
stride_ = step;
3435
pads_ = pads;
3536
group_ = group;

include/layers/FlattenLayer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class FlattenLayer : public Layer {
1616
public:
1717
FlattenLayer() : Layer(kFlatten), order_({0, 1, 2, 3}), axis_(0) {}
1818
FlattenLayer(int axis) : Layer(kFlatten), order_({}), axis_(axis) {}
19-
FlattenLayer(const std::vector<size_t>& order) : Layer(kFlatten), order_(order), axis_(0) {}
19+
FlattenLayer(const std::vector<size_t>& order)
20+
: Layer(kFlatten), order_(order), axis_(0) {}
2021
void run(const std::vector<Tensor>& input,
2122
std::vector<Tensor>& output) override;
2223
#ifdef ENABLE_STATISTIC_WEIGHTS

include/layers/MatmulLayer.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace it_lab_ai {
88

99
class MatmulLayer : public Layer {
1010
public:
11-
MatmulLayer() = default;
11+
MatmulLayer() : Layer(kMatmul) {}
1212

1313
void run(const std::vector<Tensor>& input,
1414
std::vector<Tensor>& output) override;
@@ -17,8 +17,6 @@ class MatmulLayer : public Layer {
1717
Tensor get_weights() override { return Tensor(); }
1818
#endif
1919

20-
static std::string get_name() { return "MatMulLayer"; }
21-
2220
private:
2321
template <typename T>
2422
void matmul_impl(const Tensor& a, const Tensor& b, Tensor& output) const;

include/layers/PoolingLayer.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class PoolingLayer : public Layer {
2323
const Shape& dilations = {1, 1}, bool ceil_mode = false,
2424
std::string pooling_type = "average",
2525
ImplType implType = kDefault)
26-
: Layer(kPooling), poolingShape_(pooling_shape),
26+
: Layer(kPooling),
27+
poolingShape_(pooling_shape),
2728
strides_(strides),
2829
pads_(pads),
2930
dilations_(dilations),
@@ -32,7 +33,8 @@ class PoolingLayer : public Layer {
3233
implType_(implType) {}
3334
PoolingLayer(const Shape& pooling_shape, std::string pooling_type = "average",
3435
ImplType implType = kDefault)
35-
: Layer(kPooling), poolingShape_(pooling_shape),
36+
: Layer(kPooling),
37+
poolingShape_(pooling_shape),
3638
strides_({2, 2}),
3739
pads_({0, 0, 0, 0}),
3840
dilations_({1, 1}),

include/layers/ReshapeLayer.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ReshapeLayer : public Layer {
1010
public:
1111
explicit ReshapeLayer(bool allowzero = false,
1212
const std::vector<int64_t>& shape = {})
13-
: allowzero_(allowzero), shape_(shape) {}
13+
: Layer(kReshape), allowzero_(allowzero), shape_(shape) {}
1414

1515
void run(const std::vector<Tensor>& input,
1616
std::vector<Tensor>& output) override;
@@ -19,8 +19,6 @@ class ReshapeLayer : public Layer {
1919
Tensor get_weights() override { return Tensor(); }
2020
#endif
2121

22-
static std::string get_name() { return "ReshapeLayer"; }
23-
2422
void set_shape(const std::vector<int64_t>& shape) { shape_ = shape; }
2523
void set_allowzero(bool allowzero) { allowzero_ = allowzero; }
2624

include/layers/SoftmaxLayer.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace it_lab_ai {
1111

1212
class SoftmaxLayer : public Layer {
1313
public:
14-
explicit SoftmaxLayer(int axis = -1) : axis_(axis) {}
14+
explicit SoftmaxLayer(int axis = -1) : Layer(kSoftmax), axis_(axis) {}
1515

1616
void run(const std::vector<Tensor>& input,
1717
std::vector<Tensor>& output) override;
@@ -20,8 +20,6 @@ class SoftmaxLayer : public Layer {
2020
Tensor get_weights() override { return Tensor(); }
2121
#endif
2222

23-
static std::string get_name() { return "SoftmaxLayer"; }
24-
2523
void set_axis(int axis) { axis_ = axis; }
2624
int get_axis() const { return axis_; }
2725

0 commit comments

Comments
 (0)