TensorSpace.js
Getting Start
Basic Concepts
Model Preprocessing
Models
Layers
Merge Function
Reshape
Constructor
Reshape is a factory function which generates the proper object based on the provided targetShape argument.

If the input has shape 1d, then it returns a 1d TSP.layers.Reshape1d;

if the input has shape 2d, then it returns a 2d TSP.layers.Reshape2d;

if the input has shape 3d, then it returns a 3d TSP.layers.Reshape3d.

〔Method 1〕Use targetShape
TSP.layers.Reshape( { targetShape : Int[] } );
〔Method 2〕Use shape
TSP.layers.Reshape( { shape : Int[] } );
Fig. 1 - Reshape layer collapse and expand
Arguments

Name

Tag

Type

Instruction

Usage Notes and Examples

targetShape

⭐️📦

Int[] Output shape The product of both input and output shape dimension lengths should be the same.

name

🔧

String Name of this layer. Highly recommend to arrange to make code more readable. name: "layerName"

color

⚙️🎨

color format Color of layer Reshape default is light purple #A287F4

closeButton

⚙️🎨

Dict Close button appearance control dict, more about close button

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

ratio : Int. Times to normal size, default is 1

For example, 2 means twice the normal size

initStatus

⚙️️🎦

String Layer status at beginning. Open or Close close[default] : Closed at beginning

animeTime

⚙️🎦

Int The speed of open and close animation For example, 2000 means 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 the output tensor is 3-dimensional. 3️⃣
filter_center_focusThe dataFormat is "channel last". For example, outputShape = [ 32, 32, 4 ] represents the output through this layer has 4 feature maps and each one is 32 by 32.
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.init(), the data are available. Otherwise is undefined.
.name : String
filter_center_focusThe custom name for this layer.
filter_center_focusOnce created, you can get it.
.layerType : String
filter_center_focusType of this layer. There are 3 possible types: if targetShape has length 1, return string Reshape1d; if targetShape has length 2, return string Reshape2d; if targetShape has length 3, return string Reshape3d.
filter_center_focusOnce created, you can get it.
Method
filter_center_focusThis method only used in Functional Model (Non-sequential, Graph structure).
filter_center_focusLink this layer to layer which is the previous layer.
filter_center_focusTo crete a link between this layer and the previous layer. You don't need to use this method specifically to create links in Sequential Model; Instead, you can simply add layers along the lines of Keras or TensorFlow.js build the model syntax.
let inputLayer = new TSP.layers.GreyscaleInput( {

    shape: [28, 28]

} );

let reshapeLayer = new TSP.layers.Reshape( {

    targetShape: [ 7, 7, 16 ],
    name: "Reshape1",
    initStatus: "open",
    animeTime: 4000

} );

reshapeLayer.apply( inputLayer );
.openLayer() : void
filter_center_focusClick on the layer directly to open it by interacting directly with the object in the 3D scene.
filter_center_focusIn code, calling the method to open it.
let reshapedLayer = new TSP.layers.Reshape( {

    // configure some parameters for reshapedLayer.

} );

model.add( reshapedLayer );

// ... add more layers for model.

model.init();

// Call openLayer API to open layer.

reshapedLayer.openLayer();
filter_center_focusTo close by interacting directly with objects in a 3D scene by clicking the close button.
filter_center_focus In code, calling the method to close it.
let reshapedLayer = new TSP.layers.Reshape( {

    // configure some parameters for reshapedLayer.

} );

model.add( reshapedLayer );

// ... add more layers for model.

model.init();

// If this layer already opened, call closeLayer API to close layer.

reshapedLayer.closeLayer();
Example
filter_center_focus Declare an instance of Conv2D to facilitate reuse
let reshapedLayer = new TSP.layers.Reshape( {

    targetShape: [ 24, 24 ],
    name: "Reshape1",
    initStatus: "open",
    animeTime: 4000

} );

model.add( reshapedLayer );
filter_center_focusAdd Conv2D directly
model.add(new TSP.layers.Reshape( {

    targetShape: [ 24, 24 ],
    name: "Reshape1",
    initStatus: "open",
    animeTime: 4000

} ));
Use Case
When you add reshape layer with Keras | TensorFlow | tfjs in your model the corresponding API is Reshape in TensorSpace.
Framework Documentation
Keras keras.layers.Reshape(target_shape)
TensorFlow tf.reshape( tensor, shape )
TensorFlow.js tf.layers.reshape({targetShape: [2, 6]})
Tag Lookup
Tag Icon Meaning Instruction
⭐️ Required Must be provided, cannot be empty. Meanwhile constructor works properly if this arguments provided. Control arguments use default value.
🔧 Suggest Recommended for giving. The API can work without them.
⚙️️ Optional As an auxiliary adjustment parameter when used, selectively added according to the specific situation The parameters here have no effect on the structure of the layer (3D visualized form).
📦 Model Configure the properties of the Layer. It changes the output shape.
🎨 Style Override the properties in TSP.model (model configuration)
🎦 Animation Override the properties in TSP.model (model configuration)
Source Code
tensorspace/src/layer/intermediate/Reshape.js