Coder Social home page Coder Social logo

cnn's Introduction

NN

Pooling|Convolution: В чем разница между заполнением "SAME" и "VALID"
  • VALID
    • без отступов
    • удаляет только крайние правые столбцы (или самые нижние строки).
    • т.к. нет «придуманных» полей ввода. Слой использует только допустимые входные данные.
  • SAME
    • с отступом
    • пытается равномерно заполнить слева и справа, если количество добавляемых столбцов нечетное, он добавит дополнительный столбец справа, (та же логика применяется по вертикали: может быть дополнительная строка нулей внизу).
    • если шаг 1, выходные данные слоя будут иметь те же пространственные размеры, что и его входы.

Examples:

Example:

import Matrix from './entity/Matrix.mjs'
import MatrixPadding from './entity/MatrixPadding.mjs'
import MatrixPooling from './entity/MatrixPooling.mjs'
import MatrixConvolution from './entity/MatrixConvolution.mjs'

const input = [
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
];

const matrix = new Matrix().create(input, { width: 5, deep: 2 })

/*
const matrix = [
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
   [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
]
*/

const matrixPadding = new MatrixPadding().create(matrix, { 
    width: 5, deep: 2, top: 1, right: 2, bottom: 1, left: 1 
  })

/*
const matrixPadding = [
   [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [0, 0], [0, 0]],
   [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]],
]
*/

const filter = [
  [[-1, -1], [-1, -1], [-1, -1]],
  [[-1, -1], [ 8,  8], [-1, -1]],
  [[-1, -1], [-1, -1], [-1, -1]],
]

const matrixConvolution = new MatrixConvolution().create(matrixPadding, { filter })
// (-1 * 0 +-1 * 0 + -1 * 0) + (-1 * 0 + 8 * 1 + -1 * 1) + (-1 * 0 + -1 * 1 + -1 * 1) = 5 === matrixConvolution[0][0][0]
// (-1 * 0 +-1 * 0 + -1 * 0) + (-1 * 0 + 8 * 1 + -1 * 1) + (-1 * 0 + -1 * 1 + -1 * 1) = 5 === matrixConvolution[0][0][1]

/*
const expectMatrixConvolution = [
  [[5,  5],[3,  3],[3,  3],[3,  3],[5,  5],[-2,-2]],
  [[3,  3],[0,  0],[0,  0],[0,  0],[3,  3],[-3,-3]],
  [[3,  3],[0,  0],[0,  0],[0,  0],[3,  3],[-3,-3]],
  [[3,  3],[0,  0],[0,  0],[0,  0],[3,  3],[-3,-3]],
  [[3,  3],[0,  0],[0,  0],[0,  0],[3,  3],[-3,-3]],
  [[3,  3],[0,  0],[0,  0],[0,  0],[3,  3],[-3,-3]],
  [[3,  3],[0,  0],[0,  0],[0,  0],[3,  3],[-3,-3]],
  [[3,  3],[0,  0],[0,  0],[0,  0],[3,  3],[-3,-3]],
  [[3,  3],[0,  0],[0,  0],[0,  0],[3,  3],[-3,-3]],
  [[5,  5],[3,  3],[3,  3],[3,  3],[5,  5],[-2,-2]],
]
*/

const matrixPooling = new MatrixPooling().create(matrixConvolution, { 
    type: MatrixPooling.TYPE_MAX, filterX: 2, filterY: 2 
})

/*
const expectMatrixPooling = [
  [[5,5],[3,3],[5,5]],
  [[3,3],[0,0],[3,3]],
  [[3,3],[0,0],[3,3]],
  [[3,3],[0,0],[3,3]],
  [[5,5],[3,3],[5,5]]
]
*/

cnn's People

Watchers

Валера avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.