void Blob::fill(const BlobShape &shape, int type, void *data, bool deepCopy) { CV_Assert(type == CV_32F || type == CV_64F); if (deepCopy) { m.create(shape.dims(), shape.ptr(), type); memcpy(m.data, data, m.total() * m.elemSize()); } else { m = Mat(shape.dims(), shape.ptr(), type, data); } }
Blob::Blob(InputArray image, int dstCn) { CV_Assert(dstCn == -1 || dstCn > 0); std::vector<Mat> inMats = extractMatVector(image); BlobShape dstShape = getBlobShpae(inMats, dstCn); m.create(dstShape.dims(), dstShape.ptr(), CV_32F); std::vector<Mat> wrapBuf(dstShape[-3]); int elemSize = (int)m.elemSize(); uchar *ptr = this->ptr(); for (size_t i = 0; i < inMats.size(); i++) { Mat inMat = inMats[i]; if (inMat.dims <= 2) { inMat.convertTo(inMat, m.type()); wrapBuf.resize(0); for (int cn = 0; cn < inMat.channels(); cn++) { wrapBuf.push_back(Mat(inMat.rows, inMat.cols, m.type(), ptr)); ptr += elemSize * inMat.total(); } cv::split(inMat, wrapBuf); } else { inMat.convertTo(Mat(inMat.dims, inMat.size, m.type(), ptr), m.type()); ptr += elemSize * inMat.total(); } } }
void FullyConnectedLayer::reshape(const Blob &inp, Blob &out) { BlobShape inpShape = inp.shape(); BlobShape outShape(axis+1, inpShape.ptr()); outShape[axis] = numOutputs; out.create(outShape, inp.type()); }
void Blob::create(const BlobShape &shape, int type) { CV_Assert(type == CV_32F || type == CV_64F); m.create(shape.dims(), shape.ptr(), type); }