internal PoolingLayer(int range, int inputWidth, int inputHeight, int inputDepth, PoolingMode mode = PoolingMode.Max) { Range = range; InputWidth = inputWidth; InputHeight = inputHeight; Depth = inputDepth; Mode = mode; }
public void EnumSerialize() { PoolingMode mode = PoolingMode.AverageIncludingPadding; using (MemoryStream stream = new MemoryStream()) { stream.Write(mode); stream.Seek(0, SeekOrigin.Begin); Assert.IsTrue(stream.TryRead(out PoolingMode copy)); Assert.IsTrue(mode == copy); } }
// Internal constructor private PoolingInfo( PoolingMode mode, int windowHeight, int windowWidth, int verticalPadding, int horizontalPadding, int verticalStride, int horizontalStride) { WindowHeight = windowHeight > 0 ? windowHeight : throw new ArgumentOutOfRangeException(nameof(windowHeight), "The window height must be at least equal to 1"); WindowWidth = windowWidth > 0 ? windowWidth : throw new ArgumentOutOfRangeException(nameof(windowWidth), "The window width must be at least equal to 1"); VerticalPadding = verticalPadding >= 0 ? verticalPadding : throw new ArgumentOutOfRangeException(nameof(verticalPadding), "The vertical padding must be greater than or equal to 0"); HorizontalPadding = horizontalPadding >= 0 ? horizontalPadding : throw new ArgumentOutOfRangeException(nameof(horizontalPadding), "The horizontal padding must be greater than or equal to 0"); VerticalStride = verticalStride >= 1 ? verticalStride : throw new ArgumentOutOfRangeException(nameof(verticalStride), "The vertical stride must be at least equal to 1"); HorizontalStride = horizontalStride >= 1 ? horizontalStride : throw new ArgumentOutOfRangeException(nameof(horizontalStride), "The horizontal stride must be at least equal to 1"); Mode = mode; }
public PoolingLayer(double[,,] input, PoolingMode mode, int stride, int windowSize) { this.input = input; this.mode = mode; this.stride = stride; this.windowSize = windowSize; maxCoordinates = new List <double[]>(); this.deltas = new double[input.GetLength(0), input.GetLength(1), input.GetLength(2)]; output = new double[(input.GetLength(0) - windowSize) / stride - 1, (input.GetLength(1) - windowSize) / stride - 1, input.GetLength(2)]; if (this.mode == PoolingMode.average) { AveragePooling(); } else { MaximumPooling(); } }
public Pooling2D(Variable <T> data, PoolingMode mode, int kernelH, int kernelW, int strideH, int strideW) { Descriptor = new PoolingDescriptor(); Descriptor.Set2D(mode, NanPropagation.NOT_PROPAGATE_NAN, kernelH, kernelW, 0, 0, strideH, strideW); var dataType = Dnn.DataTypeOf <T>(); var dataDesc = new TensorDescriptor(); dataDesc.Set4D(dataType, TensorFormat.CUDNN_TENSOR_NCHW, 10, (int)data.Shape[1], (int)data.Shape[2], (int)data.Shape[3]); int n, c, h, w; Descriptor.Get2dForwardOutputDim(dataDesc, out n, out c, out h, out w); Data = data; Output = Variable <T>(PartialShape.Create(-1, c, h, w)); AddInput(Data); AddOutput(Output); dataDesc.Dispose(); }
public void SetPoolingMode(PoolingMode Mode) { this.Mode = Mode; }
public static PoolingInfo New( PoolingMode mode, int windowHeight = 2, int windowWidth = 2, int verticalPadding = 0, int horizontalPadding = 0, int verticalStride = 2, int horizontalStride = 2) => new PoolingInfo(mode, windowHeight, windowWidth, verticalPadding, horizontalPadding, verticalStride, horizontalStride);
/// <summary> /// Creating a new Object Pool from script. Returns null, if no pool was created. /// </summary> /// <param name="PrefabToSpawn">The Prefab to spawn. Must have a JustSaveRuntimeId-component</param> /// <param name="PrefabId">A prefab id. Should be unique among your other object-pooling-ids</param> /// <param name="BasePoolSize">The base size to which the pool should be filled</param> /// <param name="Mode">How the pool should operate if you want to spawn something and the pool is empty.</param> /// <param name="NotifyToDespawn">How many objects ahead a pool object will be notified to despawn itself (JSOnNeeded is called)</param> /// <returns></returns> public ObjectPool CreateObjectPool(GameObject PrefabToSpawn, string PrefabId, int BasePoolSize, PoolingMode Mode, int NotifyToDespawn) { if (BasePoolSize < 0 || PrefabId == null || PrefabId == "") { return(null); } GameObject newPool = new GameObject("ObjectPoolFor" + PrefabToSpawn, typeof(ObjectPool)); ObjectPool newPoolComponent = newPool.GetComponent <ObjectPool>(); newPoolComponent.SpawnPrefabId = PrefabId; JustSaveRuntimeId SavablePrefabToSpawn = PrefabToSpawn.GetComponent <JustSaveRuntimeId>(); if (SavablePrefabToSpawn == null) { return(null); } newPoolComponent.SpawnPrefab = SavablePrefabToSpawn; newPoolComponent.BasePoolSize = BasePoolSize; newPoolComponent.SetPoolingMode(Mode); newPoolComponent.NotifyToDespawn = NotifyToDespawn <= BasePoolSize ? NotifyToDespawn : BasePoolSize; myObjectPoolingManager.RegisterObjectPool(PrefabId, newPoolComponent); return(newPoolComponent); }