本文整理汇总了C++中Series::AddToStack方法的典型用法代码示例。如果您正苦于以下问题:C++ Series::AddToStack方法的具体用法?C++ Series::AddToStack怎么用?C++ Series::AddToStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Series
的用法示例。
在下文中一共展示了Series::AddToStack方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseC
// Parses a network that begins with 'C'.
Network* NetworkBuilder::ParseC(const StaticShape& input_shape, char** str) {
NetworkType type = NonLinearity((*str)[1]);
if (type == NT_NONE) {
tprintf("Invalid nonlinearity on C-spec!: %s\n", *str);
return nullptr;
}
int y = 0, x = 0, d = 0;
if ((y = strtol(*str + 2, str, 10)) <= 0 || **str != ',' ||
(x = strtol(*str + 1, str, 10)) <= 0 || **str != ',' ||
(d = strtol(*str + 1, str, 10)) <= 0) {
tprintf("Invalid C spec!:%s\n", *str);
return nullptr;
}
if (x == 1 && y == 1) {
// No actual convolution. Just a FullyConnected on the current depth, to
// be slid over all batch,y,x.
return new FullyConnected("Conv1x1", input_shape.depth(), d, type);
}
Series* series = new Series("ConvSeries");
Convolve* convolve =
new Convolve("Convolve", input_shape.depth(), x / 2, y / 2);
series->AddToStack(convolve);
StaticShape fc_input = convolve->OutputShape(input_shape);
series->AddToStack(new FullyConnected("ConvNL", fc_input.depth(), d, type));
return series;
}
示例2: ParseOutput
// Parses an Output spec.
Network* NetworkBuilder::ParseOutput(const StaticShape& input_shape,
char** str) {
char dims_ch = (*str)[1];
if (dims_ch != '0' && dims_ch != '1' && dims_ch != '2') {
tprintf("Invalid dims (2|1|0) in output spec!:%s\n", *str);
return nullptr;
}
char type_ch = (*str)[2];
if (type_ch != 'l' && type_ch != 's' && type_ch != 'c') {
tprintf("Invalid output type (l|s|c) in output spec!:%s\n", *str);
return nullptr;
}
int depth = strtol(*str + 3, str, 10);
if (depth != num_softmax_outputs_) {
tprintf("Warning: given outputs %d not equal to unicharset of %d.\n", depth,
num_softmax_outputs_);
depth = num_softmax_outputs_;
}
NetworkType type = NT_SOFTMAX;
if (type_ch == 'l')
type = NT_LOGISTIC;
else if (type_ch == 's')
type = NT_SOFTMAX_NO_CTC;
if (dims_ch == '0') {
// Same as standard fully connected.
return BuildFullyConnected(input_shape, type, "Output", depth);
} else if (dims_ch == '2') {
// We don't care if x and/or y are variable.
return new FullyConnected("Output2d", input_shape.depth(), depth, type);
}
// For 1-d y has to be fixed, and if not 1, moved to depth.
if (input_shape.height() == 0) {
tprintf("Fully connected requires fixed height!\n");
return nullptr;
}
int input_size = input_shape.height();
int input_depth = input_size * input_shape.depth();
Network* fc = new FullyConnected("Output", input_depth, depth, type);
if (input_size > 1) {
Series* series = new Series("FCSeries");
series->AddToStack(new Reconfig("FCReconfig", input_shape.depth(), 1,
input_shape.height()));
series->AddToStack(fc);
fc = series;
}
return fc;
}
示例3: BuildFullyConnected
// Helper builds a truly (0-d) fully connected layer of the given type.
static Network* BuildFullyConnected(const StaticShape& input_shape,
NetworkType type, const STRING& name,
int depth) {
if (input_shape.height() == 0 || input_shape.width() == 0) {
tprintf("Fully connected requires positive height and width, had %d,%d\n",
input_shape.height(), input_shape.width());
return nullptr;
}
int input_size = input_shape.height() * input_shape.width();
int input_depth = input_size * input_shape.depth();
Network* fc = new FullyConnected(name, input_depth, depth, type);
if (input_size > 1) {
Series* series = new Series("FCSeries");
series->AddToStack(new Reconfig("FCReconfig", input_shape.depth(),
input_shape.width(), input_shape.height()));
series->AddToStack(fc);
fc = series;
}
return fc;
}
示例4: ParseSeries
// Parses a sequential series of networks, defined by [<net><net>...].
Network* NetworkBuilder::ParseSeries(const StaticShape& input_shape,
Input* input_layer, char** str) {
StaticShape shape = input_shape;
Series* series = new Series("Series");
++*str;
if (input_layer != nullptr) {
series->AddToStack(input_layer);
shape = input_layer->OutputShape(shape);
}
Network* network = NULL;
while (**str != '\0' && **str != ']' &&
(network = BuildFromString(shape, str)) != NULL) {
shape = network->OutputShape(shape);
series->AddToStack(network);
}
if (**str != ']') {
tprintf("Missing ] at end of [Series]!\n");
delete series;
return NULL;
}
++*str;
return series;
}