/// <summary> /// Setup the layer. /// </summary> /// <param name="colBottom">Specifies the collection of bottom (input) Blobs.</param> /// <param name="colTop">Specifies the collection of top (output) Blobs.</param> public override void LayerSetUp(BlobCollection <T> colBottom, BlobCollection <T> colTop) { m_nLabelCount = colBottom[0].count() / colBottom[0].num; // The pools contains tuples, where // Item1 = label and // Item2 = index of the item associated with the label. // Item3 = distance from input item and this item in the cache. m_log.CHECK_LE(m_param.binary_hash_param.pool_size, m_param.binary_hash_param.cache_depth * m_nLabelCount, "The pool depth is too big, it must be less than the cache_depth * the label count."); Blob <T> blobCache1 = new common.Blob <T>(m_cuda, m_log, false); blobCache1.Name = "cache 1"; m_colBlobs.Add(blobCache1); Blob <T> blobCache2 = new common.Blob <T>(m_cuda, m_log, false); blobCache2.Name = "cache 2"; m_colBlobs.Add(blobCache2); Blob <T> blobParam = new common.Blob <T>(m_cuda, m_log, false); blobParam.Name = "params"; m_colBlobs.Add(blobParam); // The current indexes tell when to 'roll' back // to the start and maintain the rolling buffer // so as to only store the latest outputs. m_rgCache1CurrentIndex = new IndexItemCollection(m_nLabelCount); m_rgCache2CurrentIndex = new IndexItemCollection(m_nLabelCount); m_nIteration = 0; }
/// <summary> /// Setup the layer. /// </summary> /// <param name="colBottom">Specifies the collection of bottom (input) Blobs.</param> /// <param name="colTop">Specifies the collection of top (output) Blobs.</param> public override void LayerSetUp(BlobCollection <T> colBottom, BlobCollection <T> colTop) { m_log.CHECK_GE(colBottom.Count, 2, "There should be at least two bottom items: data (embeddings) and labels."); m_log.CHECK_EQ(colTop.Count, colBottom.Count - 1, "The top count should equal the bottom count - 1"); // Allocate the temp batch storage. for (int i = 0; i < m_nMaxBatches; i++) { Blob <T> data = new Blob <T>(m_cuda, m_log); data.ReshapeLike(colBottom[0]); m_rgBatchData.Add(data); Blob <T> label = new common.Blob <T>(m_cuda, m_log, false); label.ReshapeLike(colBottom[1]); m_rgBatchLabels.Add(label); } }