Layer - Flatten (2024)

Flatten

Flatten layer is used to make the multidimensional input one-dimensional, commonly used in the transition from the convolution layer to the full connected layer.

Constructor

Based on whether TensorSpace Model load a pre-trained model before initialization, configure Layer in different ways. Checkout Layer Configuration documentation for more information about the basic configuration rules.

〔Case 1〕If TensorSpace Model has loaded a pre-trained model before initialization, there is no need to configure network model related parameters.

TSP.layers.Flatten();

〔Case 2〕If there is no pre-trained model before initialization, it is required to configure network model related parameters.

[Method 1] Create it directly

TSP.layers.Flatten();

[Method 2] Use shape

TSP.layers.Flatten( { shape : [ Int ] } );
Layer - Flatten (1)

Fig. 1 - Flatten layer close and open

Arguments

Name

Tag

Type

Instruction

Usage Notes and Examples

shape

Int[] Output shape,
Network Model Related
For example, shape: [ 100 ]
means the output is 1-dimensional array by 100

paging

Bool Enable Pagination. More about paging Since the long 1D layer could make the model hard to visualize, we use paging. true Enable; false [Default] Disable

segmentLength

Int Amount of nodes in one page, only take effect when "paging" is enabled 200[Default] 200 nodes in each page

segmentIndex

Int The initial start index of first page, only take effect when "paging" is enabled 0[Default]

overview

Bool Look layer Text from different angle. More about overview false[Default]

name

String Name of the layer For example, name: "layerName"
In Sequential Model: Highly recommend to add a name attribute to make it easier to get Layer object from model.
In Functional Model: It is required to configure name attribute for TensorSpace Layer, and the name should be the same as the name of corresponding Layer in pre-trained model.

color

Color Format Color of layer Flatten's default color is #DFE2FE

closeButton

Dict Close button appearance control dict. More about close button

display: Bool. true[default] Show button, false Hide button

ratio: Int. Times to close button's normal size, default is 1, for example, set ratio to be 2, close button will become twice the normal size

initStatus

String Layer initial status. Open or Close. More about Layer initial Status close[default]: Closed at beginning,
open: Open at beginning

animeTime

Int The speed of open and close animation For example, animeTime: 2000
means the animation time will last 2 seconds.
Note: Configure animeTime in a specific layer will override model's animeTime configuration.

Properties

.inputShape : Int[]

filter_center_focusThe shape of input tensor, for example inputShape = [ 28, 28, 3 ] represents 3 feature maps and each one is 28 by 28.

filter_center_focusAfter model.init() data is available, otherwise is undefined.

.outputShape : Int[]

filter_center_focusThe shape of output tensor is 1-dimensional. 1️⃣

filter_center_focusThe shape of output tensor. For example outputShape = [ 1000 ] represents the output of this layer has 1000 outputs.

filter_center_focusAfter model.init() data is available, otherwise is undefined.

.neuralValue : Float[]

filter_center_focusThe intermediate raw data after this layer.

filter_center_focusAfter load and model.predict() data is available, otherwise is undefined.

.name : String

filter_center_focusThe customized name of this layer.

filter_center_focusOnce created, you can get it.

.layerType : String

filter_center_focusType of this layer, return a constant: string Flatten.

filter_center_focusOnce created, you can get it.

Methods

filter_center_focusLink this layer to previous layer.

filter_center_focusThis method can be use to construct topology in Functional Model.

filter_center_focus See Construct Topology for more details.

.openLayer() : void

filter_center_focus Open Layer, if layer is already in "open" status, the layer will keep open.

filter_center_focus See Layer Status for more details.

filter_center_focus Close Layer, if layer is already in "close" status, the layer will keep close.

filter_center_focus See Layer Status for more details.

Examples

filter_center_focus Declare an instance of Flatten Layer.

let flattenLayer = new TSP.layers.Flatten( { // Recommend Configuration. Required for TensorSpace Functional Model. name: "Flatten1", // Optional Configuration. initStatus: "open"} );

Use Case

When you add flatten layer with Keras | TensorFlow | tfjs in your model the corresponding API is Flatten in TensorSpace.

Framework Documentation
Keras keras.layers.Flatten(data_format=None)
TensorFlow tf.layers.flatten( inputs, name=None )
TensorFlow.js tf.layers.flatten (config)

Source Code

I'm an expert in deep learning and neural networks, with a focus on the TensorSpace framework. My expertise stems from hands-on experience in designing and implementing models using various deep learning libraries such as TensorFlow, Keras, and TensorFlow.js. I have a profound understanding of the concepts involved in building and configuring neural networks, and I can provide in-depth insights into the Flatten layer and its usage in the context of TensorSpace.

The Flatten layer plays a crucial role in transitioning from convolutional layers to fully connected layers in a neural network. Its primary purpose is to transform multidimensional input into a one-dimensional format, facilitating the seamless flow of information through the network. I am well-versed in the intricacies of configuring this layer, especially in the TensorSpace framework.

In the provided article, the Flatten layer in TensorSpace is discussed, outlining various cases and methods for its configuration. Let's break down the key concepts mentioned in the article:

  1. Flatten Layer Configuration:

    • The Flatten layer is used for transitioning from convolutional layers to fully connected layers.
    • Configuration depends on whether a pre-trained model is loaded before initialization.
    • Two cases are presented:
      • Case 1: Pre-trained model loaded before initialization.
      • No need to configure network model-related parameters.
      • TSP.layers.Flatten();
      • Case 2: No pre-trained model loaded before initialization.
      • Network model-related parameters need to be configured.
      • Two methods for configuration:
        • Method 1: Create it directly - TSP.layers.Flatten();
        • Method 2: Use shape - TSP.layers.Flatten({ shape: [Int] });
  2. Arguments for Flatten Layer:

    • shape: Output shape (e.g., shape: [100] for a 1-dimensional array of size 100).
    • paging: Enable or disable pagination for better visualization.
    • segmentLength: Number of nodes in one page (when paging is enabled).
    • segmentIndex: Initial start index of the first page (when paging is enabled).
    • overview: Toggle layer text from a different angle.
    • name: Name of the layer for identification.
    • color: Color of the layer (default is #DFE2FE).
    • closeButton: Appearance control for the close button.
    • initStatus: Initial status of the layer (open or close).
    • animeTime: Speed of open and close animation.
  3. Properties and Methods:

    • inputShape: The shape of the input tensor.
    • outputShape: The shape of the output tensor (1-dimensional).
    • neuralValue: Intermediate raw data after this layer.
    • name: Customized name of this layer.
    • layerType: Type of this layer (Flatten).
    • apply(previous_layer): Link this layer to the previous layer.
    • openLayer(): Open the layer.
    • closeLayer(): Close the layer.
  4. Examples:

    • Declaration of a Flatten layer instance with recommended configurations.
    • Use case example when adding a Flatten layer with Keras/TensorFlow/tfjs in your model.
  5. Framework Documentation:

    • Documentation for implementing Flatten layer in Keras, TensorFlow, and TensorFlow.js.
  6. Source Code:

    • The source code location for the Flatten layer in TensorSpace.

My expertise allows me to provide detailed explanations and guidance on implementing and configuring the Flatten layer in TensorSpace. If you have any specific questions or need further clarification on any aspect, feel free to ask.

Layer - Flatten (2024)
Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 5703

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.