Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Crop2DLayer

Neural network layer in a neural network that can be used to crop an input feature map

Description

A crop layer contains information about how to crop a feature map.

A crop layer has two inputs:

  • 'in' — The feature map that will be cropped

  • 'ref' — A reference layer used to determine the size, [height width], of the cropped output

Once you create this layer, you can add it to a layerGraph to make serial connections between layers. To connect the crop layer to other layers, call connectLayers and specify the input names. The connectLayers function returns a connected LayerGraph object ready to train a network. Connecting layers requires Neural Network Toolbox™.

Creation

Syntax

layer = crop2dLayer('centercrop')
layer = crop2dLayer(Location)
layer = crop2dLayer(___,'Name',Name)

Description

layer = crop2dLayer('centercrop') returns a layer that crops an input feature map, and sets the Mode property.

layer = crop2dLayer(Location) returns a layer that crops an input feature map using a rectangular window, and sets the Location property that indicates the position of the window.

layer = crop2dLayer(___,'Name',Name) creates a layer for cropping and sets the optional Name property.

Properties

expand all

Layer name, specified as a character vector. If Name is set to '', then the software automatically assigns a name at training time.

Data Types: char

Cropping mode, specified as 'centercrop' or 'custom'.

ModeDescription
'centercrop'The location of the cropping window is the center of the input feature map.
'custom'The location of the cropping window is based on the Location property. This value is automatically set when the Location property is specified as a 2-element row vector.

Data Types: char

Cropping window location, specified as 'auto' or a 2-element row vector.

LocationDescription

2-element row vector in the format [x y]

The upper-left corner of the cropping window is at the location [x y] of the input feature map. x indicates the location in the horizontal direction and y is the vertical direction.

'auto'The cropping window is located at the center of the input feature map. This value is automatically set when the Mode property is specified as 'centercrop'.

Examples

expand all

Create a 2-D drop layer and connect both of the inputs using a layerGraph object.

Create the layers.

layers = [
     imageInputLayer([32 32 3],'Name','image')
     crop2dLayer('centercrop','Name','crop')
     ]
layers = 
  2x1 Layer array with layers:

     1   'image'   Image Input   32x32x3 images with 'zerocenter' normalization
     2   'crop'    Crop 2D       center crop

Create a layerGraph. The first input of crop2dLayer is automatically connected to the first output of the image input layer.

lgraph = layerGraph(layers)
lgraph = 
  LayerGraph with properties:

         Layers: [2x1 nnet.cnn.layer.Layer]
    Connections: [1x2 table]

Connect the second input to the image layer output.

lgraph = connectLayers(lgraph,'image','crop/ref')  
lgraph = 
  LayerGraph with properties:

         Layers: [2x1 nnet.cnn.layer.Layer]
    Connections: [2x2 table]

     

Introduced in R2017b