Skip to main content

Often we spend lots of time calculating the Receptive field of a CNN model.This Module can calculate the receptive field, Output image size from a model object

Reason this release was yanked:

FC layer updates

Project description

This Project can help you calculating Receptive Field in every layer for CNN model

How to use ?

from rf_calc import receptive_field 
model = models.GoogLeNet().to(device)
image_input_size  = 224
RF = receptive_field(model,image_input_size)

Output

Kernel_size : Size of the convolving kernel.
Padding : Zero-padding added to both sides of the input image.
Stride : Stride of the convolution. Default: 1
Input_Img_size : Shape of image as input to the layer.
Output_Img_size : Shape of image as Output from the layer.
Receptive_field : Shape pf Receptive field in the layer.

=======================================Reciptive Field Calculator========================================
|    | Kernel_size   | Padding   |   Stride | Input_Img_size   | Output_Img_size   | Receptive_field   |
|---:|:--------------|:----------|---------:|:-----------------|:------------------|:------------------|
|  0 | 7*7           | 3         |        2 | 224*224          | 112*112           | 7*7               |
|  1 | 3*3           | NO        |        2 | 112*112          | 55*55             | 11*11             |
|  2 | 1*1           | NO        |        1 | 55*55            | 55*55             | 11*11             |
|  3 | 3*3           | 1         |        1 | 55*55            | 55*55             | 19*19             |
|  4 | 3*3           | NO        |        2 | 55*55            | 27*27             | 27*27             |
|  5 | 1*1           | NO        |        1 | 27*27            | 27*27             | 27*27             |
|  6 | 1*1           | NO        |        1 | 27*27            | 27*27             | 27*27             |
|  7 | 3*3           | 1         |        1 | 27*27            | 27*27             | 43*43             |
|  8 | 1*1           | NO        |        1 | 27*27            | 27*27             | 43*43             |
|  9 | 3*3           | 1         |        1 | 27*27            | 27*27             | 59*59             |
| 10 | 3*3           | 1         |        1 | 27*27            | 27*27             | 75*75             |
| 11 | 1*1           | NO        |        1 | 27*27            | 27*27             | 75*75             |
| 12 | 1*1           | NO        |        1 | 27*27            | 27*27             | 75*75             |
| 13 | 1*1           | NO        |        1 | 27*27            | 27*27             | 75*75             |
| 14 | 3*3           | 1         |        1 | 27*27            | 27*27             | 91*91             |
| 15 | 1*1           | NO        |        1 | 27*27            | 27*27             | 91*91             |
| 16 | 3*3           | 1         |        1 | 27*27            | 27*27             | 107*107           |
| 17 | 3*3           | 1         |        1 | 27*27            | 27*27             | 123*123           |
| 18 | 1*1           | NO        |        1 | 27*27            | 27*27             | 123*123           |
| 19 | 3*3           | NO        |        2 | 27*27            | 13*13             | 139*139           |
| 20 | 1*1           | NO        |        1 | 13*13            | 13*13             | 139*139           |
| 21 | 1*1           | NO        |        1 | 13*13            | 13*13             | 139*139           |
| 22 | 3*3           | 1         |        1 | 13*13            | 13*13             | 171*171           |
| 23 | 1*1           | NO        |        1 | 13*13            | 13*13             | 171*171           |
| 24 | 3*3           | 1         |        1 | 13*13            | 13*13             | 203*203           |
| 25 | 3*3           | 1         |        1 | 13*13            | 13*13             | 235*235           |
| 26 | 1*1           | NO        |        1 | 13*13            | 13*13             | 235*235           |
| 27 | 1*1           | NO        |        1 | 13*13            | 13*13             | 235*235           |
| 28 | 1*1           | NO        |        1 | 13*13            | 13*13             | 235*235           |
| 29 | 3*3           | 1         |        1 | 13*13            | 13*13             | 267*267           |
| 30 | 1*1           | NO        |        1 | 13*13            | 13*13             | 267*267           |
| 31 | 3*3           | 1         |        1 | 13*13            | 13*13             | 299*299           |
| 32 | 3*3           | 1         |        1 | 13*13            | 13*13             | 331*331           |
| 33 | 1*1           | NO        |        1 | 13*13            | 13*13             | 331*331           |
| 34 | 1*1           | NO        |        1 | 13*13            | 13*13             | 331*331           |
| 35 | 1*1           | NO        |        1 | 13*13            | 13*13             | 331*331           |
| 36 | 3*3           | 1         |        1 | 13*13            | 13*13             | 363*363           |
| 37 | 1*1           | NO        |        1 | 13*13            | 13*13             | 363*363           |
| 38 | 3*3           | 1         |        1 | 13*13            | 13*13             | 395*395           |
| 39 | 3*3           | 1         |        1 | 13*13            | 13*13             | 427*427           |
| 40 | 1*1           | NO        |        1 | 13*13            | 13*13             | 427*427           |
| 41 | 1*1           | NO        |        1 | 13*13            | 13*13             | 427*427           |
| 42 | 1*1           | NO        |        1 | 13*13            | 13*13             | 427*427           |
| 43 | 3*3           | 1         |        1 | 13*13            | 13*13             | 459*459           |
| 44 | 1*1           | NO        |        1 | 13*13            | 13*13             | 459*459           |
| 45 | 3*3           | 1         |        1 | 13*13            | 13*13             | 491*491           |
| 46 | 3*3           | 1         |        1 | 13*13            | 13*13             | 523*523           |
| 47 | 1*1           | NO        |        1 | 13*13            | 13*13             | 523*523           |
| 48 | 1*1           | NO        |        1 | 13*13            | 13*13             | 523*523           |
| 49 | 1*1           | NO        |        1 | 13*13            | 13*13             | 523*523           |
| 50 | 3*3           | 1         |        1 | 13*13            | 13*13             | 555*555           |
| 51 | 1*1           | NO        |        1 | 13*13            | 13*13             | 555*555           |
| 52 | 3*3           | 1         |        1 | 13*13            | 13*13             | 587*587           |
| 53 | 3*3           | 1         |        1 | 13*13            | 13*13             | 619*619           |
| 54 | 1*1           | NO        |        1 | 13*13            | 13*13             | 619*619           |
| 55 | 2*2           | NO        |        2 | 13*13            | 6*6               | 635*635           |
| 56 | 1*1           | NO        |        1 | 6*6              | 6*6               | 635*635           |
| 57 | 1*1           | NO        |        1 | 6*6              | 6*6               | 635*635           |
| 58 | 3*3           | 1         |        1 | 6*6              | 6*6               | 699*699           |
| 59 | 1*1           | NO        |        1 | 6*6              | 6*6               | 699*699           |
| 60 | 3*3           | 1         |        1 | 6*6              | 6*6               | 763*763           |
| 61 | 3*3           | 1         |        1 | 6*6              | 6*6               | 827*827           |
| 62 | 1*1           | NO        |        1 | 6*6              | 6*6               | 827*827           |
| 63 | 1*1           | NO        |        1 | 6*6              | 6*6               | 827*827           |
| 64 | 1*1           | NO        |        1 | 6*6              | 6*6               | 827*827           |
| 65 | 3*3           | 1         |        1 | 6*6              | 6*6               | 891*891           |
| 66 | 1*1           | NO        |        1 | 6*6              | 6*6               | 891*891           |
| 67 | 3*3           | 1         |        1 | 6*6              | 6*6               | 955*955           |
| 68 | 3*3           | 1         |        1 | 6*6              | 6*6               | 1019*1019         |
| 69 | 1*1           | NO        |        1 | 6*6              | 6*6               | 1019*1019         |
| 70 | 1*1           | NO        |        1 | 6*6              | 6*6               | 1019*1019         |
| 71 | 1*1           | NO        |        1 | 6*6              | 6*6               | 1019*1019         |
=========================================================================================================

