国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Day 84:網(wǎng)絡(luò)結(jié)構(gòu)與參數(shù)

這篇具有很好參考價(jià)值的文章主要介紹了Day 84:網(wǎng)絡(luò)結(jié)構(gòu)與參數(shù)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

單層數(shù)據(jù)

package dl;

/**
 * One layer, support all four layer types. The code mainly initializes, gets,
 * and sets variables. Essentially no algorithm is implemented.
 */
public class CnnLayer {
    /**
     * The type of the layer.
     */
    LayerTypeEnum type;

    /**
     * The number of out map.
     */
    int outMapNum;

    /**
     * The map size.
     */
    Size mapSize;

    /**
     * The kernel size.
     */
    Size kernelSize;

    /**
     * The scale size.
     */
    Size scaleSize;

    /**
     * The index of the class (label) attribute.
     */
    int classNum = -1;

    /**
     * Kernel. Dimensions: [front map][out map][width][height].
     */
    private double[][][][] kernel;

    /**
     * Bias. The length is outMapNum.
     */
    private double[] bias;

    /**
     * Out maps. Dimensions:
     * [batchSize][outMapNum][mapSize.width][mapSize.height].
     */
    private double[][][][] outMaps;

    /**
     * Errors.
     */
    private double[][][][] errors;

    /**
     * For batch processing.
     */
    private static int recordInBatch = 0;

    /**
     ***********************
     * The first constructor.
     *
     * @param paraNum
     *            When the type is CONVOLUTION, it is the out map number. when
     *            the type is OUTPUT, it is the class number.
     * @param paraSize
     *            When the type is INPUT, it is the map size; when the type is
     *            CONVOLUTION, it is the kernel size; when the type is SAMPLING,
     *            it is the scale size.
     ***********************
     */
    public CnnLayer(LayerTypeEnum paraType, int paraNum, Size paraSize) {
        type = paraType;
        switch (type) {
            case INPUT:
                outMapNum = 1;
                mapSize = paraSize; // No deep copy.
                break;
            case CONVOLUTION:
                outMapNum = paraNum;
                kernelSize = paraSize;
                break;
            case SAMPLING:
                scaleSize = paraSize;
                break;
            case OUTPUT:
                classNum = paraNum;
                mapSize = new Size(1, 1);
                outMapNum = classNum;
                break;
            default:
                System.out.println("Internal error occurred in AbstractLayer.java constructor.");
        }// Of switch
    }// Of the first constructor

    /**
     ***********************
     * Initialize the kernel.
     *
     * @param paraNum
     *            When the type is CONVOLUTION, it is the out map number. when
     ***********************
     */
    public void initKernel(int paraFrontMapNum) {
        kernel = new double[paraFrontMapNum][outMapNum][][];
        for (int i = 0; i < paraFrontMapNum; i++) {
            for (int j = 0; j < outMapNum; j++) {
                kernel[i][j] = MathUtils.randomMatrix(kernelSize.width, kernelSize.height, true);
            } // Of for j
        } // Of for i
    }// Of initKernel

    /**
     ***********************
     * Initialize the output kernel. The code is revised to invoke
     * initKernel(int).
     ***********************
     */
    public void initOutputKernel(int paraFrontMapNum, Size paraSize) {
        kernelSize = paraSize;
        initKernel(paraFrontMapNum);
    }// Of initOutputKernel

    /**
     ***********************
     * Initialize the bias. No parameter. "int frontMapNum" is claimed however
     * not used.
     ***********************
     */
    public void initBias() {
        bias = MathUtils.randomArray(outMapNum);
    }// Of initBias

    /**
     ***********************
     * Initialize the errors.
     *
     * @param paraBatchSize
     *            The batch size.
     ***********************
     */
    public void initErrors(int paraBatchSize) {
        errors = new double[paraBatchSize][outMapNum][mapSize.width][mapSize.height];
    }// Of initErrors

    /**
     ***********************
     * Initialize out maps.
     *
     * @param paraBatchSize
     *            The batch size.
     ***********************
     */
    public void initOutMaps(int paraBatchSize) {
        outMaps = new double[paraBatchSize][outMapNum][mapSize.width][mapSize.height];
    }// Of initOutMaps

    /**
     ***********************
     * Prepare for a new batch.
     ***********************
     */
    public static void prepareForNewBatch() {
        recordInBatch = 0;
    }// Of prepareForNewBatch

    /**
     ***********************
     * Prepare for a new record.
     ***********************
     */
    public static void prepareForNewRecord() {
        recordInBatch++;
    }// Of prepareForNewRecord

    /**
     ***********************
     * Set one value of outMaps.
     ***********************
     */
    public void setMapValue(int paraMapNo, int paraX, int paraY, double paraValue) {
        outMaps[recordInBatch][paraMapNo][paraX][paraY] = paraValue;
    }// Of setMapValue

    /**
     ***********************
     * Set values of the whole map.
     ***********************
     */
    public void setMapValue(int paraMapNo, double[][] paraOutMatrix) {
        outMaps[recordInBatch][paraMapNo] = paraOutMatrix;
    }// Of setMapValue

    /**
     ***********************
     * Getter.
     ***********************
     */
    public Size getMapSize() {
        return mapSize;
    }// Of getMapSize

    /**
     ***********************
     * Setter.
     ***********************
     */
    public void setMapSize(Size paraMapSize) {
        mapSize = paraMapSize;
    }// Of setMapSize

