Skip to content

Commit

Permalink
convert Min Prod Reciprocal Sigmoid Square
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui committed Sep 27, 2017
1 parent 7f2adcd commit 222bec5
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion tools/tensorflow/tensorflow2ncnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ int main(int argc, char** argv)
{
isBinaryOp = true;
}
if (node.op() == "Max" || node.op() == "Maximum")
if (node.op() == "Max" || node.op() == "Maximum" || node.op() == "Min" || node.op() == "Minimum")
{
// check weights
tensorflow::TensorProto tensor;
Expand Down Expand Up @@ -380,6 +380,19 @@ int main(int argc, char** argv)
{
fprintf(pp, "%-16s", "Pooling");
}
else if (node.op() == "Min" || node.op() == "Minimum")
{
// check weights
tensorflow::TensorProto tensor;
if (find_tensor_proto(weights, node, tensor))
{
fprintf(pp, "%-16s", "Reduction");
}
else
{
fprintf(pp, "%-16s", "BinaryOp");
}
}
else if (node.op() == "Mul")
{
fprintf(pp, "%-16s", "BinaryOp");
Expand All @@ -400,10 +413,18 @@ int main(int argc, char** argv)
{
fprintf(pp, "%-16s", "Input");
}
else if (node.op() == "Prod")
{
fprintf(pp, "%-16s", "Reduction");
}
else if (node.op() == "RealDiv")
{
fprintf(pp, "%-16s", "BinaryOp");
}
else if (node.op() == "Reciprocal")
{
fprintf(pp, "%-16s", "UnaryOp");
}
else if (node.op() == "Relu")
{
fprintf(pp, "%-16s", "ReLU");
Expand All @@ -416,10 +437,18 @@ int main(int argc, char** argv)
{
fprintf(pp, "%-16s", "UnaryOp");
}
else if (node.op() == "Sigmoid")
{
fprintf(pp, "%-16s", "Sigmoid");
}
else if (node.op() == "Softmax")
{
fprintf(pp, "%-16s", "Softmax");
}
else if (node.op() == "Square")
{
fprintf(pp, "%-16s", "UnaryOp");
}
else if (node.op() == "Sub")
{
fprintf(pp, "%-16s", "BinaryOp");
Expand Down Expand Up @@ -887,6 +916,26 @@ int main(int argc, char** argv)

fprintf(pp, " %d %d %d %d %d", pooling_type, kernel_size_w, stride_w, pad, global_pooling);
}
else if (node.op() == "Min" || node.op() == "Minimum")
{
// check weights
tensorflow::TensorProto tensor;
if (find_tensor_proto(weights, node, tensor))
{
int operation = 5;
int dim = 0;
float coeff = 1.f;

dim = parse_tensor_reduction_dim(tensor);

fprintf(pp, " %d %d %f", operation, dim, coeff);
}
else
{
int op_type = 5;
fprintf(pp, " %d", op_type);
}
}
else if (node.op() == "Mul")
{
int op_type = 2;
Expand Down Expand Up @@ -948,11 +997,31 @@ int main(int argc, char** argv)
// TODO pass through
fprintf(pp, " 0 0 0");
}
else if (node.op() == "Prod")
{
int operation = 6;
int dim = 0;
float coeff = 1.f;

// check weights
tensorflow::TensorProto tensor;
if (find_tensor_proto(weights, node, tensor))
{
dim = parse_tensor_reduction_dim(tensor);
}

fprintf(pp, " %d %d %f", operation, dim, coeff);
}
else if (node.op() == "RealDiv")
{
int op_type = 3;
fprintf(pp, " %d", op_type);
}
else if (node.op() == "Reciprocal")
{
int op_type = 15;
fprintf(pp, " %d", op_type);
}
else if (node.op() == "Relu")
{
float slope = 0.f;
Expand Down Expand Up @@ -996,9 +1065,17 @@ int main(int argc, char** argv)
int op_type = 6;
fprintf(pp, " %d", op_type);
}
else if (node.op() == "Sigmoid")
{
}
else if (node.op() == "Softmax")
{
}
else if (node.op() == "Square")
{
int op_type = 4;
fprintf(pp, " %d", op_type);
}
else if (node.op() == "Sub")
{
int op_type = 1;
Expand Down

0 comments on commit 222bec5

Please sign in to comment.