About Receptive Field

What is Receptive Field ?

1> Local Receptive field Local receptive field is present in every layer. Local receptive will be the size of kernel used in the layer .For example if we have an image of size 19x19 and we are applying a 3x3 metric then local receptive field will be 3x3 in first layer.

2> Global Receptive field At every layer the part of image our kernel can see is global receptive field .For a 3x3 kernel convolution global receptive field will increase by 2 units ( there is a mathematical formula that we can cover in later chapters ). It means if you see the below code in every convolution step our model will be able to see 2 pixel more in each side of image .

Input image => kernel shape => Output Image -> local Receptive field -> Global Receptive field 19x19 => 3x3 => 17x17 -> 3x3 ->3x3 17x17 => 3x3 => 15x15 ->3x3 ->5x5 15x15 => 3x3 => 13x13 ->3x3 ->7x7 13x13 => 3x3 => 11x11 ->3x3 ->9x9 11x11 => 3x3 => 9x9 ->3x3 ->11x11 9x9 => 3x3 => 7x7 ->3x3 ->13x13 7x7 => 3x3 => 5x5 ->3x3 ->15x15 5x5 => 3x3 => 3x3 ->3x3 ->17x17 3x3 => 3x3 => 1x1 ->3x3 ->19x19

Read the article for better understanding. https://medium.com/@data.pruthiraj/building-blocks-of-computer-vision-and-cnn-f5acdbf3c0b7

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rf_calc-0.0.5.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rf_calc-0.0.5-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file rf_calc-0.0.5.tar.gz.

File metadata

  • Download URL: rf_calc-0.0.5.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for rf_calc-0.0.5.tar.gz
Algorithm Hash digest
SHA256 1711e36062c24687ab8d5ceddde1e7554aaaa7936d580fe3c2f667e9332817bc
MD5 63ef8f6e1d43d4d2273b3ac4af3f67c4
BLAKE2b-256 443ff02cae9f0646e46b642959694f6a86776fded6a10261acff9858c98638d4

See more details on using hashes here.

File details

Details for the file rf_calc-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: rf_calc-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for rf_calc-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4b946b059da65db6c192613e8b97b9ae7711457e171ec03341baa5959f5cb300
MD5 0f133f77a1381dd779d6db796f6bdd06
BLAKE2b-256 ad3d8661c94977204f965b3a2582679aab77bc2c8b5f17084eb0c7005406a895

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page