Day 84:网络结构与参数

这篇具有很好参考价值的文章主要介绍了Day 84:网络结构与参数。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

单层数据

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

多层管理文章来源地址https://www.toymoban.com/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

到了这里,关于Day 84:网络结构与参数的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 数据结构的应用场景:如社交网络、路由算法、图论、网络协议等

    作者:禅与计算机程序设计艺术 数据结构(Data Structure)是计算机科学中存储、组织、管理数据的方式,主要用于解决信息检索、处理和运算时的效率及空间占用问题。它是指数据元素(elements)之间的关系、顺序和逻辑结构,以及相互作用的算法。数据结构通常采用抽象数据类

    2024年02月14日
    浏览(35)
  • DES加密解密 Feistel算法网络结构 详讲

    DES算法是属于对称密码算法中的分组加算法。 分组加密 和 流密码 加密是相对应的。 流密码 是逐字节进行加密,即一个字节一个字节进行加密 分组加密 算法也叫 块加密 ,将明文分成固定字节块,对每个字节块分别进行加密,最后拼接在一起得到密文 密钥长64位,56位参与运

    2024年02月16日
    浏览(28)
  • 【数据结构】拓扑网络(AOE算法举例+源码)

    博主介绍:✌专研于前后端领域优质创作者、本质互联网精神开源贡献答疑解惑、坚持优质作品共享、掘金/腾讯云/阿里云等平台优质作者、擅长前后端项目开发和毕业项目实战,深受全网粉丝喜爱与支持✌有需要可以联系作者我哦! 🍅文末获取源码联系🍅 👇🏻 精彩专栏

    2024年02月22日
    浏览(38)
  • YOLO系列 --- YOLOV7算法(四):YOLO V7算法网络结构解析

    今天来讲讲YOLO V7算法网络结构吧~ 在 train.py 中大概95行的地方开始创建网络,如下图(YOLO V7下载的时间不同,可能代码有少许的改动,所以行数跟我不一定一样) 我们进去发现,其实就是在 yolo.py 里面。后期,我们就会发现相关的网络结构都是在该py文件里面。这篇blog就主

    2024年02月05日
    浏览(33)
  • 视频算法最新动能抽帧网络结构梳理与应用领域

    今天我们来谈一谈大家每天都在刷,但又对它充满疑问的领域,视频算法。 其实,视频算法是推荐系统中的一种,它利用计算机视觉和自然语言处理等技术,分析视频的内容,从而为用户推荐相关的视频。简单来说,视频算法就像是一个智能的推荐员,它可以根据用户的历史

    2024年01月22日
    浏览(32)
  • YOLOv5源码中的参数超详细解析(2)— 配置文件yolov5s.yaml(包括源码+网络结构图)

    前言: Hello大家好,我是小哥谈。 配置文件yolov5s.yaml在YOLOv5模型训练过程中发挥着至关重要的作用,属于初学者必知必会的文件!在YOLOv5-6.0版本源码中,配置了5种不同大小的网络模型,分别是YOLOv5n、YOLOv5s、YOLOv5m、YOLOv5l、YOLOv5x,其中YOLOv5n是网络深度和宽度最小但检测速度

    2024年02月08日
    浏览(36)
  • 【网络安全】数据加密标准(DES算法)详细介绍( 分组密码、Feistel密码结构、轮函数、子密钥生成算法)

    将被加密明文划分成一个一个的分组,输入n比特明文分组,输出n比特密文分组。 若映射可逆,具有 x n ! x^n! x n ! 种替换可能性。 如以下示例,每个4比特输入唯一映射为另一个4比特输出。 2.1 什么是Feistel密码结构 1973年由 IBM的Horst Feistel首次提出 ,通过将明文分组分成 左右

    2023年04月08日
    浏览(33)
  • Python实现透明隧道爬虫ip:不影响现有网络结构

    作为一名专业爬虫程序员,我们常常需要使用隧道代理来保护个人隐私和访问互联网资源。本文将分享如何使用Python实现透明隧道代理,以便在保护隐私的同时不影响现有网络结构。通过实际操作示例和专业的解析,我们将带您深入了解透明隧道代理的工作原理,并提供实用

    2024年02月12日
    浏览(33)
  • 【Java实战项目】基于ssm的数据结构课程网络学习平台

    🙊作者简介:多年一线开发工作经验,分享技术代码帮助学生学习,独立完成自己的项目或者毕业设计。 代码可以私聊博主获取。🌹 赠送计算机毕业设计600个选题excel文件,帮助大学选题。 赠送开题报告模板,帮助书写开题报告。 作者完整代码目录供你选择: 《Springboo

    2024年01月18日
    浏览(31)
  • 算法/后端计算机基础课程如何学?——八股文基础(数据结构、计算机网络、算法导论、操作系统)

    UCB CS61B 数据结构 Stanford CS144 计网 MIT 6.006 算法导论 6.S081 操作系统 配合国内外名校的开源课件和lab 浙大 数据结构 哈工大 计网/计组/操作系统/数据库 [b站/慕课] MIT 6.824分布式系统 6.830/6.814:数据库系统 fault tolerance/心跳/选举/日志复制都是如何实现的 ? 做完labs你就有答案啦

    2024年02月02日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包