GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — arrayfire-python/arrayfire/ml.py at master · arrayfire/arrayfire-python

Expand file tree

/

ml.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
83 lines (63 loc) · 2.9 KB
/

ml.py

Copy path

File metadata and controls

83 lines (63 loc) · 2.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#######################################################
# Copyright (c) 2020, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
"""
Machine learning functions
- Pool 2D, ND, maxpooling, minpooling, meanpooling
- Forward and backward convolution passes
"""
from .library import *
from .array import *
def convolve2GradientNN(incoming_gradient, original_signal, original_kernel, convolved_output, stride = (1, 1), padding = (0, 0), dilation = (1, 1), gradType = CONV_GRADIENT.DEFAULT):
"""
Function for calculating backward pass gradient of 2D convolution.
This function calculates the gradient with respect to the output of the
\ref convolve2NN() function that uses the machine learning formulation
for the dimensions of the signals and filters
Multiple signals and filters can be batched against each other, however
their dimensions must match.
Example:
Signals with dimensions: d0 x d1 x d2 x Ns
Filters with dimensions: d0 x d1 x d2 x Nf
Resulting Convolution: d0 x d1 x Nf x Ns
Parameters
-----------
incoming_gradient: af.Array
- Gradients to be distributed in backwards pass
original_signal: af.Array
- A 2 dimensional signal or batch of 2 dimensional signals.
original_kernel: af.Array
- A 2 dimensional kernel or batch of 2 dimensional kernels.
convolved_output: af.Array
- output of forward pass of convolution
stride: tuple of ints. default: (1, 1).
- Specifies how much to stride along each dimension
padding: tuple of ints. default: (0, 0).
- Specifies signal padding along each dimension
dilation: tuple of ints. default: (1, 1).
- Specifies how much to dilate kernel along each dimension before convolution
Returns
--------
output: af.Array
- Gradient wrt/requested gradient type
"""
output = Array()
stride_dim = dim4(stride[0], stride[1])
padding_dim = dim4(padding[0], padding[1])
dilation_dim = dim4(dilation[0], dilation[1])
safe_call(backend.get().af_convolve2_gradient_nn(
c_pointer(output.arr),
incoming_gradient.arr,
original_signal.arr,
original_kernel.arr,
convolved_output.arr,
2, c_pointer(stride_dim),
2, c_pointer(padding_dim),
2, c_pointer(dilation_dim),
gradType.value))
return output
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.