/// <summary> /// Adds a layer instance on top of the layer stack. /// </summary> /// <param name="layer"></param> public void add(ILayer layer) { built = false; var set_inputs = false; if (_layers.Count == 0) { if (layer is InputLayer) { set_inputs = true; } else { if (layer.BatchInputShape != null) { // Instantiate an input layer. var x = keras.Input( batch_input_shape: layer.BatchInputShape, dtype: layer.DType, name: layer.Name + "_input"); // This will build the current layer // and create the node connecting the current layer // to the input layer we just created. layer.Apply(x); set_inputs = true; } } if (set_inputs) { // If an input layer (placeholder) is available. outputs = layer.InboundNodes.Last().Outputs; inputs = layer_utils.get_source_inputs(outputs[0]); built = true; _has_explicit_input_shape = true; } } else if (outputs != null) { outputs = layer.Apply(outputs); built = true; } if (set_inputs || _is_graph_network) { _init_graph_network(inputs, outputs); _is_graph_network = true; } else { _self_tracked_trackables.add(layer); _handle_deferred_layer_dependencies(layer); } }
/// <summary> /// Adds a layer instance on top of the layer stack. /// </summary> /// <param name="layer"></param> public void add(ILayer layer) { built = false; var set_inputs = false; if (_layers.Count == 0) { if (layer is InputLayer) { set_inputs = true; } else { if (layer.BatchInputShape != null) { // Instantiate an input layer. var x = keras.Input( batch_input_shape: layer.BatchInputShape, dtype: layer.DType, name: layer.Name + "_input"); // This will build the current layer // and create the node connecting the current layer // to the input layer we just created. layer.Apply(x); set_inputs = true; } } if (set_inputs) { // If an input layer (placeholder) is available. outputs = layer.InboundNodes[^ 1].Outputs;
// Set forward pass. protected override Tensor[] call(Tensor inputs, bool is_training = false, Tensor state = null) { var x = fc1.Apply(inputs); throw new NotImplementedException(""); }