    /**
     ***********************
     * Getter.
     ***********************
     */
    public LayerTypeEnum getType() {
        return type;
    }// Of getType

    /**
     ***********************
     * Getter.
     ***********************
     */
    public int getOutMapNum() {
        return outMapNum;
    }// Of getOutMapNum

    /**
     ***********************
     * Setter.
     ***********************
     */
    public void setOutMapNum(int paraOutMapNum) {
        outMapNum = paraOutMapNum;
    }// Of setOutMapNum

    /**
     ***********************
     * Getter.
     ***********************
     */
    public Size getKernelSize() {
        return kernelSize;
    }// Of getKernelSize

    /**
     ***********************
     * Getter.
     ***********************
     */
    public Size getScaleSize() {
        return scaleSize;
    }// Of getScaleSize

    /**
     ***********************
     * Getter.
     ***********************
     */
    public double[][] getMap(int paraIndex) {
        return outMaps[recordInBatch][paraIndex];
    }// Of getMap

    /**
     ***********************
     * Getter.
     ***********************
     */
    public double[][] getKernel(int paraFrontMap, int paraOutMap) {
        return kernel[paraFrontMap][paraOutMap];
    }// Of getKernel

    /**
     ***********************
     * Setter. Set one error.
     ***********************
     */
    public void setError(int paraMapNo, int paraMapX, int paraMapY, double paraValue) {
        errors[recordInBatch][paraMapNo][paraMapX][paraMapY] = paraValue;
    }// Of setError

    /**
     ***********************
     * Setter. Set one error matrix.
     ***********************
     */
    public void setError(int paraMapNo, double[][] paraMatrix) {
        errors[recordInBatch][paraMapNo] = paraMatrix;
    }// Of setError

    /**
     ***********************
     * Getter. Get one error matrix.
     ***********************
     */
    public double[][] getError(int paraMapNo) {
        return errors[recordInBatch][paraMapNo];
    }// Of getError

    /**
     ***********************
     * Getter. Get the whole error tensor.
     ***********************
     */
    public double[][][][] getErrors() {
        return errors;
    }// Of getErrors

    /**
     ***********************
     * Setter. Set one kernel.
     ***********************
     */
    public void setKernel(int paraLastMapNo, int paraMapNo, double[][] paraKernel) {
        kernel[paraLastMapNo][paraMapNo] = paraKernel;
    }// Of setKernel

    /**
     ***********************
     * Getter.
     ***********************
     */
    public double getBias(int paraMapNo) {
        return bias[paraMapNo];
    }// Of getBias

    /**
     ***********************
     * Setter.
     ***********************
     */
    public void setBias(int paraMapNo, double paraValue) {
        bias[paraMapNo] = paraValue;
    }// Of setBias

    /**
     ***********************
     * Getter.
     ***********************
     */
    public double[][][][] getMaps() {
        return outMaps;
    }// Of getMaps

    /**
     ***********************
     * Getter.
     ***********************
     */
    public double[][] getError(int paraRecordId, int paraMapNo) {
        return errors[paraRecordId][paraMapNo];
    }// Of getError

    /**
     ***********************
     * Getter.
     ***********************
     */
    public double[][] getMap(int paraRecordId, int paraMapNo) {
        return outMaps[paraRecordId][paraMapNo];
    }// Of getMap

    /**
     ***********************
     * Getter.
     ***********************
     */
    public int getClassNum() {
        return classNum;
    }// Of getClassNum

    /**
     ***********************
     * Getter. Get the whole kernel tensor.
     ***********************
     */
    public double[][][][] getKernel() {
        return kernel;
    } // Of getKernel
}// Of class CnnLayer

多層管理文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-676449.html

package dl;

import java.util.ArrayList;
import java.util.List;

/**
 * CnnLayer builder.
 */
public class LayerBuilder {
    /**
     * Layers.
     */
    private List<CnnLayer> layers;

    /**
     ***********************
     * The first constructor.
     ***********************
     */
    public LayerBuilder() {
        layers = new ArrayList<CnnLayer>();
    }// Of the first constructor

    /**
     ***********************
     * The second constructor.
     ***********************
     */
    public LayerBuilder(CnnLayer paraLayer) {
        this();
        layers.add(paraLayer);
    }// Of the second constructor

    /**
     ***********************
     * Add a layer.
     *
     * @param paraLayer
     *            The new layer.
     ***********************
     */
    public void addLayer(CnnLayer paraLayer) {
        layers.add(paraLayer);
    }// Of addLayer

    /**
     ***********************
     * Get the specified layer.
     *
     * @param paraIndex
     *            The index of the layer.
     ***********************
     */
    public CnnLayer getLayer(int paraIndex) throws RuntimeException{
        if (paraIndex >= layers.size()) {
            throw new RuntimeException("CnnLayer " + paraIndex + " is out of range: "
                    + layers.size() + ".");
        }//Of if

        return layers.get(paraIndex);
    }//Of getLayer

    /**
     ***********************
     * Get the output layer.
     ***********************
     */
    public CnnLayer getOutputLayer() {
        return layers.get(layers.size() - 1);
    }//Of getOutputLayer

    /**
     ***********************
     * Get the number of layers.
     ***********************
     */
    public int getNumLayers() {
        return layers.size();
    }//Of getNumLayers
}// Of class LayerBuilder

到了這里,關(guān)于Day 84:網(wǎng)絡(luò)結(jié)構(gòu)與參數(shù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包