Img2ColOperator
public class Img2ColOperator: ComputableOperator
Operator works like img2col in matlab.
It converts any 3D tensor ([H, W, C]
or [C, H, W]
) into a 2D tensor ([H*W, C*M*N]
) according to patchSize [M, N]
and stride.
-
Operator label. Conforms to
ComputableOperator
Declaration
Swift
public var operatorLabel: String
-
This operator does not operator on GPU. Conforms to
ComputableOperator
Declaration
Swift
public var metalKernelFuncLabel:String = "Img2col"
-
Conforms to
ComputableOperator
Declaration
Swift
public var computationDelegate: OperatorCalculationDelegate?
-
Conforms to
ComputableOperator
Declaration
Swift
public var inputTensors: [Tensor]?
-
Conforms to
ComputableOperator
Declaration
Swift
public var outputTensors: [Tensor]?
-
If
true
, operator will not callinputOutputTensorsCheck()
before doing calculation. This is used inside framework to speed up in situation we know it will not be wrong.Declaration
Swift
public var disableInputOutputCheck: Bool
-
Indicate if this operator would do paramter update.
Declaration
Swift
public var trainable: Bool = true
-
The mapping type of this operator.
OneToOne
for this operator.Declaration
Swift
public var mapType: OperatorMappingType
-
img2col operator cannot do in-place calculation
Declaration
Swift
public var inPlaceble: Bool = false
-
The patch size. 2D vecotr.
[patchHeight, patchWidth]
Declaration
Swift
public var patchSize: [Int]
-
The stride. 2D vector. Default is
[1, 1]
.[strideHeight, strideWidth]
Declaration
Swift
public var stride: [Int] = [1, 1]
-
Channel position. Default is
ImageChannelOrder.First
Declaration
Swift
public var channelPosition: TensorChannelOrder = .First
-
Padding mode. Default is
PaddingMode.Valid
Declaration
Swift
public var padMode: PaddingMode = .Valid
-
Padding value
Declaration
Swift
public var paddingValue: Float = 0.0
-
init(patchSize:stride:channelPosition:padMode:computationDelegate:inputTensors:outputTensors:operatorLabel:disableInputOutputCheck:)
Designated init
Declaration
Swift
public init(patchSize: [Int], stride: [Int], channelPosition: TensorChannelOrder = .First, padMode: PaddingMode = PaddingMode.Valid, computationDelegate: OperatorCalculationDelegate? = nil, inputTensors: [Tensor]? = nil, outputTensors: [Tensor]? = nil, operatorLabel: String = "Img2ColOp", disableInputOutputCheck: Bool = false)
Parameters
patchSize
[patchHeight, patchWidth]
channelPosition
channelPosition description
padMode
padMode
stride
[strideHeight, strideWidth]
computationDelegate
computationDelegate description
inputTensors
inputTensors description
outputTensors
outputTensors description
operatorLabel
operatorLabel description
-
Compute output shape according
numFilters
,kernelSize
,stride
anddilation
.Declaration
Swift
public func outputShape(shapeArray shapes: [TensorShape]) -> [TensorShape]?
Parameters
shapes
shapes description
Return Value
return value description
-
Check input and output tensors.
Declaration
Swift
public func inputOutputTensorsCheck() -> (check: Bool, msg: String)
Return Value
return value description
-
Compute sync way.
Declaration
Swift
public func compute(_ computationMode: OperatorComputationMode)
Parameters
computationMode
mode
-
Compute async
Declaration
Swift
public func computeAsync(_ computationMode: OperatorComputationMode)
Parameters
computationMode
computationMode
-
This operator itself does not do any grad update.
Declaration
Swift
public func gradCompute(_ computationMode: OperatorComputationMode) -> [String: DataSymbolSupportedDataType]
Parameters
computationMode
computationMode description
Return Value
return value description
-
This operator itself does not do any grad update.
Declaration
Swift
public func gradComputAsync(_ computationMode: OperatorComputationMode)
Parameters
computationMode
computationMode description
upGrads
upGrads description
-
Do nothing. No param to update
Declaration
Swift
public func updateParams(grads: [Tensor], LR: Float)
Parameters
grads
grads description
LR
LR description
-
This operator has no parameters. Do nothing
Declaration
Swift
public func bindParamSymbols(_ symbols: [GraphSymbol])
-
This operator returns no param symbols
Declaration
Swift
public func paramSymbols() -> [GraphSymbol]
Return Value
empty array
-
CPU calculation
Declaration
Swift
internal func cpu()
-
make
Img2ColInfo
Declaration
Swift
internal func makeImg2ColInfo(inputShape: TensorShape, outputShape: TensorShape) -> Img2ColInfo
Parameters
inputShape
input
outputShape
output
Return Value
struct
-
GPU calculation.
Split the output 2D matrix into threadgroups based on each patch and channel index. Calculate each element in each group independently.
Declaration
Swift
internal func gpu()