This repository was archived by the owner on Aug 15, 2019. It is now read-only.
Commit 9f5ec47
Add NCHW dataFormat support for conv2d (#1791)
This PR makes `conv2d` support `NCHW` dataFormat, `NCHW` works well in inference and gradient. The `NCHW` dataFormat is supported in CPU and WebGL backend. Feature requested in [tensorflow/tfjs#1648](tensorflow/tfjs#1648).
**Features:**
* Make conv2d support NCHW.
* Make conv2dDerInput support NCHW.
* Make conv2dDerFilter support NCHW.
* Add a helper method `convertConv2DDataFormat` to convert `'NHWC'|'NCHW'` format into `'channelsLast'|'channelsFirst'` format.
**Tests:**
* Add unit tests for NCHW conv2D inference.
* Add unit tests for NCHW conv2D gradient.
* Add unit tests for `convertConv2DDataFormat`.
**Changes in Kernel:**
* Make CPU kernel function `conv2d`, `conv2dDerInput`, `conv2dDerFilter` support `channelsFirst` and `channelsLast` dataFormat.
* Make GPU kernel function `conv2d`, `conv2dDerInput`, `conv2dDerFilter` support `channelsFirst` and `channelsLast` dataFormat.
* Make GPI kernel function `conv2dByMatMul`, `conv2dWithIm2Row` support `channelsFirst` and `channelsLast` dataFormat.
* Make GPGPUProgram `Conv2DProgram`, `Conv2DDerInputProgram`, `Conv2DDerFilterProgram`, `Im2ColPackedProgram` support `channelsFirst` and `channelsLast` dataFormat.1 parent 6183caf commit 9f5ec47
File tree
9 files changed
+429
-96
lines changed- src
- backends
- cpu
- webgl
- ops
9 files changed
+429
-96
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1558 | 1558 | | |
1559 | 1559 | | |
1560 | 1560 | | |
| 1561 | + | |
| 1562 | + | |
1561 | 1563 | | |
1562 | 1564 | | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
1563 | 1574 | | |
1564 | 1575 | | |
1565 | 1576 | | |
1566 | 1577 | | |
1567 | 1578 | | |
1568 | | - | |
1569 | | - | |
| 1579 | + | |
| 1580 | + | |
1570 | 1581 | | |
1571 | | - | |
| 1582 | + | |
1572 | 1583 | | |
1573 | 1584 | | |
1574 | 1585 | | |
1575 | 1586 | | |
1576 | 1587 | | |
1577 | 1588 | | |
1578 | 1589 | | |
1579 | | - | |
| 1590 | + | |
1580 | 1591 | | |
1581 | | - | |
| 1592 | + | |
1582 | 1593 | | |
1583 | 1594 | | |
1584 | 1595 | | |
1585 | 1596 | | |
1586 | 1597 | | |
1587 | 1598 | | |
1588 | 1599 | | |
1589 | | - | |
| 1600 | + | |
1590 | 1601 | | |
1591 | 1602 | | |
1592 | | - | |
| 1603 | + | |
1593 | 1604 | | |
1594 | | - | |
| 1605 | + | |
| 1606 | + | |
1595 | 1607 | | |
1596 | 1608 | | |
1597 | 1609 | | |
| |||
1677 | 1689 | | |
1678 | 1690 | | |
1679 | 1691 | | |
1680 | | - | |
1681 | 1692 | | |
1682 | | - | |
1683 | 1693 | | |
1684 | 1694 | | |
1685 | 1695 | | |
| |||
1693 | 1703 | | |
1694 | 1704 | | |
1695 | 1705 | | |
1696 | | - | |
| 1706 | + | |
| 1707 | + | |
1697 | 1708 | | |
1698 | 1709 | | |
1699 | 1710 | | |
1700 | 1711 | | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
1701 | 1722 | | |
1702 | 1723 | | |
1703 | 1724 | | |
| |||
1718 | 1739 | | |
1719 | 1740 | | |
1720 | 1741 | | |
1721 | | - | |
| 1742 | + | |
| 1743 | + | |
1722 | 1744 | | |
1723 | 1745 | | |
1724 | 1746 | | |
1725 | 1747 | | |
1726 | | - | |
| 1748 | + | |
1727 | 1749 | | |
1728 | 1750 | | |
1729 | 1751 | | |
1730 | 1752 | | |
1731 | 1753 | | |
1732 | | - | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
1733 | 1757 | | |
1734 | 1758 | | |
1735 | 1759 | | |
| |||
1829 | 1853 | | |
1830 | 1854 | | |
1831 | 1855 | | |
| 1856 | + | |
1832 | 1857 | | |
1833 | 1858 | | |
1834 | 1859 | | |
| |||
1854 | 1879 | | |
1855 | 1880 | | |
1856 | 1881 | | |
1857 | | - | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
1858 | 1889 | | |
1859 | 1890 | | |
1860 | 1891 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1843 | 1843 | | |
1844 | 1844 | | |
1845 | 1845 | | |
| 1846 | + | |
1846 | 1847 | | |
1847 | 1848 | | |
1848 | 1849 | | |
| |||
1856 | 1857 | | |
1857 | 1858 | | |
1858 | 1859 | | |
| 1860 | + | |
| 1861 | + | |
1859 | 1862 | | |
1860 | | - | |
1861 | | - | |
1862 | | - | |
| 1863 | + | |
1863 | 1864 | | |
1864 | 1865 | | |
1865 | 1866 | | |
| |||
1879 | 1880 | | |
1880 | 1881 | | |
1881 | 1882 | | |
1882 | | - | |
1883 | | - | |
1884 | | - | |
1885 | | - | |
1886 | | - | |
1887 | | - | |
1888 | | - | |
1889 | | - | |
1890 | | - | |
1891 | | - | |
1892 | | - | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
1893 | 1896 | | |
1894 | 1897 | | |
1895 | 1898 | | |
| |||
1948 | 1951 | | |
1949 | 1952 | | |
1950 | 1953 | | |
| 1954 | + | |
1951 | 1955 | | |
1952 | 1956 | | |
| 1957 | + | |
| 1958 | + | |
1953 | 1959 | | |
1954 | 1960 | | |
1955 | 1961 | | |
| |||
1982 | 1988 | | |
1983 | 1989 | | |
1984 | 1990 | | |
1985 | | - | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
1986 | 1996 | | |
1987 | 1997 | | |
1988 | 1998 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
62 | | - | |
63 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
| |||
82 | 90 | | |
83 | 91 | | |
84 | 92 | | |
| 93 | + | |
85 | 94 | | |
86 | 95 | | |
87 | 96 | | |
88 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
89 | 102 | | |
90 | 103 | | |
91 | 104 | | |
92 | 105 | | |
93 | 106 | | |
94 | 107 | | |
95 | | - | |
| 108 | + | |
96 | 109 | | |
97 | | - | |
| 110 | + | |
98 | 111 | | |
99 | 112 | | |
100 | 113 | | |
| |||
123 | 136 | | |
124 | 137 | | |
125 | 138 | | |
126 | | - | |
127 | | - | |
128 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
129 | 150 | | |
130 | 151 | | |
131 | 152 | | |
| |||
0 commit comments