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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371
|
// Copyright (c) 2017-2019, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
/*
* A neural network is defined through a collection of layers
* and represents a directed acyclic graph (DAG).
* Each layer has a name, a layer type,
* a list of input names, a list of output names,
* and a collection of parameters specific to the layer type.
*
* The graph structure and connectivity of the neural network
* is inferred from the input and output names.
* A neural network starts with the layer
* whose input name is equal to the value specified in
* ``Model.description.input.name``,
* and ends with the layer
* whose output name is equal to the value specified in
* ``Model.description.output.name``.
* Layers must have unique input and output names,
* and a layer may not have input or output names that
* refer to layers that are not yet defined.
*
* For Core ML specification version <=3,
* all inputs are mapped to static rank 5 tensors, with axis notations
* [Sequence, Batch, Channel, Height, Width].
*
* From specification version 4 onwards (iOS >= 13, macOS >= 10.15), more
* options are available (see enums ``NeuralNetworkMultiArrayShapeMapping``,
* ``NeuralNetworkImageShapeMapping``) to map inputs to generic N-Dimensional
* (or N rank) tensors, where N >= 1.
*
* Each layer type may have specific constraints on the ranks of its inputs and
* outputs.
*
* Some of the layers (such as softmax, reduce, etc) have parameters that have
* been described in terms of notational axis "Channel", "Height", "Width" or
* "Sequence". They can be re-interpreted easily in the general ND setting by
* using the following rule: "width" is same as axis = -1 (i.e. the last axis
* from the end) "height" is same as axis = -2 (i.e. the second last axis from
* the end) "channel" is same as axis = -3 (i.e. the third last axis from the
* end) "sequence" is same as axis = -5 (i.e. the fifth last axis from the end)
*
* Several layers are available in 3 different variations, with the names ending
* in identifiers: ``like``, ``static`` and ``dynamic``. For instance,
* ``FillLike``,
* ``FillStatic`` and ``FillDynamic``. The ``static`` variation generally will
* have a property corresponding to the shape of the output. For instance, if
* the output of the ``FillStatic`` layer is desired to be of shape (10, 4), the
* property ``targetShape`` will have to be set to [10, 4]. In the ``dynamic``
* case, the shape is an input, hence it can be changed at runtime. For
* instance, for a ``FillDynamic`` layer, the input would have to be an array
* containing the values 10 and 4, if the desired output is of shape (10, 4).
* Whereas in the
* ``like`` case, the additional input's shape is used as the output shape,
* ignoring its values. For instance, for a ``FillLike`` layer, for an input
* with shape (10, 4), the output generated will also be of shape (10, 4),
* values of the input will be ignored.
*/
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
import public "Parameters.proto";
package CoreML.Specification;
enum NeuralNetworkMultiArrayShapeMapping {
/*
* Describes how the MultiArray shape for the inputs,
* provided in Features Types proto via model description,
* is mapped to construct tensors that are fed into the Neural Network layers.
*/
/*
* Default legacy value. Only supported for Core ML Specification version
* <= 3.
*
* The default legacy shape mapping resolves all input shapes to a rank 5
* equivalent with axis notation of [Seq, Batch, Channel, Height, Width].
*
* When this enum value is selected,
* the repeated shape field in the message "ArrayFeatureType" in feature types
* proto, must be either length 1 or length 3.
*
* The following rule is used to map the values in the shape field to the
* actual tensor shape: rank 1 shape is mapped to shape [1,1,C,1,1] rank 3
* shape is mapped to shape [1,1,C,H,W] At runtime, the first two dimensions
* (Seq or Batch) can be presented as well, with non-1 values.
*
* It is invalid to use this enum value if any of the layers added
* Specification version 4 (iOS >= 13, macOS >= 10.15) onwards are used in the
* network. Validator will raise an error in that case.
*/
RANK5_ARRAY_MAPPING = 0;
/*
* The exact shape and rank (i.e. number of dimensions in the shape) of the
* input, as specified in the message "ArrayFeatureType", is passed through to
* the layers. Supported only for Specification version >= 4 (iOS >= 13, macOS
* >= 10.15).
*/
EXACT_ARRAY_MAPPING = 1;
}
enum NeuralNetworkImageShapeMapping {
/*
* Describes how the shape of the input tensors is constructed from image
* inputs.
*/
/*
* In this case, image input is mapped to a rank 5 tensor.
* For Color images, input tensor is shaped as [1,1,3,H,W].
* For Gray images, input tensor is shaped as [1,1,1,H,W].
*/
RANK5_IMAGE_MAPPING = 0;
/*
* For Color images, input tensor is shaped as [1,3,H,W].
* For Gray images, input tensor is shaped as [1,1,H,W].
* Supported only for Specification version >= 4 (iOS >= 13, macOS >= 10.15).
*/
RANK4_IMAGE_MAPPING = 1;
}
/*
A neural network.
*/
message NeuralNetwork {
repeated NeuralNetworkLayer layers = 1;
repeated NeuralNetworkPreprocessing preprocessing = 2;
// use this enum value to determine the input tensor shapes to the neural
// network, for multiarray inputs
NeuralNetworkMultiArrayShapeMapping arrayInputShapeMapping = 5;
// use this enum value to determine the input tensor shapes to the neural
// network, for image inputs
NeuralNetworkImageShapeMapping imageInputShapeMapping = 6;
NetworkUpdateParameters updateParams = 10;
}
// Preprocessing
// -------------
/*
* A neural network preprocessor that
* performs a scalar multiplication of an image
* followed by addition of scalar biases to the channels.
*
* Input: X
* An image in BGR or RGB format with shape ``[3, H, W]``
* or in grayscale format with shape ``[1, H, W]``.
* Output: Y
* An image with format and shape corresponding to the input.
*
* If the input image is in BGR format:
*
* .. code::
*
* Y[0, :, :] = channelScale * X[0, :, :] + blueBias
* Y[1, :, :] = channelScale * X[1, :, :] + greenBias
* Y[2, :, :] = channelScale * X[2, :, :] + redBias
*
* If the input image is in RGB format:
*
* .. code::
*
* Y[0, :, :] = channelScale * X[0, :, :] + redBias
* Y[1, :, :] = channelScale * X[1, :, :] + greenBias
* Y[2, :, :] = channelScale * X[2, :, :] + blueBias
*
* If the input image is in grayscale format:
*
* .. code::
*
* Y[0, :, :] = channelScale * X[0, :, :] + grayBias
*/
message NeuralNetworkImageScaler {
float channelScale = 10; // Scalar to be multiplied.
float blueBias = 20; // Scalar blue bias to be added.
float greenBias = 21; // Scalar green bias to be added.
float redBias = 22; // Scalar red bias to be added.
float grayBias = 30; // Scalar bias to be added for grayscale images.
}
/*
* A neural network preprocessor that
* subtracts the provided mean image from the input image.
* The mean image is subtracted from the input named
* ``NeuralNetworkPreprocessing.featureName``.
*/
message NeuralNetworkMeanImage {
/*
* Mean image stored as a flattened array of floats,
* representing shape [Channel,Height,Width].
*/
repeated float meanImage = 1;
}
// Preprocessing parameters for image inputs.
message NeuralNetworkPreprocessing {
string featureName = 1; // must be equal to the input name to which the
// preprocessing is applied
oneof preprocessor {
NeuralNetworkImageScaler scaler = 10;
NeuralNetworkMeanImage meanImage = 11;
}
}
// Activation Functions
// --------------------
/*
* A rectified linear unit (ReLU) activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \text{max}(0, x)
*/
message ActivationReLU {}
/*
* A leaky rectified linear unit (ReLU) activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \begin{cases}
* x & \text{if } x \geq 0 \\
* \alpha x & \text{if } x < 0
* \end{cases}
*/
message ActivationLeakyReLU {
float alpha = 1; // negative slope value for leakyReLU
}
/*
* A hyperbolic tangent activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \dfrac{1 - e^{-2x}}{1 + e^{-2x}}
*/
message ActivationTanh {}
/*
* A scaled hyperbolic tangent activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \alpha \tanh(\beta x)
*/
message ActivationScaledTanh {
float alpha = 1;
float beta = 2;
}
/*
* A sigmoid activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \dfrac{1}{1 + e^{-x}}
*/
message ActivationSigmoid {}
/*
* A linear activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \alpha x + \beta
*/
message ActivationLinear {
float alpha = 1;
float beta = 2;
}
/*
* A hard sigmoid activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \text{min}(\text{max}(\alpha x + \beta, 0), 1)
*/
message ActivationSigmoidHard {
float alpha = 1;
float beta = 2;
}
/*
* A parameterized rectified linear unit (PReLU) activation function.
* Input must be at least rank 3. Axis = -3 is denoted by "C", or channels.
* "alpha" parameter can be a vector of length C.
*
* This function has the following formula:
*
* .. math::
* f(x_i) = \begin{cases}
* x_i & \text{if } x_i \geq 0 \\
* \alpha_i x_i & \text{if } x_i < 0
* \end{cases} \;,\;i=1,...,C
*/
message ActivationPReLU {
// parameter of length C or 1.
// If length is 1, same value is used for all channels
WeightParams alpha = 1;
}
/*
* An exponential linear unit (ELU) activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \begin{cases}
* x & \text{if } x \geq 0 \\
* \alpha (e^x - 1) & \text{if } x < 0
* \end{cases}
*/
message ActivationELU {
float alpha = 1;
}
/*
* A thresholded rectified linear unit (ReLU) activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \begin{cases}
* x & \text{if } x \geq \alpha \\
* 0 & \text{if } x < \alpha
* \end{cases}
*/
message ActivationThresholdedReLU {
float alpha = 1;
}
/*
* A softsign activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \dfrac{x}{1 + |x|}
*/
message ActivationSoftsign {}
/*
* A softplus activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \text{log}(1 + e^x)
*/
message ActivationSoftplus {}
/*
* A parametric softplus activation function.
* Input must be at least rank 3. axis = -3 is denoted by "C", or channels.
* "alpha"/"beta" parameter can be a vector of length C.
*
* This function has the following formula:
*
* .. math::
* f(x_i) = \alpha_i \text{log}(1 + e^{\beta_i x_i}) \;,\;i=1,...,C
*/
message ActivationParametricSoftplus {
// If length is 1, same value is used for all channels
WeightParams alpha = 1; // parameter of length C or 1
WeightParams beta = 2; // parameter of length C or 1
}
message ActivationParams {
oneof NonlinearityType {
ActivationLinear linear = 5;
ActivationReLU ReLU = 10;
ActivationLeakyReLU leakyReLU = 15;
ActivationThresholdedReLU thresholdedReLU = 20;
ActivationPReLU PReLU = 25;
ActivationTanh tanh = 30;
ActivationScaledTanh scaledTanh = 31;
ActivationSigmoid sigmoid = 40;
ActivationSigmoidHard sigmoidHard = 41;
ActivationELU ELU = 50;
ActivationSoftsign softsign = 60;
ActivationSoftplus softplus = 70;
ActivationParametricSoftplus parametricSoftplus = 71;
}
}
/*
* Representation of the intermediate tensors
*/
message Tensor {
// Number of dimensions in the tensor shape
uint32 rank = 1;
// actual value of the tensor shape.
// must be of length "rank". Can contain -1s for unknown dimensions.
repeated int64 dimValue = 2;
}
/*
* A single neural network layer.
*/
message NeuralNetworkLayer {
string name = 1; // descriptive name of the layer
repeated string input = 2;
repeated string output = 3;
repeated Tensor inputTensor =
4; // must be the same length as the "input" field
repeated Tensor outputTensor =
5; // must be the same length as the "output" field
// Must be set to true to mark the layer as updatable.
// If true, the weightParams in the layer's properties must also be set to
// updatable If false, the value of the isUpdatable parameter within the
// layer's weights are ignored
bool isUpdatable = 10;
oneof layer {
// Start at 100 here
ConvolutionLayerParams convolution = 100;
PoolingLayerParams pooling = 120;
ActivationParams activation = 130;
InnerProductLayerParams innerProduct = 140;
EmbeddingLayerParams embedding = 150;
// Normalization-related Layers
BatchnormLayerParams batchnorm = 160;
MeanVarianceNormalizeLayerParams mvn = 165;
L2NormalizeLayerParams l2normalize = 170;
SoftmaxLayerParams softmax = 175;
LRNLayerParams lrn = 180;
CropLayerParams crop = 190;
PaddingLayerParams padding = 200;
UpsampleLayerParams upsample = 210;
ResizeBilinearLayerParams resizeBilinear = 211;
CropResizeLayerParams cropResize = 212;
UnaryFunctionLayerParams unary = 220;
// Element-wise Operations
AddLayerParams add = 230;
MultiplyLayerParams multiply = 231;
AverageLayerParams average = 240;
ScaleLayerParams scale = 245;
BiasLayerParams bias = 250;
MaxLayerParams max = 260;
MinLayerParams min = 261;
DotProductLayerParams dot = 270;
ReduceLayerParams reduce = 280;
LoadConstantLayerParams loadConstant = 290;
// Data Reorganization
ReshapeLayerParams reshape = 300;
FlattenLayerParams flatten = 301;
PermuteLayerParams permute = 310;
ConcatLayerParams concat = 320;
SplitLayerParams split = 330;
SequenceRepeatLayerParams sequenceRepeat = 340;
ReorganizeDataLayerParams reorganizeData = 345;
SliceLayerParams slice = 350;
// Recurrent Layers
SimpleRecurrentLayerParams simpleRecurrent = 400;
GRULayerParams gru = 410;
UniDirectionalLSTMLayerParams uniDirectionalLSTM = 420;
BiDirectionalLSTMLayerParams biDirectionalLSTM = 430;
// Custom (user-implemented) Layer
CustomLayerParams custom = 500;
// Following layers are available only after Core ML Specification
// version >= 4 (iOS >= 13, macOS >= 10.15)
// Control Flow related Layers
CopyLayerParams copy = 600;
BranchLayerParams branch = 605;
LoopLayerParams loop = 615;
LoopBreakLayerParams loopBreak = 620;
LoopContinueLayerParams loopContinue = 625;
RangeStaticLayerParams rangeStatic = 635;
RangeDynamicLayerParams rangeDynamic = 640;
// Element-wise Unary Layers
ClipLayerParams clip = 660;
CeilLayerParams ceil = 665;
FloorLayerParams floor = 670;
SignLayerParams sign = 680;
RoundLayerParams round = 685;
Exp2LayerParams exp2 = 700;
SinLayerParams sin = 710;
CosLayerParams cos = 715;
TanLayerParams tan = 720;
AsinLayerParams asin = 730;
AcosLayerParams acos = 735;
AtanLayerParams atan = 740;
SinhLayerParams sinh = 750;
CoshLayerParams cosh = 755;
TanhLayerParams tanh = 760;
AsinhLayerParams asinh = 770;
AcoshLayerParams acosh = 775;
AtanhLayerParams atanh = 780;
ErfLayerParams erf = 790;
GeluLayerParams gelu = 795;
// Element-wise Binary with Broadcasting Support
EqualLayerParams equal = 815;
NotEqualLayerParams notEqual = 820;
LessThanLayerParams lessThan = 825;
LessEqualLayerParams lessEqual = 827;
GreaterThanLayerParams greaterThan = 830;
GreaterEqualLayerParams greaterEqual = 832;
LogicalOrLayerParams logicalOr = 840;
LogicalXorLayerParams logicalXor = 845;
LogicalNotLayerParams logicalNot = 850;
LogicalAndLayerParams logicalAnd = 855;
ModBroadcastableLayerParams modBroadcastable = 865;
MinBroadcastableLayerParams minBroadcastable = 870;
MaxBroadcastableLayerParams maxBroadcastable = 875;
AddBroadcastableLayerParams addBroadcastable = 880;
PowBroadcastableLayerParams powBroadcastable = 885;
DivideBroadcastableLayerParams divideBroadcastable = 890;
FloorDivBroadcastableLayerParams floorDivBroadcastable = 895;
MultiplyBroadcastableLayerParams multiplyBroadcastable = 900;
SubtractBroadcastableLayerParams subtractBroadcastable = 905;
// Tensor Manipulations
TileLayerParams tile = 920;
StackLayerParams stack = 925;
GatherLayerParams gather = 930;
ScatterLayerParams scatter = 935;
GatherNDLayerParams gatherND = 940;
ScatterNDLayerParams scatterND = 945;
SoftmaxNDLayerParams softmaxND = 950;
GatherAlongAxisLayerParams gatherAlongAxis = 952;
ScatterAlongAxisLayerParams scatterAlongAxis = 954;
ReverseLayerParams reverse = 960;
ReverseSeqLayerParams reverseSeq = 965;
SplitNDLayerParams splitND = 975;
ConcatNDLayerParams concatND = 980;
TransposeLayerParams transpose = 985;
SliceStaticLayerParams sliceStatic = 995;
SliceDynamicLayerParams sliceDynamic = 1000;
SlidingWindowsLayerParams slidingWindows = 1005;
TopKLayerParams topK = 1015;
ArgMinLayerParams argMin = 1020;
ArgMaxLayerParams argMax = 1025;
EmbeddingNDLayerParams embeddingND = 1040;
BatchedMatMulLayerParams batchedMatmul = 1045;
// Tensor Allocation / Reshape-related Operations
GetShapeLayerParams getShape = 1065;
LoadConstantNDLayerParams loadConstantND = 1070;
FillLikeLayerParams fillLike = 1080;
FillStaticLayerParams fillStatic = 1085;
FillDynamicLayerParams fillDynamic = 1090;
BroadcastToLikeLayerParams broadcastToLike = 1100;
BroadcastToStaticLayerParams broadcastToStatic = 1105;
BroadcastToDynamicLayerParams broadcastToDynamic = 1110;
SqueezeLayerParams squeeze = 1120;
ExpandDimsLayerParams expandDims = 1125;
FlattenTo2DLayerParams flattenTo2D = 1130;
ReshapeLikeLayerParams reshapeLike = 1135;
ReshapeStaticLayerParams reshapeStatic = 1140;
ReshapeDynamicLayerParams reshapeDynamic = 1145;
RankPreservingReshapeLayerParams rankPreservingReshape = 1150;
ConstantPaddingLayerParams constantPad = 1155;
// Random Distributions
RandomNormalLikeLayerParams randomNormalLike = 1170;
RandomNormalStaticLayerParams randomNormalStatic = 1175;
RandomNormalDynamicLayerParams randomNormalDynamic = 1180;
RandomUniformLikeLayerParams randomUniformLike = 1190;
RandomUniformStaticLayerParams randomUniformStatic = 1195;
RandomUniformDynamicLayerParams randomUniformDynamic = 1200;
RandomBernoulliLikeLayerParams randomBernoulliLike = 1210;
RandomBernoulliStaticLayerParams randomBernoulliStatic = 1215;
RandomBernoulliDynamicLayerParams randomBernoulliDynamic = 1220;
CategoricalDistributionLayerParams categoricalDistribution = 1230;
// Reduction-related Layers:
ReduceL1LayerParams reduceL1 = 1250;
ReduceL2LayerParams reduceL2 = 1255;
ReduceMaxLayerParams reduceMax = 1260;
ReduceMinLayerParams reduceMin = 1265;
ReduceSumLayerParams reduceSum = 1270;
ReduceProdLayerParams reduceProd = 1275;
ReduceMeanLayerParams reduceMean = 1280;
ReduceLogSumLayerParams reduceLogSum = 1285;
ReduceSumSquareLayerParams reduceSumSquare = 1290;
ReduceLogSumExpLayerParams reduceLogSumExp = 1295;
// Masking / Selection Layers
WhereNonZeroLayerParams whereNonZero = 1313;
MatrixBandPartLayerParams matrixBandPart = 1315;
LowerTriangularLayerParams lowerTriangular = 1320;
UpperTriangularLayerParams upperTriangular = 1325;
WhereBroadcastableLayerParams whereBroadcastable = 1330;
// Normalization Layers
LayerNormalizationLayerParams layerNormalization = 1350;
NonMaximumSuppressionLayerParams NonMaximumSuppression = 1400;
// Following layers are available only after Core ML Specification
// version >= 5 (iOS >= 14, macOS >= 11.0)
OneHotLayerParams oneHot = 1450;
CumSumLayerParams cumSum = 1455;
ClampedReLULayerParams clampedReLU = 1460;
ArgSortLayerParams argSort = 1461;
Pooling3DLayerParams pooling3d = 1465;
GlobalPooling3DLayerParams globalPooling3d = 1466;
SliceBySizeLayerParams sliceBySize = 1470;
Convolution3DLayerParams convolution3d = 1471;
}
}
/*
* Branching Layer
*
* A layer that provides the functionality of branching or an If-Else block.
*
* Must have 1 input. There are no outputs as the execution is transferred to
* either the if or the else branch based on the value of the input.
*
* Input is the condition predicate. Must be a scalar (length 1 tensor).
*
*/
message BranchLayerParams {
/*
* execute this graph if the absolute value of the input Tensor is greater
* than 1e-6 This must be present.
*/
NeuralNetwork ifBranch = 1;
/*
* execute this graph if the absolute value of the input Tensor is less than
* 1e-6 This is optional.
*/
NeuralNetwork elseBranch = 2;
}
/*
* Loop Layer
*
* A layer that provides the functionality of a "for" loop or a "while" loop.
*
* There are either no inputs or 1 input. When an input is present, it
* corresponds to the maximum loop count, in that case the value of the
* "maxLoopIterations" field is ignored. Input must be a scalar. (For
* description below, maxLoopIterations is assumed to be the value of the input,
* when its present)
*
* No outputs are produced. Blobs produced by the condition or the body network
* are visible in the scope of the overall network.
*
* "conditionNetwork" must produce a tensor with the name specified in the
* "conditionVar" field.
*
* There are 3 possible cases for determining the termination condition:
*
* Case 1:
*
* If there is no "conditionNetwork", in this case the layer corresponds to a
* pure for loop, which is run "maxLoopIterations" number of times. Equivalent
* pseudo-code:
*
* for loopIterator = 0 : maxLoopIterations
* bodyNetwork()
*
*
* Case 2:
*
* "conditionNetwork" is present, and "maxLoopIterations" is 0 and there is no
* input, in this case the layer corresponds to a while loop. Equivalent
* pseudo-code:
*
* conditionVar = conditionNetwork()
* while conditionVar:
* bodyNetwork()
* conditionVar = conditionNetwork()
*
*
* Case 3:
*
* "conditionNetwork" is provided, and "maxLoopIterations" is positive or there
* is an input, in this case the layer corresponds to a while loop with a joint
* condition. Equivalent pseudo-code:
*
* loopIterator = 0
* conditionVar = conditionNetwork()
* while (conditionVar and loopIterator < maxLoopIterations):
* bodyNetwork()
* loopIterator = loopIterator + 1
* conditionVar = conditionNetwork()
*
*/
message LoopLayerParams {
/*
* maximum number of iterations. Ignored if input is present.
*/
uint64 maxLoopIterations = 1;
/*
* This field provides the name of the tensor which is produced by the
* conditionNetwork and whose value is checked to start/continue/terminate the
* loop. Value close to 0.0f is treated as False. This field is optional. Must
* be a non empty string if and only if "conditionNetwork" is present.
*/
string conditionVar = 2;
/*
* Must generate a tensor with the name provided in the "conditionVar" field.
* This field is optional.
* Must be present if and only if "conditionVar" field is a non empty string.
*/
NeuralNetwork conditionNetwork = 3;
/*
* Body of the loop.
* This field must be present.
*/
NeuralNetwork bodyNetwork = 4;
}
/*
* Loop break Layer
*
* Terminate the loop that has this layer.
* If present, it should always reside in the "bodyNetwork" of the loop layer
*
* No inputs/outputs
*
*/
message LoopBreakLayerParams {}
/*
* Loop Continue Layer
*
* Stop the current loop iteration and continue on the next iteration.
* If present, it should always reside in the "bodyNetwork" of the loop layer
*
* No inputs/outputs
*
*/
message LoopContinueLayerParams {}
/*
* Copy Layer
*
* A layer that copies its input tensor to the output tensor.
* Must have 1 input and 1 output, with distinct names.
* This is the only layer that is allowed to re-generate an output that is
* already present in the neural network prior to this layer, in which case it
* will overwrite the output tensor.
*
*/
message CopyLayerParams {}
/*
* GreaterThan Layer
*
* Either 1 or 2 inputs.
* Produces 1 output.
* Perform elementwise greater than operation.
*
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = x1 > x2
* or
* y = x1 > alpha, if only one input is provided
*
* Broadcasting is supported.
*
*/
message GreaterThanLayerParams {
/*
* Compare to the scalar value provided here if there is 1 input
*/
float alpha = 2;
}
/*
* GreaterEqual Layer
*
* Either 1 or 2 inputs.
* Produces 1 output.
* Perform elementwise greater equal operation.
*
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = x1 >= x2
* or
* y = x1 >= alpha, if only one input is provided
*
* Broadcasting is supported.
*
*/
message GreaterEqualLayerParams {
/*
* Compare to the scalar value provided here if there is 1 input
*/
float alpha = 2;
}
/*
* LessThan Layer
*
* Either 1 or 2 inputs.
* Produces 1 output.
* Perform elementwise less than operation.
*
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = x1 < x2
* or
* y = x1 < alpha, if only one input is provided
*
* Broadcasting is supported.
*
*/
message LessThanLayerParams {
/*
* Compare to the scalar value provided here if there is 1 input
*/
float alpha = 2;
}
/*
* LessEqual Layer
*
* Either 1 or 2 inputs.
* Produces 1 output.
* Perform elementwise less equal operation.
*
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = x1 <= x2
* or
* y = x1 <= alpha, if only one input is provided
*
* Broadcasting is supported.
*
*/
message LessEqualLayerParams {
/*
* Compare to the scalar value provided here if there is 1 input
*/
float alpha = 2;
}
/*
* Equal Layer
*
* Either 1 or 2 inputs.
* Produces 1 output.
* Perform elementwise equal operation.
*
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = x1 == x2
* or
* y = x1 == alpha, if only one input is provided
*
* Broadcasting is supported.
*
*/
message EqualLayerParams {
/*
* Compare to the scalar value provided here if there is 1 input
*/
float alpha = 1;
}
/*
* NotEqual Layer
*
* Either 1 or 2 inputs.
* Produces 1 output.
* Perform elementwise not equal operation.
*
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = x1 != x2
* or
* y = x1 != alpha, if only one input is provided
*
* Broadcasting is supported.
*
*/
message NotEqualLayerParams {
/*
* Compare to the scalar value provided here if there is 1 input
*/
float alpha = 1;
}
/*
* LogicalAnd Layer
*
* Must have 2 inputs, produces 1 output.
* Perform elementwise logical AND operation.
*
* Input is considered False if equal to 0.0f otherwise True.
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = AND(x1, x2)
*
* Broadcasting is supported.
*
*/
message LogicalAndLayerParams {}
/*
* LogicalOr Layer
*
* Must have 2 inputs, produces 1 output.
* Perform elementwise logical OR operation.
*
* Input is considered False if equal to 0.0f otherwise True.
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = OR(x1, x2)
*
* Broadcasting is supported.
*
*/
message LogicalOrLayerParams {}
/*
* LogicalXor Layer
*
* Must have 2 inputs, produces 1 output.
* Perform elementwise logical XOR operation.
*
* Input is considered False if equal to 0.0f otherwise True.
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = XOR(x1, x2)
*
* Broadcasting is supported.
*
*/
message LogicalXorLayerParams {}
/*
* LogicalNot Layer
*
* Must have 1 input, produces 1 output.
* Perform elementwise logical NOT operation.
*
* Input is considered False if equal to 0.0f otherwise True.
* Output is 1.0f if the condition is true otherwise 0.0f.
*
* .. code::
*
* y = NOT(x)
*
*
*/
message LogicalNotLayerParams {}
// Border Amounts
// --------------
/*
* Specifies the amount of spatial border to be either padded or cropped.
*
* For padding:
*
* .. code::
*
* H_out = borderAmounts[0].startEdgeSize + H_in +
* borderAmounts[0].endEdgeSize W_out = borderAmounts[1].startEdgeSize + W_in +
* borderAmounts[1].endEdgeSize
*
* topPaddingAmount == Height startEdgeSize
* bottomPaddingAmount == Height endEdgeSize
* leftPaddingAmount == Width startEdgeSize
* rightPaddingAmount == Width endEdgeSize
*
* For cropping:
*
* .. code::
*
* H_out = (-borderAmounts[0].startEdgeSize) + H_in +
* (-borderAmounts[0].endEdgeSize) W_out = (-borderAmounts[1].startEdgeSize) +
* W_in + (-borderAmounts[1].endEdgeSize)
*
* topCropAmount == Height startEdgeSize
* bottomCropAmount == Height endEdgeSize
* leftCropAmount == Width startEdgeSize
* rightCropAmount == Width endEdgeSize
*/
message BorderAmounts {
message EdgeSizes {
/*
* The amount to be padded or cropped from the beginning.
*/
uint64 startEdgeSize = 1;
/*
* The amount to be padded or cropped from the end.
*/
uint64 endEdgeSize = 2;
}
/*
* The border amounts.
* This must be length 2 in the order ``[H, W]``.
*/
repeated EdgeSizes borderAmounts = 10;
}
/*
* Specifies the type of padding to be used with Convolution/Deconvolution and
* Pooling layers. After padding, input spatial shape: ``[H_in, W_in]``, gets
* modified to the output spatial shape ``[H_out, W_out]``.
*
* .. code::
*
* topPaddingAmount == Height startEdgeSize ==
* borderAmounts[0].startEdgeSize bottomPaddingAmount == Height endEdgeSize ==
* borderAmounts[0].endEdgeSize leftPaddingAmount == Width startEdgeSize ==
* borderAmounts[1].startEdgeSize rightPaddingAmount == Width endEdgeSize ==
* borderAmounts[1].endEdgeSize
*
* With Convolution or Pooling:
*
* .. code::
*
* H_out = int_division_round_down((H_in + topPaddingAmount +
* bottomPaddingAmount - KernelSize[0]),stride[0]) + 1
*
* which is same as:
*
* .. code::
*
* H_out = int_division_round_up((H_in + topPaddingAmount +
* bottomPaddingAmount - KernelSize[0] + 1),stride[0])
*
* With Deconvolution:
*
* .. code::
*
* H_out = (H_in-1) * stride[0] + kernelSize[0] - (topPaddingAmount +
* bottomPaddingAmount)
*
*
* The equivalent expressions hold true for ``W_out`` as well.
*
*
* By default, the values of ``paddingAmounts`` are set to ``0``,
* which results in a "true" valid padding.
* If non-zero values are provided for ``paddingAmounts``,
* "valid" convolution/pooling is performed within the spatially expanded input.
*
*/
message ValidPadding {
BorderAmounts paddingAmounts = 1;
}
/*
* Specifies the type of padding to be used with Convolution/Deconvolution and
* pooling layers. After padding, input spatial shape: ``[H_in, W_in]``, gets
* modified to the output spatial shape ``[H_out, W_out]``. With Convolution or
* pooling:
*
* .. code::
*
* H_out = int_division_round_up(H_in,stride[0])
* W_out = int_division_round_up(W_in,stride[1])
*
* This is achieved by using the following padding amounts:
*
* .. code::
*
* totalPaddingHeight = max(0,(H_out-1) * stride[0] + KernelSize[0] - Hin)
* totalPaddingWidth = max(0,(W_out-1) * stride[1] + KernelSize[1] - Win)
*
* There are two modes of asymmetry:
* ``BOTTOM_RIGHT_HEAVY``, and ``TOP_LEFT_HEAVY``.
*
* If the mode is ``BOTTOM_RIGHT_HEAVY``:
*
* .. code::
*
* topPaddingAmount = floor(totalPaddingHeight / 2)
* bottomPaddingAmount = totalPaddingHeight - topPaddingAmount
* leftPaddingAmount = floor(totalPaddingWidth / 2)
* rightPaddingAmount = totalPaddingWidth - leftPaddingAmount
*
* If the mode is ``TOP_LEFT_HEAVY``:
*
* .. code::
*
* bottomPaddingAmount = floor(totalPaddingHeight / 2)
* topPaddingAmount = totalPaddingHeight - bottomPaddingAmount
* rightPaddingAmount = floor(totalPaddingWidth / 2)
* leftPaddingAmount = totalPaddingWidth - rightPaddingAmount
*
*
* With Deconvolution:
*
* .. code::
*
* H_out = H_in * stride[0]
* W_out = W_in * stride[1]
*/
message SamePadding {
enum SamePaddingMode {
BOTTOM_RIGHT_HEAVY = 0;
TOP_LEFT_HEAVY = 1;
}
SamePaddingMode asymmetryMode = 1;
}
/*
* Specifies how grid points are sampled from an interval.
* Without the loss of generality, assume the interval to be [0, X-1] from which
* N points are to be sampled. Here X may correspond to an input image's height
* or width. All the methods can be expressed in terms of numpy's linspace
* function, along with the constraint that grid points have to lie in the
* interval [0, X-1]. Note: numpy.linspace(start = start, end = end, num = N,
* endpoint = True) corresponds to sampling N points uniformly from the interval
* [start, end], endpoints included. The methods vary in how the ``start`` and
* ``end`` values are computed.
*/
message SamplingMode {
enum Method {
/*
* start = 0, end = X-1
* grid points = numpy.linspace(start, end)
*/
STRICT_ALIGN_ENDPOINTS_MODE = 0;
/*
* if N == 1: start = end = (X-1)/2
* otherwise, start = 0, end = X-1
* grid points = numpy.linspace(start, end)
*/
ALIGN_ENDPOINTS_MODE = 1;
/*
* start = 0, end = X - X/N
* grid points = min(X-1, numpy.linspace(start, end))
* This is same as the mode used in the upsample layer in this
* specification, when used with bilinear interpolation. In that case N/X =
* upsample ratio.
*/
UPSAMPLE_MODE = 2;
/*
* spacing = max(1, X-1)/N
* start = 0.5 * spacing
* end = start + (N-1) * spacing
* grid points = min(X-1, numpy.linspace(start, end))
*/
ROI_ALIGN_MODE = 3;
}
Method samplingMethod = 1;
}
/*
* Specifies the convention used to specify four bounding box coordinates for an
* image of size (Height, Width). The (0,0) coordinate corresponds to the
* top-left corner of the image.
*/
message BoxCoordinatesMode {
enum Coordinates {
/*
* [h_start, w_start, h_end, w_end]
*/
CORNERS_HEIGHT_FIRST = 0;
/*
* [w_start, h_start, w_end, h_end]
*/
CORNERS_WIDTH_FIRST = 1;
/*
* [h_center, w_center, box_height, box_width]
*/
CENTER_SIZE_HEIGHT_FIRST = 2;
/*
* [w_center, h_center, box_width, box_height]
*/
CENTER_SIZE_WIDTH_FIRST = 3;
}
Coordinates boxMode = 1;
}
/*
* Weights for layer parameters.
* Weights are stored as repeated floating point numbers
* using row-major ordering
* and can represent 1-, 2-, 3-, or 4-dimensional data.
*/
message WeightParams {
/*
* Values specified in single / float / FP32 precision.
*/
repeated float floatValue = 1;
/*
* Values in 16-bit half precision floating point.
*/
bytes float16Value = 2;
/*
* Raw value specification for quantized lower precisions.
*
* This field is interpreted as uintN, where N is the number of bits in
* quantization. E.g. if n=8, the field is interpreted as an array of UINT8.
* Use this field for quantized parameters unless specifically noted to use
* int8RawValue.
*/
bytes rawValue = 30;
/*
* Field to be used if int8DynamicQuantize is set in the parent layer.
* Cannot be set if rawValue is also set.
* The values in this field are interpreted as INT8.
*
* If this field is set, following conditions must hold true:
* * QuantizationType == LinearQuantizationParams, such that
* * size of the "scale" field is 1 and "bias" field is empty in
* "LinearQuantizationParams"
*/
bytes int8RawValue = 31;
/*
* Quantization related parameters.
*/
QuantizationParams quantization = 40;
bool isUpdatable = 50;
}
/*
* Quantization parameters.
*/
message QuantizationParams {
uint64 numberOfBits = 1;
oneof QuantizationType {
LinearQuantizationParams linearQuantization = 101;
LookUpTableQuantizationParams lookupTableQuantization = 102;
}
}
message LinearQuantizationParams {
/*
* Stores scale and bias values corresponding to the quantized weights.
* Must be an array of 1 element, or an array of C elements, where C
* is number of output channels. For recurrent layers it is equal to
* the output vector size.
*
* Relationship between quantized weights, unquantized weights, scale and
* bias:
*
* W_unquantized = W_quantized * scale + bias
*
*/
repeated float scale = 1;
repeated float bias = 2;
}
message LookUpTableQuantizationParams {
/* Stores look-up table quantization values. Must be an array of
(2^numberOfBits) Elements.
*/
repeated float floatValue = 1;
}
// Layers
// ------
/*
* A layer that performs spatial convolution or deconvolution.
*
* .. code::
*
* y = ConvolutionLayer(x)
*
* Requires 1 or 2 inputs and produces 1 output.
*
* Input
* First Input:
* A blob with rank greater than or equal to 4.
* Rank 4 blob represents [Batch, channels, height, width].
* For ranks greater than 4, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch.
*
* From Core ML specification version 4 onwards (iOS >= 13, macOS >= 10.15).
* convolution layer can have 2 inputs, in which case the second input is
* the blob representing the weights. This is allowed when "isDeconvolution"
* = False. The weight blob should have shape
* ``[outputChannels, kernelChannels, kernelHeight, kernelWidth]``,
* where kernelChannels == inputChannels / nGroups.
*
* Output
* Rank is same as the input. e.g.: for rank 4 input, output shape is [B,
* C_out, H_out, W_out]
*
*
* If ``dilationFactor`` is not 1, effective kernel size is
* modified as follows:
*
* .. code::
*
* KernelSize[0] <-- (kernelSize[0]-1) * dilationFactor[0] + 1
* KernelSize[1] <-- (kernelSize[1]-1) * dilationFactor[1] + 1
*
* Type of padding can be ``valid`` or ``same``. Output spatial dimensions
* depend on the the type of padding. For details, refer to the descriptions of
* the messages "ValidPadding" and "SamePadding". Padded values are all zeros.
*
* For Deconvolution, ``ConvolutionPaddingType`` (``valid`` or ``same``) is
* ignored when ``outputShape`` is set.
*
*
*/
message ConvolutionLayerParams {
/*
* The number of kernels.
* Same as ``C_out`` used in the layer description.
*/
uint64 outputChannels = 1;
/*
* Channel dimension of the kernels.
* Must be equal to ``inputChannels / nGroups``, if isDeconvolution == False
* Must be equal to ``inputChannels``, if isDeconvolution == True
*/
uint64 kernelChannels = 2;
/*
* Group convolution, i.e. weight reuse along channel axis.
* Input and kernels are divided into g groups
* and convolution / deconvolution is applied within the groups independently.
* If not set or 0, it is set to the default value 1.
*/
uint64 nGroups = 10;
/*
* Must be length 2 in the order ``[H, W]``.
* If not set, default value ``[3, 3]`` is used.
*/
repeated uint64 kernelSize = 20;
/*
* Must be length 2 in the order ``[H, W]``.
* If not set, default value ``[1, 1]`` is used.
*/
repeated uint64 stride = 30;
/*
* Must be length 2 in order ``[H, W]``.
* If not set, default value ``[1, 1]`` is used.
* It is ignored if ``isDeconvolution == true``.
*/
repeated uint64 dilationFactor = 40;
/*
* The type of padding.
*/
oneof ConvolutionPaddingType {
ValidPadding valid = 50;
SamePadding same = 51;
}
/*
* Flag to specify whether it is a deconvolution layer.
*/
bool isDeconvolution = 60;
/*
* Flag to specify whether a bias is to be added or not.
*/
bool hasBias = 70;
/*
* Weights associated with this layer.
* If convolution (``isDeconvolution == false``), weights have the shape
* ``[outputChannels, kernelChannels, kernelHeight, kernelWidth]``, where
* kernelChannels == inputChannels / nGroups If deconvolution
* (``isDeconvolution == true``) weights have the shape
* ``[kernelChannels, outputChannels / nGroups, kernelHeight, kernelWidth]``,
* where kernelChannels == inputChannels
*/
WeightParams weights = 90;
WeightParams bias = 91; // Must be of size [outputChannels].
/*
* The output shape, which has length 2 ``[H_out, W_out]``.
* This is used only for deconvolution (``isDeconvolution == true``).
* If not set, the deconvolution output shape is calculated
* based on ``ConvolutionPaddingType``.
*/
repeated uint64 outputShape = 100;
}
/*
* A layer that performs a 3-dimensional convolution.
*
* .. code::
*
* y = Convolution3DLayer(x)
*
* Input
* A blob of rank 5.
* The input blob's shape should be ``[batch, channels, depth, height,
* width]``.
*
* Fields
* The bias field, if set, should have shape of ``[channelsOut]``.
*
* Output
* A blob of rank 5.
* The output blob's shape is ``[batch, channelsOut, depthOut, heightOut,
* widthOut]``.
*
* Type of padding can be ``custom``, ``valid``, or ``same``. Padded values are
* all zeros. Output spatial dimensions depend on the the type of padding. For
* details, refer to the descriptions of the ``PaddingType`` field of this
* ``Convolution3DLayerParams`` message.
*
* Example
* For example, given an input of size ``[1, 3, 3, 8, 8]``, a stride of 2 in
* each dimension, a kernel of 3 in each dimension, 2 output channels, and
* ``same`` padding, this layer will compute the total padding applied in the
* depth, height, and width dimensions to be 2, 1, and 1, respectively. The
* depth padding is even and will be applied equally to both sides of the depth
* dimension. Since the height and width padding values are odd, they'll be
* applied to the bottom/right of the height/width dimensions. Thus, the padding
* applied to the input will be
* ``[1, 1, 0, 1, 0, 1]`` (front, back, top, bottom, left, right). Finally,
* the output produced will have size ``[1, 2, 2, 4, 4]``.
*
*/
message Convolution3DLayerParams {
/*
* The number of channels in the output (channelsOut). Must be a positive
* integer.
*/
int32 outputChannels = 1;
/*
* The number of channels in the input (channels). Must be a positive integer.
*/
int32 inputChannels = 2;
/*
* Group convolution, i.e., weight reuse along the channel axis.
* It must evenly divide both the number of input and output channels and be
* at most the number of input channels (a depthwise convolution). Input and
* kernels are divided into g groups and convolution is applied within the
* groups independently.
*/
int32 nGroups = 10;
/* Depth of the convolution kernel. Must be a positive integer.
*/
int32 kernelDepth = 20;
/* Height of the convolution kernel. Must be a positive integer.
*/
int32 kernelHeight = 21;
/* Width of the convolution kernel. Must be a positive integer.
*/
int32 kernelWidth = 22;
/* Stride along the depth direction. Must be a positive integer.
*/
int32 strideDepth = 31;
/* Stride along the height direction. Must be a positive integer.
*/
int32 strideHeight = 32;
/* Stride along the width direction. Must be a positive integer.
*/
int32 strideWidth = 33;
/* Dilation along the depth direction. Must be a positive integer.
*/
int32 dilationDepth = 40;
/* Dilation along the height direction. Must be a positive integer.
*/
int32 dilationHeight = 41;
/* Dilation along the width direction. Must be a positive integer.
*/
int32 dilationWidth = 42;
/*
* Flag to specify whether a bias is to be added or not.
* If false, then no bias is added.
*/
bool hasBias = 50;
/*
* Weights associated with this layer.
* Weights have the shape
* if deconvolution == False
* ``[outputChannels, kernelChannels, kernelDepth, kernelHeight,
* kernelWidth]``, where kernelChannels == inputChannels / nGroups else if
* deconvolution == True
* ``[outputChannels / nGroups, kernelChannels, kernelDepth, kernelHeight,
* kernelWidth]``, where
*/
WeightParams weights = 60;
/*
* Must be of size ``[outputChannels]``.
*/
WeightParams bias = 61;
/*
* The type of padding.
* All padding types pad the input shape with zeros.
* CUSTOM padding will add the custom padding values specified below to their
* respective dimensions, e.g., `customPaddingFront` number of zeros will be
* added to one side of the input's depth dimension and `customPaddingBack`
* number of zeros will be added to the other side of the input's depth
* dimension. VALID padding adds no padding to any dimension. In this case,
* the last convolution along each dimension will be dropped if the input
* dimension and the kernel size, stride, and dilation do not match. SAME
* padding adds enough padding to each dimension such that the output of the
* convolution has size ``Ceiling(inputShape / stride)``. Padding is added
* evenly to both sides of each dimension unless the total padding to add is
* odd, in which case it is added to the back/bottom/right side of the
* respective dimension. For example, if the total padding needed in the depth
* dimension is 3, 1 zero will be added to the front side of the depth
* dimension and 2 zeros will be added to the back side.
*/
enum PaddingType {
CUSTOM = 0;
VALID = 1;
SAME = 2;
}
PaddingType paddingType = 70;
/* Padding before the input in the depth direction. Must be zero or a positive
* integer. Used when the `PaddingType` is `CustomPadding`, otherwise ignored
* by other padding types.
*/
int32 customPaddingFront = 80;
/* Padding after the input in the depth direction. Must be zero or a positive
* integer. Used when the `PaddingType` is `CustomPadding`, otherwise ignored
* by other padding types.
*/
int32 customPaddingBack = 81;
/* Padding before the input in the height direction. Must be zero or a
* positive integer. Used when the `PaddingType` is `CustomPadding`, otherwise
* ignored by other padding types.
*/
int32 customPaddingTop = 82;
/* Padding after the input in the height direction. Must be zero or a positive
* integer. Used when the `PaddingType` is `CustomPadding`, otherwise ignored
* by other padding types.
*/
int32 customPaddingBottom = 83;
/* Padding before the input in the width direction. Must be zero or a positive
* integer. Used when the `PaddingType` is `CustomPadding`, otherwise ignored
* by other padding types.
*/
int32 customPaddingLeft = 84;
/* Padding after the input in the width direction. Must be zero or a positive
* integer. Used when the `PaddingType` is `CustomPadding`, otherwise ignored
* by other padding types.
*/
int32 customPaddingRight = 85;
/* Flag to specify if this is Convolution Transpose or not.
*/
bool isDeconvolution = 86;
/*
* The output shape, which has length 3 ``[D_out, H_out, W_out]``.
* This is used only for deconvolution (``isDeconvolution == true``).
* If not set, the deconvolution output shape is calculated
* based on ``PaddingType``.
*/
repeated uint64 outputShape = 87;
}
/*
* A layer that performs a matrix-vector or matrix-matrix product.
* This is equivalent to a fully-connected, or dense layer.
* The weight parameters correspond to a matrix of dimensions (inputChannels,
* outputChannels) i.e. (C_in, C_out)
*
* .. code::
*
* y = InnerProductLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* Input can have rank 1 to rank 5. This is how it is reshaped in to the
* matrix (for rank > 1): rank 1 (x1) : in this case, the layer corresponds to a
* matrix-vector product. x1 must be equal to C_in rank 2 (x1, x2): x2 must be
* equal to C_in rank 3 (x1, x2, x3) --> (x1 * x2, x3). x3 must be equal to C_in
* rank 4 (x1, x2, x3, x4) ---> (x1, x2 * x3 * x4). x2 * x3 * x4 must be
* equal to C_in rank 5 (x1, x2, x3, x4, x5) ---> (x1 * x2, x3 * x4 * x5). x3 *
* x4 * x5 must be equal to C_in
*
* Output
* Output rank is same as the input rank
* rank 1: (C_out)
* rank 2: (x1, C_out)
* rank 3: (x1, x2, C_out)
* rank 4: (x1, C_out, 1, 1)
* rank 5: (x1, x2, C_out, 1, 1)
*
*/
message InnerProductLayerParams {
uint64 inputChannels = 1; // Input size: C_in.
uint64 outputChannels = 2; // Output size: C_out.
bool hasBias = 10; // Whether a bias is added or not.
WeightParams weights = 20; // Weight matrix [C_out, C_in].
WeightParams bias = 21; // Bias vector [C_out].
/*
* If set, this layer, at runtime, quantizes the floating point input blob to
* int8 before applying an inner product using INT8 weight matrix parameters,
* as provided in weights->int8RawValue. The result is then dequantized.
* Requires:
* * hasBias == false
* * QuantizationType == LinearQuantizationParams, such that
* * size of the "scale" field is 1 and "bias" field is empty in
* "LinearQuantizationParams"
* * numberOfBits == 8
* * weights->rawValue_size to be empty
*/
bool int8DynamicQuantize = 22;
}
/*
* A layer that performs a matrix lookup and optionally adds a bias.
* The weights matrix is stored with dimensions [outputChannels, inputDim].
*
* .. code::
*
* y = EmbeddingLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* Input values must be in the range ``[0, inputDim - 1]``.
*
* Input must have rank equal to 4 or 5, such that the last 3 dimensions are
* all 1. rank 4: shape (x1, 1, 1, 1). x1 is effectively the batch/sequence
* length. rank 5: shape (x1, x2 , 1, 1, 1). x1 * x2 is effectively the combined
* batch/sequence length.
*
* Output
* Output rank is same as the input rank. Please see input description
* above. rank 4: shape (x1, outputChannels, 1, 1) rank 5: shape (x1, x2,
* outputChannels, 1, 1)
*
*/
message EmbeddingLayerParams {
uint64 inputDim = 1; // Size of the input dictionary.
uint64 outputChannels = 2; // Size of the output vectors.
bool hasBias = 10; // Whether a bias is added or not.
WeightParams weights =
20; // 2-D weights of dimensions [outputChannels, inputDim].
WeightParams bias = 21; // Bias of size [outputChannels].
}
/*
* A layer that performs a matrix lookup and optionally adds a bias.
* The weights matrix is stored with dimensions [embeddingSize, vocabSize].
*
* .. code::
*
* y = EmbeddingNDLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* Input values must be in the range ``[0, vocabSize - 1]``.
* Input must have rank at least 2. The last dimension must always be 1.
* rank 2: shape (x1, 1). x1 is the batch/sequence length.
* rank 3: shape (x1, x2, 1). x1 * x2 is effectively the combined
* batch/sequence length. rank 4: shape (x1, x2, x3, 1). x1 * x2 * x2 is
* effectively the combined batch/sequence length. rank 5: shape (x1, x2 , x3,
* x4, 1). x1 * x2 * x3 * x4 is effectively the combined batch/sequence length.
*
* Output
* Output rank is same as the input rank. Please see input description
* above. rank 2: shape (x1, embeddingSize) rank 3: shape (x1, x2,
* embeddingSize) rank 4: shape (x1, x2, x3, embeddingSize) rank 5: shape (x1,
* x2, x3, x4, embeddingSize)
*
*/
message EmbeddingNDLayerParams {
uint64 vocabSize = 1; // Size of the input dictionary.
uint64 embeddingSize = 2; // Size of the output vectors.
bool hasBias = 3; // Whether a bias is added or not.
WeightParams weights =
20; // 2-D weights of dimensions [embeddingSize, vocabSize].
WeightParams bias = 21; // Bias of size [embeddingSize].
}
/*
* A layer that performs batch normalization,
* which is performed along axis = -3,
* and repeated along the other axes, if present.
*
* .. code::
*
* y = BatchnormLayer(x)
*
* Requires 1 input and produces 1 output.
*
* This operation is described by the following formula:
*
* .. math::
* y_i = \gamma_i \dfrac{ (x_i - \mu_i)}{\sqrt{\sigma_i^2 + \epsilon}} +
* \beta_i \;,\;i=1,....,C
*
* Input
* A blob with rank greater than equal to 3.
* Example: Rank 4 blob represents [Batch, channels, height, width]
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch.
*
* Output
* A blob with the same shape as the input.
*/
message BatchnormLayerParams {
uint64 channels = 1; // Size of the channel dimension in the input.
/*
* If ``computeMeanVar == true``,
* the mean and variance are calculated from either
* the single input instance, if ``instanceNormalization == true``,
* or the whole batch, if ``instanceNormalization = false``.
* and the values provided in parameters "mean" and "variance" are ignored.
*/
bool computeMeanVar = 5;
bool instanceNormalization = 6;
/*
* A small constant to avoid division by 0 while normalizing by variance.
* Defaults to ``1e-5`` if not set or set to ``0``.
*/
float epsilon = 10;
WeightParams gamma = 15; // Parameter of length [channels]
WeightParams beta = 16; // Parameter of length [channels]
WeightParams mean = 17; // Parameter of length [channels]
WeightParams variance = 18; // Parameter of length [channels]
}
/*
* A spatial pooling layer.
*
* .. code::
*
* y = PoolingLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank greater than equal to 4.
* Rank 4 blob represents [Batch, channels, height, width]
* For ranks greater than 4, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch.
*
* Output
* Rank is same as the input. e.g.: for rank 4 input, output shape is [B, C,
* H_out, W_out]
*
* Padding options are similar to ``ConvolutionLayerParams``
* with the additional option of ``ValidCompletePadding``
* (``includeLastPixel``), which ensures that the last application of the kernel
* always includes the last pixel of the input image, if there is padding.
*
* .. code::
*
* H_out = ceil(float(H_in + 2 * paddingAmounts[0] -
* kernelSize[0])/float(Stride[0])) + 1 if (paddingAmounts[0] > 0 or
* paddingAmounts[1] > 0) if ((H_out - 1) * Stride >= H_in + paddingAmounts[0])
* { H_out = H_out - 1
* }
* }
*
* The equivalent expressions hold true for ``W_out`` as well.
* Only symmetric padding is supported with this option.
*/
message PoolingLayerParams {
enum PoolingType {
MAX = 0;
AVERAGE = 1;
L2 = 2;
}
PoolingType type = 1; // Type of pooling operation.
/*
* Must be length 2 in the order ``[H, W]``.
* If not set, default value ``[3, 3]`` is used.
*/
repeated uint64 kernelSize = 10;
/*
* Must be length 2 in the order ``[H, W]``.
* If not set, default value ``[1, 1]`` is used.
*/
repeated uint64 stride = 20;
message ValidCompletePadding {
/*
* Must be length 2 in order ``[H, W]``.
* If not set, value ``[0, 0]`` is used.
*/
repeated uint64 paddingAmounts = 10;
}
oneof PoolingPaddingType {
ValidPadding valid = 30;
SamePadding same = 31;
ValidCompletePadding includeLastPixel = 32;
}
/*
* If true, padded values are excluded from the count (denominator)
* when computing average pooling.
*/
bool avgPoolExcludePadding = 50;
/*
* If true, global pooling is performed.
* Kernel size is inferred from the input data spatial dimensions.
*/
bool globalPooling = 60;
}
/*
* A layer to pool three spatial dimensions
*
* Input
* A blob with rank equal to 5, representing [Batch, channels, depth,
* height, width].
*
* Output
* Rank is same as the input: A blob with rank equal to 5, representing
* [Batch, channels, depth, height, width].
*
* Requires 1 input and produces 1 output.
*
* For example, given an input of shape (1,1,2,3,3):
* +----+----+----+
* / | 10 | 11 | 12 |
* / +----+----+----+
* / | 13 | 14 | 15 |
* / +----+----+----+
* / | 16 | 17 | 18 |
* / +----+----+----+
* +----+----+----+ /
* | 1 | 2 | 3 | /
* +----+----+----+ /
* | 4 | 5 | 6 | /
* +----+----+----+ /
* | 7 | 8 | 9 | /
* +----+----+----+
*
* And applying MAX pooling using:
* Kernel: 2x2x2
* Stride: 1x1x1
* Valid Padding
* We expect to get an output with shape: (1,1,1,2,2) and value:
* +----+----+
* | 14 | 15 |
* +----+----+
* | 17 | 18 |
* +----+----+
*/
message Pooling3DLayerParams {
enum PoolingType3D {
MAX = 0;
AVERAGE = 1;
}
// Whether to use Max or Average
PoolingType3D type = 1;
// Depth of the pooling region.
int32 kernelDepth = 2;
// Height of the pooling region.
int32 kernelHeight = 3;
// Width of the pooling region.
int32 kernelWidth = 4;
// Stride along the depth direction
int32 strideDepth = 5;
// Stride along the height direction
int32 strideHeight = 6;
// Stride along the width direction
int32 strideWidth = 7;
/*
* The type of padding.
* All padding types pad the input shape with zeros.
* CUSTOM padding will add the custom padding values specified below to their
* respective dimensions, e.g., `customPaddingFront` number of zeros will be
* added to one side of the input's depth dimension and `customPaddingBack`
* number of zeros will be added to the other side of the input's depth
* dimension. VALID padding adds no padding to any dimension. In this case,
* the last pool along each dimension will be dropped if the input dimension
* and the kernel size, and stride do not match. SAME padding adds enough
* padding to each dimension such that the output has the same spatial
* dimensions as the input. Padding is added evenly to both sides of each
* dimension unless the total padding to add is odd, in which case the extra
* padding is added to the back/bottom/right side of the respective dimension.
* For example, if the the total horizontal padding is 3, then there will be 1
* padding on the left, and 2 padding on the right.
*/
enum Pooling3DPaddingType {
CUSTOM = 0;
VALID = 1;
SAME = 2;
}
Pooling3DPaddingType paddingType = 15;
// Padding before the input in the depth direction.
int32 customPaddingFront = 8;
// Padding after the input in the depth direction.
int32 customPaddingBack = 9;
// Padding before the input in the height direction.
int32 customPaddingTop = 10;
// Padding after the input in the height direction.
int32 customPaddingBottom = 11;
// Padding before the input in the width direction.
int32 customPaddingLeft = 12;
// Padding after the input in the width direction.
int32 customPaddingRight = 13;
// If true, exclude zeros from padding in Average pooling. Meaningless in Max
// Pooling.
bool countExcludePadding = 14;
}
/*
* A layer to pool three spatial dimensions down to one value.
* This behaves like a special case of Pooling3DLayerParams in which
* the Kernel is the size of the input and there is no padding.
*
* Input
* A blob with rank equal to 5, representing [Batch, channels, depth,
* height, width].
*
* Output
* Rank is same as the input: A blob with rank equal to 5, representing
* [Batch, channels, depth, height, width]. Depth, height, and width of the
* output will always be 1.
*
* Requires 1 input and produces 1 output.
*
* For example, given an input of shape (1,1,2,3,3):
* +----+----+----+
* / | 10 | 11 | 12 |
* / +----+----+----+
* / | 13 | 14 | 15 |
* / +----+----+----+
* / | 16 | 17 | 18 |
* / +----+----+----+
* +----+----+----+ /
* | 1 | 2 | 3 | /
* +----+----+----+ /
* | 4 | 5 | 6 | /
* +----+----+----+ /
* | 7 | 8 | 9 | /
* +----+----+----+
*
* And applying MAX global 3d pooling, we expect to get an output with shape:
* (1,1,1,1,1) and value:
* +----+
* | 18 |
* +----+
*/
message GlobalPooling3DLayerParams {
enum GlobalPoolingType3D {
MAX = 0;
AVERAGE = 1;
}
// Whether to use Max or Average
GlobalPoolingType3D type = 1;
}
/*
* A layer that performs padding along spatial dimensions.
*
* .. code::
*
* y = PaddingLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank at least 2.
* e.g.: blob with shape ``[H_in, W_in]``.
* For ranks greater than 2, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch i.e. Padding is applied on last two
* dimensions.
*
* Output
* Same rank as the input.
* e.g.: blob with shape ``[H_out, W_out]``.
*
* Output dimensions are calculated as follows:
*
* .. code::
*
* H_out = H_in + topPaddingAmount + bottomPaddingAmount
* W_out = W_in + leftPaddingAmount + rightPaddingAmount
*
* topPaddingAmount == Height startEdgeSize ==
* borderAmounts[0].startEdgeSize bottomPaddingAmount == Height endEdgeSize ==
* borderAmounts[0].endEdgeSize leftPaddingAmount == Width startEdgeSize ==
* borderAmounts[1].startEdgeSize rightPaddingAmount == Width endEdgeSize ==
* borderAmounts[1].endEdgeSize
*
* There are three types of padding:
*
* - ``PaddingConstant``, which fills a constant value at the border.
* - ``PaddingReflection``, which reflects the values at the border.
* - ``PaddingReplication``, which replicates the values at the border.
*
* Given the following input:
*
* .. code::
*
* [1, 3, 4] : 1 2 3 4
* 5 6 7 8
* 9 10 11 12
*
* Here is the output of applying the padding
* ``(top=2, left=2, bottom=0, right=0)``
* with each of the supported types:
*
* - ``PaddingConstant`` (``value = 0``):
* .. code::
*
* [1, 5, 6] : 0 0 0 0 0 0
* 0 0 0 0 0 0
* 0 0 1 2 3 4
* 0 0 5 6 7 8
* 0 0 9 10 11 12
*
* - ``PaddingReflection``:
* .. code::
*
* [1, 5, 6] : 11 10 9 10 11 12
* 7 6 5 6 7 8
* 3 2 1 2 3 4
* 7 6 5 6 7 8
* 11 10 9 10 11 12
*
* - ``PaddingReplication``:
* .. code::
*
* [1, 5, 6] : 1 1 1 2 3 4
* 1 1 1 2 3 4
* 1 1 1 2 3 4
* 5 5 5 6 7 8
* 9 9 9 10 11 12
*/
message PaddingLayerParams {
/*
* Fill a constant value in the padded region.
*/
message PaddingConstant {
float value = 1;
}
/*
* Reflect the values at the border for padding.
*/
message PaddingReflection {}
/*
* Replicate the values at the border for padding.
*/
message PaddingReplication {}
oneof PaddingType {
PaddingConstant constant = 1;
PaddingReflection reflection = 2;
PaddingReplication replication = 3;
}
BorderAmounts paddingAmounts = 10; // Amounts to be padded to the input.
}
/*
* A layer that concatenates along the axis = -3 or -5.
* For general concatenation along any axis, see ConcatNDLayer.
*
* .. code::
*
* y = ConcatLayer(x1,x2,....)
*
* Requires more than 1 input and produces 1 output.
*
* Input
* All input blobs must have same rank.
* If "sequenceConcat" = False, rank must be greater than equal to 3. In this
* case concatenation is along axis = -3 If "sequenceConcat" = True, rank must
* be greater than equal to 5. In this case concatenation is along axis = -5
*
* Output
* Same rank as the input.
*
*/
message ConcatLayerParams {
/*
* If true, concatenate along the axis = -5 instead of axis = -3.
*/
bool sequenceConcat = 100;
}
/*
* A layer that performs local response normalization (LRN).
*
* .. code::
*
* y = LRNLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank greater than equal to 3.
* Example: Rank 4 blob represents [Batch, channels, height, width]
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch. Output A blob with the same shape as
* the input.
*
* This layer is described by the following formula:
*
* .. math::
* x_i \leftarrow \dfrac{x_i}{\left ( k + \dfrac{\alpha}{\text{localSize}}
* \sum_j x_j^2 \right )^\beta}
*
* where the summation is done over a ``(localSize, 1, 1)`` neighborhood ---
* that is, over a window "across" channels in 1x1 spatial neighborhoods.
*/
message LRNLayerParams {
float alpha = 1;
float beta = 2;
uint64 localSize = 3; // Number of channels in the normalization window.
float k = 4; // Defaults to 1 if not set or 0. Must be strictly positive.
}
/*
* Softmax Normalization Layer
*
* A layer that performs softmax normalization.
* Normalization is applied along axis = -3 or N-3 (where N is the rank of the
* input) For softmax layer that can operate on any axis, see SoftmaxNDLayer.
*
*
* .. code::
*
* y = SoftmaxLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* Must be a blob with rank >= 3.
* Output
* A blob with the same shape as the input.
*
* This layer is described by the following formula:
*
* .. math::
* x_i \leftarrow \dfrac{e^{x_i}}{\sum_i{e^{x_i}}}
*/
message SoftmaxLayerParams {}
/*
* A layer that uniformly splits across axis = -3 to produce a specified number
* of outputs. For general split operation along any axis, see SplitNDLayer.
*
* .. code::
*
* (y1,y2,...yN) = SplitLayer(x), where N = nOutputs
*
* Requires 1 input and produces multiple outputs.
*
* Input
* A blob with rank at least 3.
* e.g.: blob with shape ``[C, H, W]``
* Output
* ``nOutputs`` blobs each with same rank as the input.
* e.g.: For input that is of shape ``[C, H, W]``, output shapes will be
* ``[C/nOutputs, H, W]``
*/
message SplitLayerParams {
uint64 nOutputs = 1; // The number of outputs.
}
/*
* A layer that performs elementwise addition.
* This layer has limited broadcasting support. For general broadcasting see
* AddBroadcastableLayer.
*
* .. code::
*
* y = AddLayer(x1,x2,...)
*
* Requires 1 or more than 1 input and produces 1 output.
*
* Input
* In general, there are no rank constraints.
* However, only certain set of shapes are broadcastable. For example:
* [B, 1, 1, 1], [B, C, 1, 1], [B, 1, H, W], [B, C, H, W]
* Output
* A blob with shape equal to the input blob.
*
* If only one input is provided, scalar addition is performed:
*
* .. math::
* y = x + \alpha
*
*/
message AddLayerParams {
/*
* Scalar to be added to the input.
* Only used if there is a single input.
*/
float alpha = 1;
}
/*
* A layer that performs elementwise multiplication.
* This layer has limited broadcasting support. For general broadcasting see
* MultiplyBroadcastableLayer.
*
* .. code::
*
* y = MultiplyLayer(x1,x2,...)
*
* Requires 1 or more than 1 input and produces 1 output.
*
* Input
* In general, there are no rank constraints.
* However, only certain set of shapes are broadcastable. For example:
* [B, 1, 1, 1], [B, C, 1, 1], [B, 1, H, W], [B, C, H, W]
* Output
* A blob with shape equal to the first input blob.
*
* If only one input is provided, scalar multiplication is performed:
*
* .. math::
* y = \alpha x
*
*/
message MultiplyLayerParams {
/*
* Scalar to be multiplied with the input.
* Only used if there is a single input.
*/
float alpha = 1;
}
/*
* A layer that applies a unary function.
*
* .. code::
*
* y = UnaryFunctionLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with no rank constraints.
* Output
* A blob with the same shape as the input.
*
* The input is first modified by shifting and scaling:
*
* .. math::
* x \leftarrow \text{scale} \cdot x + \text{shift}
*/
message UnaryFunctionLayerParams {
/*
* A unary operator.
*
* The following functions are supported:
*
* ``SQRT``
* .. math:: f(x) = \sqrt{x}
*
* ``RSQRT``
* .. math:: f(x) = \dfrac{1}{\sqrt{x + \epsilon}}
*
* ``INVERSE``
* .. math:: f(x) = \dfrac{1}{x + \epsilon}
*
* ``POWER``
* .. math:: f(x) = x^\alpha
*
* ``EXP``
* .. math:: f(x) = e^x
*
* ``LOG``
* .. math:: f(x) = \log x
*
* ``ABS``
* .. math:: f(x) = |x|
*
* ``THRESHOLD``
* .. math:: f(x) = \text{max}(\alpha, x)
*/
enum Operation {
SQRT = 0;
RSQRT = 1;
INVERSE = 2;
POWER = 3;
EXP = 4;
LOG = 5;
ABS = 6;
THRESHOLD = 7;
}
Operation type = 1; // The type of unary function.
/*
* A constant used in ``POWER`` and ``THRESHOLD`` functions.
*/
float alpha = 2;
/*
* A small constant to avoid division by 0 while normalizing variance.
* Defaults to ``1e-6`` if not set or set to ``0``.
*/
float epsilon = 3;
/*
* Input is shifted by this amount
* before the unary function is applied.
* Defaults to ``0.0`` if not set.
*/
float shift = 4;
/*
* Input is scaled by this amount
* before the unary function is applied.
* Defaults to ``1.0`` if not set or set to ``0``.
*/
float scale = 5;
}
/*
* A layer that scales up spatial dimensions.
* It supports two modes: nearest neighbour (default) and bilinear.
*
* .. code::
*
* y = UpsampleLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank at least 3.
* e.g.: blob with shape ``[C, H, W]``.
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch.
*
* Output
* Same rank as the input.
* e.g.: blob with shape ``[C, scalingFactor[0] * H, scalingFactor[1] * W]``
*/
message UpsampleLayerParams {
/*
* Scaling Factor. Mutually exclusive with fractionalScalingFactor.
* Must be length 2 in order ``[H, W]``.
* If not set, default value ``[1, 1]`` is used.
*/
repeated uint64 scalingFactor = 1;
/*
* Fractional scaling factor. Mutually exclusive with scalingFactor.
* Must be length 2 in order ``[H, W]``.
* If not set, default value ``[1.0, 1.0]`` is used.
*/
repeated float fractionalScalingFactor = 7;
/*
* Overall mode for interpolating new elements when upsampling.
* NN - Nearest Neighbors - simply pick the nearest true value for
* interpolated values. BILINEAR - Use bilinear interpolation. See
* LinearUpsamplingMode for behavior.
*/
enum InterpolationMode {
NN = 0; // Nearest Neighbour
BILINEAR = 1; // Bilinear
}
InterpolationMode mode = 5;
/*
* LinearUpsampleMode specifies the behavior for linear upsampling. Only valid
* when Interpolation Mode is BILINEAR. If input grid is [0, Xin-1]
* (corresponding to an input size of Xin), and if the output size is Xout,
* then the grid points are sampled in the following manner:
* DEFAULT:
* spacing = (Xin-Xin/Xout) / (Xout-1)
* grid_point[i] = min(Xin-1, max(0, i * spacing)), for i = 0,1,2,….,Xout-1
* ALIGN_CORNERS_TRUE:
* spacing = (Xin-1) / (Xout-1)
* grid_point[i] = min(Xin-1, max(0, i * spacing)), for i = 0,1,2,….,Xout-1
* ALIGN_CORNERS_FALSE:
* spacing = Xin / Xout
* grid_point[i] = min(Xin-1, max(0, i * spacing + 0.5 * spacing - 0.5)),
* for i = 0,1,2,….,Xout-1
*/
enum LinearUpsampleMode {
DEFAULT = 0;
ALIGN_CORNERS_TRUE = 1;
ALIGN_CORNERS_FALSE = 2;
}
LinearUpsampleMode linearUpsampleMode = 6;
}
/*
* A layer that resizes the input to a pre-specified spatial size using bilinear
* interpolation.
*
* .. code::
*
* y = ResizeBilinearLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank at least 3.
* e.g.: blob with shape ``[C, H_in, W_in]``.
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch.
*
* Output
* Same rank as the input.
* e.g.: blob with shape ``[C, H_out, W_out]``.
*
*/
message ResizeBilinearLayerParams {
/*
* Target Spatial Size.
* Must be length 2 in order ``[Height, Width]``, i.e. ``[H_out, W_out]``.
* If not set, default value ``[1, 1]`` is used.
*/
repeated uint64 targetSize = 1;
/*
* Mode used to compute the grid on which the spatial output values are
* evaluated. Same mode is applied to both the height and width axes.
*/
SamplingMode mode = 2;
}
/*
* A layer that extracts cropped spatial patches or RoIs (regions of interest)
* from the input and resizes them to a pre-specified size using bilinear
* interpolation. Note that RoI Align layer can be implemented with this layer
* followed by a pooling layer.
*
* .. code::
*
* y = CropResizeLayer(x)
*
* Requires 2 inputs and produces 1 output.
*
* Input
* There are two inputs.
* First input represents an image feature map.
* Second input represents the bounding box coordinates for N patches or
* RoIs (region of interest).
*
* First input is rank 5: [1, Batch, C, H_in, W_in].
* Second input is rank 5. Its shape can be either [N, 1, 4, 1, 1] or [N, 1,
* 5, 1, 1].
*
* N: number of patches/RoIs to be extracted
*
* If RoI shape = ``[N, 1, 4, 1, 1]``
* The axis=-3 corresponds to the four coordinates specifying
* the bounding box. All the N RoIs are extracted from all the batches of the
* input.
*
* If RoI shape = ``[N, 1, 5, 1, 1]``
* The first element of the axis=-3 specifies the input
* batch id from which to extract the RoI and must be in the interval ``[0,
* Batch - 1]``. That is, n-th RoI is extracted from the RoI[n,0,0,0,0]-th input
* batch id. The last four elements of the axis=-3 specify the bounding box
* coordinates.
*
* Output
* A blob with rank 5.
* - Shape is [N, Batch, C, H_out, W_out] if input RoI shape is [N, 1,
* 4, 1, 1]
* - Shape is [N, 1, C, H_out, W_out] if input RoI shape is [N, 1, 5,
* 1, 1]
*
*/
message CropResizeLayerParams {
/*
* Target Spatial Size.
* Must be length 2 in order ``[Height, Width]``, i.e. ``[H_out, W_out]``.
* If not set, default value ``[1, 1]`` is used.
*/
repeated uint64 targetSize = 1;
/*
* If true the bounding box coordinates must be in the interval [0, 1].
* They are scaled by (H_in - 1), (W_in - 1), i.e. based on the input spatial
* dimensions. If false the bounding box coordinates must be in the interval
* [0, H_in -1] and [0, W_in - 1], respectively for height and width
* dimensions.
*/
bool normalizedCoordinates = 2;
/*
* Mode used to compute the grid on which the spatial output values are
* evaluated. Same mode is applied to both the height and width axes.
*/
SamplingMode mode = 3;
/*
* Representation used to express the bounding box coordinates.
* It determines how the values of the second input are interpreted.
*/
BoxCoordinatesMode boxIndicesMode = 4;
/*
* Additional spatial scale that multiplies the bounding box coordinates.
* Generally used while implementing the RoI Align layer,
* which uses unnormalized RoI coordinates along with a spatial scale less
* than or equal to 1.
*/
float spatialScale = 5;
}
/*
* A layer that performs elementwise addition of a bias,
* which is broadcasted to match the input shape.
*
* .. code::
*
* y = BiasLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank at least 3.
* e.g.: blob with shape ``[C, H, W]``.
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch. Output A blob with the same shape as
* the input.
*/
message BiasLayerParams {
/*
* The shape of the bias.
* Must be one of the following:
* ``[1]``, ``[C]``, ``[1, H, W]`` or ``[C, H, W]``.
*/
repeated uint64 shape = 1;
/*
* The bias values.
* The size must be equal to the product of the ``shape`` dimensions.
*/
WeightParams bias = 2;
}
/*
* A layer that performs elmentwise multiplication by a scale factor
* and optionally adds a bias;
* both the scale and bias are broadcasted to match the input shape.
*
* .. code::
*
* y = ScaleLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank at least 3.
* e.g.: blob with shape ``[C, H, W]``.
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch. Output A blob with the same shape as
* the input.
*/
message ScaleLayerParams {
/*
* The shape of the scale.
* Must be one of the following:
* ``[1]``, ``[C]``, ``[1, H, W]`` or ``[C, H, W]``.
*/
repeated uint64 shapeScale = 1;
/*
* The scale values.
* The size must be equal to the product of the ``shape`` dimensions.
*/
WeightParams scale = 2; // Scale values. Size must be equal to the product of
// dimensions specified in shapeScale.
bool hasBias = 3; // If true, a bias is added after scaling.
/*
* The shape of the bias.
* Must be one of the following:
* ``[1]``, ``[C]``, ``[1, H, W]`` or ``[C, H, W]``.
*/
repeated uint64 shapeBias = 4;
/*
* The bias values.
* The size must be equal to the product of the ``shape`` dimensions.
*/
WeightParams bias = 5;
}
/*
* A layer that loads data as a parameter and provides it as an output.
* The output is rank 5. For general rank, see LoadConstantNDLayer.
*
* .. code::
*
* y = LoadConstantLayer()
*
* Requires no input and produces 1 output.
*
* Output:
* A blob with rank 5 and shape ``[1, 1, C, H, W]``
*/
message LoadConstantLayerParams {
/*
* The shape of the constant to be loaded,
* which must be``[C, H, W]``, that is length 3.
*/
repeated uint64 shape = 1;
/*
* The data values,
* of size ``C * H * W``.
*/
WeightParams data = 2;
}
/*
* A layer that performs L2 normalization, i.e. divides by the
* the square root of the sum of squares of all elements of input.
*
* .. code::
*
* y = L2NormalizeLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank greater than equal to 3.
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch. Output A blob with the same shape as
* the input.
*
* This layer is described by the following formula:
*
* .. math::
* x_i \leftarrow \dfrac{x_i}{\sqrt{\sum{x_i^2} + \epsilon}}
*/
message L2NormalizeLayerParams {
/*
* A small constant to avoid division by 0 while normalizing variance.
* Defaults to ``1e-6`` if not set or set to ``0``.
*/
float epsilon = 1;
}
// Data Reorganization Layers
// --------------------------
/*
* A layer that flattens the input.
*
* .. code::
*
* y = FlattenLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank greater than equal to 3.
* e.g.: Rank 4 blob represents [Batch, C, H, W]
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch. Output Same rank as the input, such
* that last two dimensions are both 1. e.g.: For rank 4 input, output shape is
* ``[Batch, C * H * W, 1, 1]``
*
* There are two X orders: ``CHANNEL_FIRST`` and ``CHANNEL_LAST``.
* ``CHANNEL_FIRST`` does not require data to be rearranged,
* because row major ordering is used by internal storage.
* ``CHANNEL_LAST`` requires data to be rearranged.
*/
message FlattenLayerParams {
enum FlattenOrder {
CHANNEL_FIRST = 0;
CHANNEL_LAST = 1;
}
FlattenOrder mode = 1;
}
/*
* A layer that recasts the input into a new shape.
*
* .. code::
*
* y = ReshapeLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank 5.
* e.g.: ``[1, 1, C, H, W]`` or ``[Seq, 1, C, H, W]``.
* Output
* A blob with rank 5.
* e.g.: ``[1, 1, C_out, H_out, W_out]`` or ``[Seq_out, 1, C_out, H_out,
* W_out]``.
*
* There are two reshape orders: ``CHANNEL_FIRST`` and ``CHANNEL_LAST``.
* ``CHANNEL_FIRST`` is equivalent to
* flattening the input to ``[Seq, 1, C * H * W, 1, 1]`` in channel first order
* and then reshaping it to the target shape;
* no data rearrangement is required.
* ``CHANNEL_LAST`` is equivalent to
* flattening the input to ``[Seq, 1, H * W * C, 1, 1]`` in channel last order,
* reshaping it to ``[Seq_out, 1, H_out, W_out, C_out]`` (it is now in
* "H_out-major"" order), and then permuting it to ``[C_out, H_out, W_out]``;
* both the flattening and permuting requires the data to be rearranged.
*/
message ReshapeLayerParams {
/*
* The shape of the output.
* Must be of length 3 or 4.
* If set to 3, ``targetShape`` is interpreted as
* ``[1, 1, C_out, H_out, W_out]``, and sequence length of the input is
* preserved. If set to 4, ``targetShape`` is interpreted as
* ``[Seq_out, 1, C_out, H_out, W_out]``,
* where ``Seq_out`` is the new sequence length.
*/
repeated int64 targetShape = 1;
enum ReshapeOrder {
CHANNEL_FIRST = 0;
CHANNEL_LAST = 1;
}
ReshapeOrder mode = 2;
}
/*
* A layer that rearranges the dimensions and data of an input.
* For generic transpose/permute operation see TransposeLayer.
*
* .. code::
*
* y = PermuteLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* Must be a rank 5 blob.
* e.g.: shape ``[Seq, B, C, H, W]``.
* Output
* Rank 5 blob. Transposed version of the input, such that dimensions at
* axis=1 or axis=-4 is unchanged.
*
*
* Examples:
*
* Assume input shape is [Seq, B, C, H, W]
*
* - If ``axis`` is set to ``[0, 3, 1, 2]``,
* then the output has shape ``[Seq, B, W, C, H]``
*
* - If ``axis`` is set to ``[3, 1, 2, 0]``,
* then the output has shape ``[W, B, C, H, Seq]``
*
* - If ``axis`` is set to ``[0, 3, 2, 1]``,
* then the output has shape ``[Seq, B, W, H, C]``
*
* - If ``axis`` is not set, or is set to ``[0, 1, 2, 3]``,
* the output is the same as the input.
*/
message PermuteLayerParams {
/*
* The order in which to permute the dimensions.
* Must have length 4 and a permutation of ``[0, 1, 2, 3]``.
*/
repeated uint64 axis = 1;
}
/*
* A layer that reorganizes data in the input in specific ways.
*
* .. code::
*
* y = ReorganizeDataLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank at least 3.
* e.g.: blob with shape ``[C, H, W]``.
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch. Output Same rank as the input. e.g.:
* blob with shape ``[C_out, H_out, W_out]``.
*
* mode == SPACE_TO_DEPTH
* ``[C_out, H_out, W_out]`` : ``[C * blockSize * blockSize, H/blockSize,
* W/blockSize]``. blockSize must divide H and W. Data is moved from the spatial
* dimensions to the channel dimension. Input is spatially divided into
* non-overlapping blocks of size blockSize X blockSize and data from each
* block is moved into the channel dimension.
*
* mode == DEPTH_TO_SPACE
* ``[C_out, H_out, W_out]`` : ``[C/(blockSize * blockSize), H * blockSize, W *
* blockSize]``. Square of blockSize must divide C. Reverse of SPACE_TO_DEPTH.
* Data is moved from the channel dimension to the spatial dimensions.
*
* mode == PIXEL_SHUFFLE
* ``[C_out, H_out, W_out]`` : ``[C/(blockSize * blockSize), H * blockSize, W *
* blockSize]``. Square of blockSize must divide C. Similar to DEPTH_TO_SPACE,
* but using the pixel-shuffle semantics for channel order in the output space.
* In both modes, elements along the channel dimension are collapsed into
* blocks in the spatial dimensions. The difference is in the arrangement of
* the input-channels' data in the output space. See below example for more
* detail.
* (Only available in Core ML Specification >= 5 (iOS >= 14, macOS >= 11.0)
*
*
* Examples:
*
* Assume input is the following [C = 8, H = 1, W = 2] tensor:
*
* .. code::
*
* [[[1 2]] [[3 4]] [[5 6]] [[7 8]] [[9 10]] [[11 12]] [[13 14]] [[15 16]]]
*
* If block_size == 2 and mode == DEPTH_TO_SPACE, output will be the following
* [C = 2, H = 2, W = 4] tensor:
*
* .. code::
*
* [[[ 1 5 2 6]
* [ 9 13 10 14]]
*
* [[ 3 7 4 8]
* [11 15 12 16]]]
*
* For mode == SPACE_TO_DEPTH, the behavior is the same as mode ==
* DEPTH_TO_SPACE, but with the input and output swapped.
*
* If block_size == 2 and mode == PIXEL_SHUFFLE, output will be the following
* [C = 2, H = 2, W = 4] tensor:
*
* .. code::
*
* [[[ 1 3 2 4]
* [ 5 7 6 8]]
*
* [[ 9 11 10 12]
* [13 15 14 16]]]
*
*/
message ReorganizeDataLayerParams {
enum ReorganizationType {
SPACE_TO_DEPTH = 0;
DEPTH_TO_SPACE = 1;
PIXEL_SHUFFLE = 2;
}
ReorganizationType mode = 1;
uint64 blockSize = 2; // must be greater than 1
}
/*
* A layer that slices the input data along axis = -1 or -2 or -3.
* For general slice along any axis, please see
* SliceStaticLayer/SliceDynamicLayer.
*
* .. code::
*
* y = SliceLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob that can, in general, have any rank. However, depending on the
* value of "axis" , there may be additional rank constraints. Output A blob
* with the same rank as the input.
*
* Sliced section is taken from the interval ``[startIndex, endIndex)``, i.e.
* startIndex is inclusive while endIndex is exclusive.
* stride must be positive and represents the step size for slicing.
* Negative indexing is supported for startIndex and endIndex.
* -1 denotes N-1, -2 denotes N-2 and so on, where N is the length of the
* dimension to be sliced.
*
*/
message SliceLayerParams {
int64 startIndex = 1; // start of the sliced section. Inclusive.
int64 endIndex = 2; // end of sliced section. Exclusive.
uint64 stride = 3; // The step size. Must be positive.
enum SliceAxis {
CHANNEL_AXIS = 0;
HEIGHT_AXIS = 1;
WIDTH_AXIS = 2;
}
// The following mapping is used for interpreting this parameter:
// CHANNEL_AXIS => axis = -3, input must have rank at least 3.
// HEIGHT_AXIS => axis = -2, input must have rank at least 2.
// WIDTH_AXIS => axis = -1
SliceAxis axis = 4;
}
/*
* A layer that reduces the input using a specified operation.
*
* .. code::
*
* y = ReduceLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob that can, in general, have any rank. However, depending on the
* value of "axis" , there may be additional rank constraints. Output A blob
* with the same rank as the input, which has 1s on the dimensions specified in
* the parameter "axis"
*
* Values supported for axis are [-1], [-2], [-3], [-2,-1], [-3,-2,-1]
* and the equivalent positive values (depending on the rank of the input)
* For mode == 'ArgMax', axis must be [-1] or [-2] or [-3].
*/
message ReduceLayerParams {
/*
* The following reduction operations are supported
* and are applied on the specified axis of the input array:
*
* ``SUM``
* Sum of all elements
*
* .. math:: \sum{x_i}
*
* ``AVG``
* Sum of all elements divided by the number of elements
*
* .. math:: \dfrac{\sum^n{x_i}}{n}
*
* ``PROD``
* Product of all elements
*
* .. math:: \prod{x_i}
*
* ``LOGSUM``
* Sum of the natural logarithm of all elements
*
* .. math:: \sum{\ln{(x_i + \epsilon)}}
*
* ``SUMSQUARE``
* Sum of squares of all elements
*
* .. math:: \sum{x^2}
*
* ``L1``
* L1 normalization of all elements
*
* .. math:: ||x||_1 = \sum{|x_i|}
*
* ``L2``
* L2 normalization of all elements
*
* .. math:: ||x||_2 = \sqrt{\sum{x_i^2}}
*
* ``MAX``
* Maximum of all elements
*
* .. math:: \text{max}(x_i)
*
* ``MIN``
* Minimum of all elements
*
* .. math:: \text{min}(x_i)
*
* ``ARGMAX``
* Argument of the maximum of all elements
*
* .. math:: \text{argmax}(x_i)
*
*/
enum ReduceOperation {
SUM = 0;
AVG = 1;
PROD = 2;
LOGSUM = 3;
SUMSQUARE = 4;
L1 = 5;
L2 = 6;
MAX = 7;
MIN = 8;
ARGMAX = 9; // only supported with axis = C, H or W.
}
ReduceOperation mode = 1; // Specifies function used to reduce.
/*
* Used if mode is ``LOGSUM``.
* Defaults to ``1e-6`` if not set or is set to ``0``.
*/
float epsilon = 2;
enum ReduceAxis {
CHW = 0;
HW = 1;
C = 2;
H = 3;
W = 4;
}
// The following mapping is used for interpreting this parameter:
// CHW = axis [-3, -2, -1], input must have rank at least 3.
// HW = axis [-2, -1], input must have rank at least 2.
// C = axis [-3]
// H = axis [-2]
// W = axis [-1]
ReduceAxis axis = 3;
}
/*
* A layer that crops the spatial dimensions of an input.
* If two inputs are provided, the shape of the second input is used as the
* reference shape.
*
* .. code::
*
* y = CropLayer(x1) or y = CropLayer(x1,x2)
*
* Requires 1 or 2 inputs and produces 1 output.
*
* Input
* 1 or 2 tensors, each with rank at least 3, both inputs must have equal
* rank. Example:
* - 1 input case: A blob with shape ``[C, H_in, W_in]``.
* - 2 input case: 1st blob with shape ``[C, H_in, W_in]``, 2nd blob with
* shape ``[C, H_out, W_out]``.
*
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch.
*
* Output
* Same rank as the inputs.
* e.g.: A blob with shape ``[C, H_out, W_out]``.
*
* If one input is used, output is computed as follows:
*
* .. code::
*
* y = x1[:, topCropAmount:H_in - bottomCropAmount, leftCropAmount:W_in -
* rightCropAmount]
*
* topCropAmount == Height startEdgeSize == borderAmounts[0].startEdgeSize
* bottomCropAmount == Height endEdgeSize == borderAmounts[0].endEdgeSize
* leftCropAmount == Width startEdgeSize == borderAmounts[1].startEdgeSize
* rightCropAmount == Width endEdgeSize == borderAmounts[1].endEdgeSize
*
* H_out = H_in - topCropAmount - bottomCropAmount
* W_out = W_in - leftCropAmount - rightCropAmount
*
* If two inputs are used, output is computed as follows:
*
* .. code::
*
* y = x1[:, offset[0]:offset[0] + H_out, offset[1]:offset[1] + W_out]
*/
message CropLayerParams {
/*
* The amounts to be cropped from the input.
* Used only if a single input is provided.
*/
BorderAmounts cropAmounts = 1;
/*
* The offset amounts.
* Used only if two inputs are provided.
* Must be of length 2, in order ``[H, W]``.
*/
repeated uint64 offset = 5;
}
/*
* A layer that computes the elementwise average of the inputs.
* This layer has limited broadcasting support. For general broadcasting see
* AddBroadcastableLayer.
*
* .. code::
*
* y = AverageLayer(x1,x2,...)
*
* Requires multiple inputs and produces 1 output.
*
* Input
* In general, there are no rank constraints.
* However, only certain set of shapes are broadcastable. For example:
* [B, 1, 1, 1], [B, C, 1, 1], [B, 1, H, W], [B, C, H, W]
* Output
* A blob with the same shape as each input.
*/
message AverageLayerParams {}
/*
* A layer that computes the elementwise maximum over the inputs.
*
* .. code::
*
* y = MaxLayer(x1,x2,...)
*
* Requires multiple inputs and produces 1 output.
*
* Input
* In general, there are no rank constraints.
* However, only certain set of shapes are broadcastable. For example:
* [B, C, 1, 1], [B, C, H, W]
* Output
* A blob with the same shape as each input.
*/
message MaxLayerParams {}
/*
* A layer that computes the elementwise minimum over the inputs.
*
* .. code::
*
* y = MinLayer(x1,x2,...)
*
* Requires multiple inputs and produces 1 output.
*
* Input
* In general, there are no rank constraints.
* However, only certain set of shapes are broadcastable. For example:
* [B, C, 1, 1], [B, C, H, W]
* Output
* A blob with the same shape as each input.
*/
message MinLayerParams {}
/*
* A layer that computes the dot product of two vectors.
*
* .. code::
*
* y = DotProductLayer(x1,x2)
*
* Requires 2 inputs and produces 1 output.
*
* Input
* Two blobs with rank at least 3, such that the last two dimensions must
* be 1. e.g.: blobs with shape ``[B, C, 1, 1]``. For ranks greater than 3, the
* leading dimensions, starting from 0 to -4 (inclusive), are all treated as
* batch.
*
* Output
* Same rank as the input.
* e.g. for rank 4 inputs, output shape: [B, 1, 1, 1]
*/
message DotProductLayerParams {
/*
* If true, inputs are normalized first,
* thereby computing the cosine similarity.
*/
bool cosineSimilarity = 1;
}
/*
* A layer that performs mean variance normalization, along axis = -3.
*
* .. code::
*
* y = MeanVarianceNormalizeLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank greater than equal to 3.
* Example: Rank 4 blob represents [Batch, channels, height, width]
* For ranks greater than 3, the leading dimensions, starting from 0 to -4
* (inclusive), are all treated as batch.
*
* Output
* A blob with the same shape as the input.
*
* If ``acrossChannels == true``
* normalization is performed on flattened input, i.e. the input is reshaped to
* (Batch,C), where "Batch" contains all dimensions from 0 to -4 (inclusive),
* and C contains dimensions -1, -2, -3.
*
* If ``acrossChannels == false``
* normalization is performed within a channel,
* across spatial dimensions (i.e. last two dimensions).
*/
message MeanVarianceNormalizeLayerParams {
/*
* If true, mean and variance are computed across channels.
*/
bool acrossChannels = 1;
/*
* If false, only mean is subtracted.
*/
bool normalizeVariance = 2;
/*
* A small constant to avoid division by 0 while normalizing variance.
* Defaults to ``1e-6`` if not set or set to ``0``.
*/
float epsilon = 3;
}
/*
* A layer that repeats a sequence or the dimension sitting at axis = -5
*
* .. code::
*
* y = SequenceRepeatLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with rank at least 5.
* e.g: shape ``[Seq, B, C, H, W]``
* Output
* A blob with the same rank as the input.
* e.g.: for input shape ``[Seq, B, C, H, W]``, output shape is
* ``[nRepetitions * Seq, B, C, H, W]``.
*/
message SequenceRepeatLayerParams {
/*
* Number of repetitions.
* Defaults to ``1`` if not set or set to ``0``.
*/
uint64 nRepetitions = 1;
}
// Recurrent Layers
// ----------------
/*
* The following activations are supported with recurrent layers:
* - Linear
* - Sigmoid
* - Tanh
* - ReLU
* - Scaled Hyperbolic Tangent: alpha * tanh(beta * x), currently only supported
* for alpha = 1.7159, beta = 2/3
* - Hard Sigmoid: min(max(alpha * x + beta, 0), 1), currently only supported
* for alpha = 0.2, beta = 0.5
*/
/*
* A simple recurrent layer.
*
* .. code::
*
* y_t = SimpleRecurrentLayer(x_t, y_{t-1})
*
* Input
* A blob of rank 5, with shape `[Seq, Batch, inputVectorSize, 1, 1]``.
* This represents a sequence of vectors of size ``inputVectorSize``.
* Output
* Same rank as the input.
* Represents a vector of size ``outputVectorSize``. It is either the final
* output or a sequence of outputs at all time steps.
*
* - Output Shape: ``[1, Batch, outputVectorSize, 1, 1]`` , if ``sequenceOutput
* == false``
* - Output Shape: ``[Seq, Batch, outputVectorSize, 1, 1]`` , if
* ``sequenceOutput == true``
*
* This layer is described by the following equation:
*
* .. math::
* \boldsymbol{y_t} = f(\mathrm{clip}(W \boldsymbol{x_t} + \
* R \boldsymbol{y_{t-1}} + b))
*
* - ``W`` is a 2-dimensional weight matrix
* (``[outputVectorSize, inputVectorSize]``, row-major)
* - ``R`` is a 2-dimensional recursion matrix
* (``[outputVectorSize, outputVectorSize]``, row-major)
* - ``b`` is a 1-dimensional bias vector (``[outputVectorSize]``)
* - ``f()`` is an activation
* - ``clip()`` is a function that constrains values between ``[-50.0, 50.0]``
*/
message SimpleRecurrentLayerParams {
uint64 inputVectorSize = 1; // The size of the input vectors.
uint64 outputVectorSize = 2; // The size of the output vectors.
/*
* Activations supported are Linear, Sigmoid, Tanh, ReLU, Scaled Tanh (alpha
* = 1.71, beta = 2/3), Hard sigmoid (alpha = 0.2, beta = 0.5)
*/
ActivationParams activation = 10; // The activation function.
/*
If false output is just the result after final state update.
If true, output is a sequence, containing outputs at all time steps.
*/
bool sequenceOutput = 15;
bool hasBiasVector = 20; // If false, no bias is added.
WeightParams weightMatrix = 30; // Weight matrix W.
WeightParams recursionMatrix = 31; // Recursion Weight matrix R.
WeightParams biasVector = 32; // Bias vector b.
bool reverseInput = 100;
// If true, then the node processes the input sequence from right to left
}
/*
* Gated-Recurrent Unit (GRU) Layer
*
* .. code::
*
* y_t = GRULayer(x_t, y_{t-1})
*
* Input
* A blob of rank 5, with shape `[Seq, Batch, inputVectorSize, 1, 1]``.
* This represents a sequence of vectors of size ``inputVectorSize``.
* Output
* Same rank as the input.
* Represents a vector of size ``outputVectorSize``. It is either the final
* output or a sequence of outputs at all time steps.
*
* - Output Shape: ``[1, Batch, outputVectorSize, 1, 1]`` , if ``sequenceOutput
* == false``
* - Output Shape: ``[Seq, Batch, outputVectorSize, 1, 1]`` , if
* ``sequenceOutput == true``
*
* This layer is described by the following equations:
*
* Update Gate
* .. math::
* \boldsymbol{z_t} = \
* f(\mathrm{clip}(W_z \boldsymbol{x_t} + \
* R_z \boldsymbol{y_{t-1}} + b_z)
*
* Reset Gate
* .. math::
* \boldsymbol{r_t} = \
* f(\mathrm{clip}(W_r \boldsymbol{x_t} + \
* R_r \boldsymbol{y_{t-1}} + b_r))
*
* Cell Memory State
* .. math::
* \boldsymbol{c_t} = \
* \boldsymbol{y_{t-1}} \odot \boldsymbol{r_t}
*
* Output Gate
* .. math::
* \boldsymbol{o_t} = \
* g(\mathrm{clip}(W_o \boldsymbol{x_t} + \
* R_o \boldsymbol{c_t} + b_o))
*
* Output
* .. math::
* \boldsymbol{y_t} = \
* (1 - \boldsymbol{z_t}) \odot \boldsymbol{o_t} + \
* \boldsymbol{z_t} \odot \boldsymbol{y_{t-1}}
*
* - ``W_z``, ``W_r``, ``W_o`` are 2-dimensional input weight matrices
* (``[outputVectorSize, inputVectorSize]``, row-major)
* - ``R_z``, ``R_r``, ``R_o`` are 2-dimensional recursion matrices
* (``[outputVectorSize, outputVectorSize]``, row-major)
* - ``b_z``, ``b_r``, ``b_o`` are 1-dimensional bias vectors
* (``[outputVectorSize]``)
* - ``f()``, ``g()`` are activations
* - ``clip()`` is a function that constrains values between ``[-50.0, 50.0]``
* - ``⊙`` denotes the elementwise product of matrices
*/
message GRULayerParams {
uint64 inputVectorSize = 1; // Size of the input vectors.
uint64 outputVectorSize = 2; // Size of the output vectors.
/*
* 2 element array representing activations [f(), g()] in that order.
* Typical values used = [sigmoid, tanh].
* Activations supported are Linear, Sigmoid, Tanh, ReLU, Scaled Tanh (alpha
* = 1.71, beta = 2/3), Hard sigmoid (alpha = 0.2, beta = 0.5)
*/
repeated ActivationParams activations = 10;
/*
* If false output is just the result after final state update.
* If true, output is a sequence, containing outputs at all time steps.
*/
bool sequenceOutput = 15;
/*
* If false, no biases (``b_z``, ``b_r``, ``b_o``) are added.
*/
bool hasBiasVectors = 20;
WeightParams updateGateWeightMatrix = 30; // Weight Matrix W_z.
WeightParams resetGateWeightMatrix = 31; // Weight Matrix W_r.
WeightParams outputGateWeightMatrix = 32; // Weight Matrix W_o.
WeightParams updateGateRecursionMatrix = 50; // Recursion Weight Matrix R_z.
WeightParams resetGateRecursionMatrix = 51; // Recursion Weight Matrix R_r.
WeightParams outputGateRecursionMatrix = 52; // Recursion Weight Matrix R_o.
WeightParams updateGateBiasVector = 70; // Bias vector b_z.
WeightParams resetGateBiasVector = 71; // Bias vector b_r.
WeightParams outputGateBiasVector = 72; // Bias vector b_o.
// If true, then the node processes the input sequence from right to left
bool reverseInput = 100;
}
/*
* Long short-term memory (LSTM) parameters.
*
* This is described by the following equations:
*
* Input Gate
* .. math::
* \boldsymbol{i_t} = \
* f(\mathrm{clip}(W_i \boldsymbol{x_t} + \
* R_i \boldsymbol{y_{t-1}} + \
* p_i \odot c_{t-1} + b_i))
*
* Forget Gate
* .. math::
* \boldsymbol{f_t} = \
* f(\mathrm{clip}(W_f \boldsymbol{x_t} + \
* R_f \boldsymbol{y_{t-1}} + \
* p_f \odot c_{t-1} + b_f))
*
* Block Input
* .. math::
* \boldsymbol{z_t} = \
* g(\mathrm{clip}(W_z \boldsymbol{x_t} + \
* R_z \boldsymbol{y_{t-1}} + b_z))
*
* Cell Memory State
* .. math::
* \boldsymbol{c_t} = \
* \boldsymbol{c_{t-1}} \odot \boldsymbol{f_t} + \
* \boldsymbol{i_t} \odot \boldsymbol{z_t}
*
* Output Gate
* .. math::
* \boldsymbol{o_t} = \
* f(\mathrm{clip}(W_o \boldsymbol{x_t} + \
* R_o \boldsymbol{y_{t-1}} + \
* p_o \odot c_t + b_o))
*
* Output
* .. math::
* \boldsymbol{y_t} = \
* h(\boldsymbol{c_t}) \odot \boldsymbol{o_t}
*
* - ``W_i``, ``W_f``, ``W_z``, ``W_o`` are 2-dimensional input weight matrices
* (``[outputVectorSize, inputVectorSize]``, row-major)
* - ``R_i``, ``R_f``, ``R_z``, ``R_o`` are 2-dimensional recursion matrices
* (``[outputVectorSize, outputVectorSize]``, row-major)
* - ``b_i``, ``b_f``, ``b_z``, ``b_o`` are 1-dimensional bias vectors
* (``[outputVectorSize]``)
* - ``p_``, ``p_f``, ``p_o`` are 1-dimensional peephole vectors
* (``[outputVectorSize]``)
* - ``f()``, ``g()``, ``h()`` are activations
* - ``clip()`` is a function that constrains values between ``[-50.0, 50.0]``
* - ``⊙`` denotes the elementwise product of matrices
*/
message LSTMParams {
/*
* If true, output is a sequence, containing outputs at all time steps.
* If false, output is just the result after final state update.
*/
bool sequenceOutput = 10;
/*
* If false, no biases (``b_i``, ``b_f``, ``b_z``, ``b_o``) are added.
*/
bool hasBiasVectors = 20;
/*
* If true, a vector of ``1`` values is added to ``b_f``.
*/
bool forgetBias = 30;
/*
* If true, peephole vectors are included.
*/
bool hasPeepholeVectors = 40;
/*
* If the coupled Input and Forget flag is on, the behaviour of
* ``c_t`` is changed to the following (i.e. forget gate is not used):
*
* .. math::
* \boldsymbol{c_t} = \
* \boldsymbol{c_{t-1}} \odot (1 - \boldsymbol{i_t}) + \
* \boldsymbol{i_t} \odot \boldsymbol{z_t}
*
*/
bool coupledInputAndForgetGate = 50;
/*
* Places a limit on the maximum and minimum values of ``c_t``.
* c_t = min(c_t, cellClipThreshold)
* c_t = max(c_t, -cellClipThreshold)
* If 0, it is set to its default value = 50.0.
*/
float cellClipThreshold = 60;
}
/*
* Weights for long short-term memory (LSTM) layers
*/
message LSTMWeightParams {
WeightParams inputGateWeightMatrix = 1; // Weight Matrix W_i.
WeightParams forgetGateWeightMatrix = 2; // Weight Matrix W_f.
WeightParams blockInputWeightMatrix = 3; // Weight Matrix W_z.
WeightParams outputGateWeightMatrix = 4; // Weight Matrix W_o.
WeightParams inputGateRecursionMatrix = 20; // Recursion Weight Matrix R_i.
WeightParams forgetGateRecursionMatrix = 21; // Recursion Weight Matrix R_f.
WeightParams blockInputRecursionMatrix = 22; // Recursion Weight Matrix R_z.
WeightParams outputGateRecursionMatrix = 23; // Recursion Weight Matrix R_o.
// biases:
WeightParams inputGateBiasVector = 40; // Bias vector b_i.
WeightParams forgetGateBiasVector = 41; // Bias vector b_f.
WeightParams blockInputBiasVector = 42; // Bias vector b_z.
WeightParams outputGateBiasVector = 43; // Bias vector b_o.
// peepholes:
WeightParams inputGatePeepholeVector = 60; // Peephole vector p_i.
WeightParams forgetGatePeepholeVector = 61; // Peephole vector p_f.
WeightParams outputGatePeepholeVector = 62; // Peephole vector p_o.
}
/*
* A unidirectional long short-term memory (LSTM) layer.
*
* .. code::
*
* (y_t, c_t) = UniDirectionalLSTMLayer(x_t, y_{t-1}, c_{t-1})
*
* Input
* A blob of rank 5, with shape `[Seq, Batch, inputVectorSize, 1, 1]``.
* This represents a sequence of vectors of size ``inputVectorSize``.
* Output
* Same rank as the input.
* Represents a vector of size ``outputVectorSize``. It is either the final
* output or a sequence of outputs at all time steps.
*
* - Output Shape: ``[1, Batch, outputVectorSize, 1, 1]`` , if ``sequenceOutput
* == false``
* - Output Shape: ``[Seq, Batch, outputVectorSize, 1, 1]`` , if
* ``sequenceOutput == true``
*
*/
message UniDirectionalLSTMLayerParams {
uint64 inputVectorSize = 1; // Size of the input vectors.
uint64 outputVectorSize = 2; // Size of the output vectors.
/*
* 3 element array representing activations [f(),g(),h()] in that order.
* Typical values used = [sigmoid, tanh, tanh].
* Activations supported are Linear, Sigmoid, Tanh, ReLU, Scaled Tanh (alpha
* = 1.71, beta = 2/3), Hard sigmoid (alpha = 0.2, beta = 0.5)
*/
repeated ActivationParams activations = 10;
LSTMParams params = 15;
LSTMWeightParams weightParams = 20; // Weights, biases and peepholes.
// If true, then the node processes the input sequence from right to left
bool reverseInput = 100;
}
/*
* Bidirectional long short-term memory (LSTM) layer
*
* .. code::
*
* (y_t, c_t, y_t_reverse, c_t_reverse) = BiDirectionalLSTMLayer(x_t,
* y_{t-1}, c_{t-1}, y_{t-1}_reverse, c_{t-1}_reverse)
*
* Input
* A blob of rank 5, with shape `[Seq, Batch, inputVectorSize, 1, 1]``.
* This represents a sequence of vectors of size ``inputVectorSize``.
* Output
* Same rank as the input.
* Represents a vector of size ``2 * outputVectorSize``. It is either the
* final output or a sequence of outputs at all time steps.
*
* - Output Shape: ``[1, Batch, 2 * outputVectorSize, 1, 1]`` , if
* ``sequenceOutput == false``
* - Output Shape: ``[Seq, Batch, 2 * outputVectorSize, 1, 1]`` , if
* ``sequenceOutput == true``
*
*
* The first LSTM operates on the input sequence in the forward direction.
* The second LSTM operates on the input sequence in the reverse direction.
*
* Example: given the input sequence ``[x_1, x_2, x_3]``,
* where ``x_i`` are vectors at time index ``i``:
*
* The forward LSTM output is ``[yf_1, yf_2, yf_3]``,
*
* where ``yf_i`` are vectors of size ``outputVectorSize``:
*
* - ``yf_1`` is the output at the end of sequence {``x_1``}
* - ``yf_2`` is the output at the end of sequence {``x_1``, ``x_2``}
* - ``yf_3`` is the output at the end of sequence {``x_1``, ``x_2``, ``x_3``}
*
* The backward LSTM output: ``[yb_1, yb_2, yb_3]``,
*
* where ``yb_i`` are vectors of size ``outputVectorSize``:
*
* - ``yb_1`` is the output at the end of sequence {``x_3``}
* - ``yb_2`` is the output at the end of sequence {``x_3``, ``x_2``}
* - ``yb_3`` is the output at the end of sequence {``x_3``, ``x_2``, ``x_1``}
*
* Output of the bi-dir layer:
*
* - if ``sequenceOutput = True`` : { ``[yf_1, yb_3]``, ``[yf_2, yb_2]``,
* ``[yf_3, yb_1]`` }
* - if ``sequenceOutput = False`` : { ``[yf_3, yb_3]`` }
*/
message BiDirectionalLSTMLayerParams {
/*
* Size of the input vectors.
*/
uint64 inputVectorSize = 1;
/*
* Size of the outputs vectors.
* It is same for both forward and backward LSTMs.
*/
uint64 outputVectorSize = 2;
/*
* 3 element array representing activations [f(),g(),h()] in that order.
* Typical values used = [sigmoid, tanh, tanh].
* Activations supported are Linear, Sigmoid, Tanh, ReLU, Scaled Tanh (alpha
* = 1.71, beta = 2/3), Hard sigmoid (alpha = 0.2, beta = 0.5)
*/
repeated ActivationParams activationsForwardLSTM = 10;
/*
* Currently, backward LSTM activations
* must be same as the ones for the forward LSTM.
*/
repeated ActivationParams activationsBackwardLSTM = 11;
/*
* Common parameters shared by the forward and backward LSTMs.
*/
LSTMParams params = 15;
/*
* Weights and biases.
* Must be a length 2 message,
* for the forward and backward LSTM respectively.
*/
repeated LSTMWeightParams weightParams = 20;
}
message CustomLayerParams {
message CustomLayerParamValue {
oneof value {
double doubleValue = 10;
string stringValue = 20;
int32 intValue = 30;
int64 longValue = 40;
bool boolValue = 50;
}
}
string className = 10; // The name of the class (conforming to MLCustomLayer)
// corresponding to this layer
repeated WeightParams weights = 20; // Any weights -- these are serialized in
// binary format and memmapped at runtime
map<string, CustomLayerParamValue> parameters =
30; // these may be handled as strings, so this should not be large
string description =
40; // An (optional) description of the layer provided by the model
// creator. This information is displayed when viewing the model, but
// does not affect the model's execution on device.
}
/*
* A layer that rearranges the dimensions and data of an input.
*
* .. code::
*
* y = TransposeLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A N-Dimensional tensor.
* Output
* A N-Dimensional tensor of the same rank but with dimensions and data
* permuted according to axes. Shape: ``[InputShape[axis[0]],
* InputShape[axis[1]], ... , InputShape[axis[N-1]]]``
*
* Examples:
*
* - If ``axes`` is set to ``[3, 1, 2, 0]`` and the input shape is
* ``[6,7,8,9]``, then the output has shape ``[9,7,8,6]``
*/
message TransposeLayerParams {
/*
* Length of "axes" should match the rank of input & output tensor
* "axes" should be a permutation of "[0,1,2,...,N-1]" where N is the rank.
*/
repeated uint64 axes = 1; //
}
/*
* A layer that computes the matrix multiplication of two tensors with
* numpy-like broadcasting where the matrices reside in the last two indices of
* the tensor.
*
* .. code::
*
* y = BatchedMatMul(a,b)
*
* Requires 1 or 2 inputs and produces 1 output.
*
* The first tensor, "a", must be provided as an input. The second tensor can
* either be an input or provided as a weight matrix parameter.
*
* Input
* - a: First N-Dimensional tensor
* - b: Second N-Dimensional tensor (either a rank-N input or a matrix, i.e.
* N=2, provided as a layer parameter)
*
* Output
* A tensor containing the matrix product of two tensors.
* When there are two inputs: rank is max(2, rank(a), rank(b))
* When there is one input: rank is same as that of the input.
*
* This operation behaves as following:
*
* When there are two inputs:
* - If N >= 2 for both tensors, it is treated as a batch of matrices
* residing in the last two indices. All the indices, except for the last two,
* are broadcasted using conventional rules.
* - If the first tensor is 1-D, it is converted to a 2-D tensor by
* prepending a 1 to its shape. Eg. (D) -> (1,D)
* - If the second tensor is 1-D, it is converted to a 2-D tensor by
* appending a 1 to its shape. Eg. (D) -> (D,1)
*
* When there is one input:
* - The weight matrix corresponds to a matrix, of shape (X1, X2). Values
* of X1, X2 must be provided as layer parameters.
* - The input, "a", is reshaped into a matrix by combining all the leading
* dimensions, except the last, into a batch dimension. eg:
* - if "a" is rank 1 (X1,) --> (1, X1). Output shape will be (X2,)
* - if "a" is rank 2 (B1, X1) --> no need to reshape. Output shape
* will be (B1, X2)
* - if "a" is rank 3 (B1, B2, X1) --> (B1 * B2, X1). Output shape
* will be (B1, B2, X2)
* - etc
*/
message BatchedMatMulLayerParams {
/*
* If transposeA is true, it transposes the left matrix on the fly before
* matrix multiplication. (is ignored when there is one input)
*/
bool transposeA = 1;
/*
* If transposeB is true, it transposes the right matrix on the fly before
* matrix multiplication. (is ignored when there is one input)
*/
bool transposeB = 2;
/*
* Following parameters are ignored when there are two inputs.
*/
uint64 weightMatrixFirstDimension =
5; // X1: same as the last dimension of the input tensor
uint64 weightMatrixSecondDimension =
6; // X2: same as the last dimension of the output tensor
bool hasBias = 7; // Whether a bias is added or not. Supported only when
// there is one input.
/*
* Weight matrix representing shape [X1, X2].
* Values are however stored in column major order,
* in the "repeated float" or "bytes" fields of the message "WeightParams"
*/
WeightParams weights = 8;
WeightParams bias =
9; // Bias vector [X2]. Supported only when there is one input.
/*
* If set, this layer, at runtime, quantizes the floating point input blob to
* int8 before applying the matrix multiplication using the INT8 weight
* parameters provided in weights->int8RawValue. The result is then
* dequantized. Requires:
* * number of inputs to be 1
* * hasBias == false
* * QuantizationType == LinearQuantizationParams, such that
* * size of the "scale" field is 1 and "bias" field is empty in
* "LinearQuantizationParams"
* * numberOfBits == 8
* * weights->rawValue_size to be empty
*/
bool int8DynamicQuantize = 10;
}
/*
* A layer that concatenates a list of tensors along a specified axis.
*
* .. code::
*
* y = ConcatNDLayer(x1,x2,....)
*
* Requires at least 2 input and produces 1 output.
*
* Input
* The rank of the input tensors must match and all dimensions also must
* match, except for the dimension 'axis'.
*
*
* Output
* Same rank as the input. The dimension along "axis", is the sum of the
* dimensions of the inputs.
*
* example:
*
* in1 : shape (3, 2), value = [[1, 2], [3, 4], [5, 6]]
* in2 : shape (3, 2), value = [[7, 8], [9, 10], [11, 12]]
* axis = 0
*
* if interleave = False (default)
* output : shape (6, 2)
* output[0:3, :] = in1
* output[3:6, :] = in2
* value = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]]
*
* if interleave = True
* output : shape (6, 2)
* output[0::2, :] = in1
* output[1::2, :] = in2
* value = [[1, 2], [7, 8], [3, 4], [9, 10], [5, 6], [11, 12]]
*
*/
message ConcatNDLayerParams {
/*
* Dimension along which to concatenate. Supports negative values of the
* parameter 'axis'.
*/
int64 axis = 1;
/*
* (Only available in Core ML Specification >= 5 (iOS >= 14, macOS >= 11.0)
* Interleave option. If True, concatenation is done via interleaving the
* inputs. This requires all inputs to have the exact same shape.
*/
bool interleave = 2;
}
/*
* A layer that performs softmax normalization along a specified axis.
*
* .. code::
*
* y = SoftmaxNDLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Output shape is same as the input.
*/
message SoftmaxNDLayerParams {
/*
* Dimension on which the softmax would be performed. Supports negative values
* of the parameter 'axis'.
*/
int64 axis = 1;
}
/*
* A layer that reverses specific dimensions of the input tensor.
* It is similar in functionality to the numpy.flip method.
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*/
message ReverseLayerParams {
/*
* Reverses each dimension of the input tensor for which corresponding
* reverseDim is set to True. Requires len(reverseDim) == rank(inputTensor)
*/
repeated bool reverseDim = 1;
}
/*
* A layer that reverses variable length slices.
*
* Requires 2 inputs and produces 1 output.
*
* 2 inputs, in order are denoted by "data", "seq_lengths".
* "seq_lenghts" must be a rank 1 tensor, i.e. seq_lengths.shape = (B,)
* which contains the lengths of the amount of sequence to be reversed, for each
* element of the batch. Dimension "batchAxis" in "data" must be equal to B,
* i.e, data.shape[batchAxis] = B.
*
* According to the batch axis, input "data" is first divided into a batch of B
* inputs, each of which is flipped along the dimension "sequenceAxis", by the
* amount specified in "seq_lengths", the second input.
*
* e.g.:
*
* data [shape = (2,4)]:
* [0 1 2 3]
* [4 5 6 7]
* seq_lengths [shape = (2,)]:
* [3, 0]
* batchAxis = 0
* sequenceAxis = 1
*
* output [shape = (2,4)]:
* [2 1 0 3]
* [4 5 6 7]
*
*
* data [shape = (2,3,2)]:
* [0 1]
* [2 3]
* [4 5] (slice = 0)
* [6 7]
* [8 9]
* [10 11] (slice = 1)
* seq_lengths [shape = (2,)]:
* [2, 3]
* batchAxis = 0
* sequenceAxis = 1
*
* output [shape = (2,3,2)]:
* [2 3]
* [0 1]
* [4 5] (slice = 0)
* [10 11]
* [8 9]
* [6 7] (slice = 1)
*
* Output shape is same as the input.
*/
message ReverseSeqLayerParams {
int64 batchAxis = 1; // batch axis has to be strictly less than seq_axis
int64 sequenceAxis = 2;
}
/*
* A layer that loads data as a parameter and provides it as an output.
*
* .. code::
*
* y = LoadConstantNDLayer()
*
* Requires no input and produces 1 output.
*
* Output: A tensor with shape as provided in the parameter "shape"
*/
message LoadConstantNDLayerParams {
/*
* The shape of the constant to be loaded.
*/
repeated uint64 shape = 1;
WeightParams data = 2;
}
/*
* A layer that generates an output tensor with a constant value.
* Input is only used to determine the shape of the output.
* This layer is used to allocate a tensor with a dynamic shape (that of the
* input) and constant value.
*
* Requires 1 input and produces 1 output.
*
* .. code::
*
* y = FillLikeLayer(x)
*
* Input
* A N-Dimensional tensor, whose values are ignored. Only the shape is used
* to infer the shape of the output.
*
* Output
* A N-Dimensional tensor with the same shape as the input tensor.
*
*/
message FillLikeLayerParams {
float value = 1;
}
/*
* A layer that generates an output tensor with a constant value.
* This layer is used to allocate a tensor with a static shape and constant
* value.
*
* Requires no input and produces 1 output.
*
* .. code::
*
* y = FillStaticLayer(x)
*
* Output
* A N-Dimensional tensor of shape "targetShape".
*
*/
message FillStaticLayerParams {
float value = 1;
repeated uint64 targetShape = 2;
}
/*
* A layer that generates an output tensor with a constant value.
* This layer is used to allocate a tensor with a dynamic shape (as specified by
* the input) and constant value.
*
* Requires 1 input and produces 1 output.
*
* .. code::
*
* y = FillDynamicLayer(x)
*
* Input
* A rank 1 tensor specifying the shape of the output
*
* Output
* An N-Dimensional tensor with the shape specified by the values in the
* input tensor.
*
*/
message FillDynamicLayerParams {
float value = 1;
}
/*
* A layer that returns the elements either from tensor x or tensor y,
* depending on the value in the condition tensor.
* It is similar in functionality to the numpy.where method with 3 inputs.
*
* Requires 3 inputs and produces 1 output.
* Inputs, in order, are the condition tensor, x and y.
*
* for each vector index (i,...,j):
* output[i,...,j] = x[i,...,j] if condition[i,...,j] = True
* y[i,...,j] if condition[i,...,j] = False
*
* All the 3 inputs are first broadcasted to a common shape.
* (the shapes must be broadcastable)
*
* output.rank = max(input[0].rank, input[1].rank, input[2].rank)
*
*/
message WhereBroadcastableLayerParams {}
/*
* A layer that computes elementwise trigonometric sine function.
*
*
* .. code::
*
* y = SinLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message SinLayerParams {}
/*
* A layer that computes elementwise trigonometric cosine function.
*
*
* .. code::
*
* y = CosLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message CosLayerParams {}
/*
* A layer that computes elementwise trigonometric tangent function.
*
*
* .. code::
*
* y = TanLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message TanLayerParams {}
/*
* A layer that computes elementwise trigonometric arcsine function.
*
*
* .. code::
*
* y = AsinLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message AsinLayerParams {}
/*
* A layer that computes elementwise trigonometric arccosine function.
*
*
* .. code::
*
* y = AcosLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message AcosLayerParams {}
/*
* A layer that computes elementwise trigonometric arctangent function.
*
*
* .. code::
*
* y = AtanLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message AtanLayerParams {}
/*
* A layer that computes elementwise trigonometric hyperbolic sine function.
*
*
* .. code::
*
* y = SinhLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message SinhLayerParams {}
/*
* A layer that computes elementwise trigonometric hyperbolic cosine function.
*
*
* .. code::
*
* y = CoshLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message CoshLayerParams {}
/*
* A layer that computes elementwise trigonometric hyperbolic tangent function.
*
*
* .. code::
*
* y = TanhLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message TanhLayerParams {}
/*
* A layer that computes elementwise trigonometric hyperbolic arcsine function.
*
*
* .. code::
*
* y = AsinhLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message AsinhLayerParams {}
/*
* A layer that computes elementwise trigonometric hyperbolic arccosine
* function.
*
*
* .. code::
*
* y = AcoshLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message AcoshLayerParams {}
/*
* A layer that computes elementwise trigonometric hyperbolic arctangent
* function.
*
*
* .. code::
*
* y = AtanhLayer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message AtanhLayerParams {}
/*
* A layer that raises each element in first tensor to the power of
* corresponding element in the second tensor.
* Supports conventional numpy-like broadcasting.
*
* .. code::
*
* y = PowBroadcastableLayer(x)
*
* Requires 2 inputs and produces 1 output.
*
* Input
* - First N-Dimensional tensor
* - Second N-Dimensional tensor
*
* Output
* An N-Dimensional tensor with the broadcast shape.
*
*/
message PowBroadcastableLayerParams {}
/*
* A layer that computes the exponential of all elements in the input tensor,
* with the base 2.
*
*
* .. code::
*
* y = Exp2Layer(x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message Exp2LayerParams {}
/*
* A layer that returns a tensor containing the indices of all non-zero
* elements of input tensor.
* It is similar in functionality to the numpy.where method with 1 input.
*
* Requires 1 input and produces 1 output.
* Output is of rank 2, of shape (N,R),
* where N is the number of non-zero elements in the input and R is the rank of
* the input.
*
* Output contains indices represented in the multi-index form
*
* e.g.:
* input {shape = (4,)}:
* [0 1 0 2]
* output {shape = (2,1)}:
* [1]
* [3]
*
*
* input {shape = (3, 3)}:
* [1 2 1]
* [0 2 2]
* [2 1 0]
* output {shape = (7,1)}:
* [0. 0.]
* [0. 1.]
* [0. 2.]
* [1. 1.]
* [1. 2.]
* [2. 0.]
* [2. 1.]
*
*/
message WhereNonZeroLayerParams {}
/*
* A layer that copies a tensor setting everything outside a central band in
* each inner-most matrix to zero.
*
* Requires 1 input and produces 1 output.
*
* Parameters for matrix_band_part layer
* band(m, n) = (num_lower < 0 || (m-n) <= num_lower) && (num_upper < 0 || (n-m)
* <= num_upper). output[i, j, k, ..., m, n] = band(m, n) * input[i, j, k, ...,
* m, n]
*
*
* Output shape is same as the input shape.
* Rank of the input must be at least 2.
* For rank higher than 2, the last 2 dimensions are treated as the matrix,
* while the rest are treated as batch.
*/
message MatrixBandPartLayerParams {
int64 numLower = 1;
int64 numUpper = 2;
}
/*
* A layer that copies a tensor setting everything outside upper triangular to
* zero.
*
* Requires 1 input and produces 1 output.
*
* Output shape is same as the input shape.
* Rank of the input must be at least 2.
* For rank higher than 2, the last 2 dimensions are treated as the matrix,
* while the rest are treated as batch.
*/
message UpperTriangularLayerParams {
int64 k = 1; // Diagonal below which to zero elements. k = 0 (the default) is
// the main diagonal, k < 0 is below it and k > 0 is above
}
/*
* A layer that copies a tensor setting everything outside lower triangular to
* zero.
*
* Requires 1 input and produces 1 output.
*
* Output shape is same as the input shape.
* Rank of the input must be at least 2.
* For rank higher than 2, the last 2 dimensions are treated as the matrix,
* while the rest are treated as batch.
*/
message LowerTriangularLayerParams {
int64 k = 1; // Diagonal above which to zero elements. k = 0 (the default) is
// the main diagonal, k < 0 is below it and k > 0 is above
}
/*
*
* A layer that broadcasts a tensor to a new shape.
*
* Requires 2 inputs and produces 1 output.
*
* First input is broadcast to produce the output, while the second input is
* only used to determine the shape of the output. Values of second input are
* not used.
*
* Output is a tensor with the same shape as the second input.
*
*/
message BroadcastToLikeLayerParams {}
/*
*
* A layer that broadcasts a tensor to a new shape.
*
* Requires 1 input and produces 1 output.
*
* Output tensor is the broadcasted version of the input and has shape as
* specified in the parameter "targetShape".
*/
message BroadcastToStaticLayerParams {
repeated uint64 targetShape = 1;
}
/*
*
* A layer that broadcasts a tensor to a new shape.
*
* Requires 2 inputs and produces 1 output.
*
* First input is the one that is broadcasted to produce the output.
* Second input is a rank 1 tensor specifying the shape of the output.
* Output tensor has shape as specified by the values in the 2nd input tensor.
*/
message BroadcastToDynamicLayerParams {}
/*
* A layer that performs element-wise addition operation with broadcast support.
*
* Requires 2 inputs and produces 1 output.
*/
message AddBroadcastableLayerParams {}
/*
* A layer that performs element-wise maximum operation with broadcast support.
*
* Requires 2 inputs and produces 1 output.
*/
message MaxBroadcastableLayerParams {}
/*
* A layer that performs element-wise minimum operation with broadcast support.
*
* Requires 2 inputs and produces 1 output.
*/
message MinBroadcastableLayerParams {}
/*
* A layer that performs element-wise modular operation with broadcast support.
*
* Requires 2 inputs and produces 1 output.
*/
message ModBroadcastableLayerParams {}
/*
* A layer that performs element-wise floor division operation with broadcast
* support.
*
* Requires 2 inputs and produces 1 output.
*/
message FloorDivBroadcastableLayerParams {}
/*
* A layer that performs element-wise subtract operation with broadcast support.
*
* Requires 2 inputs and produces 1 output.
*/
message SubtractBroadcastableLayerParams {}
/*
* A layer that performs element-wise multiply operation with broadcast support.
*
* Requires 2 inputs and produces 1 output.
*/
message MultiplyBroadcastableLayerParams {}
/*
* A layer that performs element-wise division operation with broadcast support.
*
* Requires 2 inputs and produces 1 output.
*/
message DivideBroadcastableLayerParams {}
/*
* Gather layer that gathers elements from the first input, along a specified
* axis, at indices specified in the second input. It is similar in
* functionality to the numpy.take method.
*
* Requires 2 inputs and produces 1 output.
*
* Given two inputs, 'data' and 'indices', gather the slices of 'data'
* and store into output.
* e.g.
* for i in [0, length(indices) - 1]
* output[i] = data[indices[i]] (1-D case, axis=0)
*
* if axis = 0:
* for each vector index (i,...,j)
* output[i,...,j,:,..,:] = data[indices[i,...,j],:,..,:]
*
* output.rank = (data.rank - 1) + indices.rank
*
* Negative indices and negative axis are supported.
*
* e.g:
*
* data shape = (2, 3)
* indices shape = (6, 8)
* axis = 0
* output shape = (6, 8) + (3,) = (6, 8, 3)
*
* data shape = (2, 3, 5)
* indices shape = (6, 8)
* axis = 1
* output shape = (2,) + (6, 8) + (5,) = (2, 6, 8, 5)
*
*/
message GatherLayerParams {
int64 axis = 1;
}
/*
* Scatter accumulation mode.
*/
enum ScatterMode {
SCATTER_UPDATE = 0;
SCATTER_ADD = 1; // add
SCATTER_SUB = 2; // subtract
SCATTER_MUL = 3; // multiply
SCATTER_DIV = 4; // divide
SCATTER_MAX = 5; // maximum
SCATTER_MIN = 6; // minimum
}
/*
* A layer that scatters data into a new tensor according to indices from the
* input. This is the inverse operation of Gather.
*
* Requires 3 inputs and produces 1 output.
*
* Output is initialized with the first input.
* Then updated with the values in the third input, at indices specified by the
* second input.
*
* An example when axis=0:
* Given three inputs, in order, "container", "indices", "updates", where
*
* - "container" is a rank R+1 tensor of shape [D_0, D_1, ..., D_R], which
* contains D_0 number of tensors, each with shape [D_1, ..., D_R].
*
* - "indices" is a rank 1 tensor with shape [N], where N is the number of
* updates. The values in this tensor must be in the range [0, D_0 - 1].
* (negative indexing is supported)
*
* - "updates" is a rank R+1 tensor with shape [N, D_1, ..., D_R], which
* represents a total number of N tensors, each of shape [D_1, ..., D_R].
*
* The effect of this operation is as follows:
*
* output = container;
* For each i in 0, ..., N - 1
* output[indices[i], :, ..., :] = updates[i, :, ..., :] // if mode ==
* "SCATTER_UPDATE"
*
* or
* For each i in 0, ..., N - 1
* output[indices[i], :, ..., :] += updates[i, :, ..., :] // if mode ==
* "SCATTER_ADD"
*
* etc
*
* When "indices" is a tensor of rank greater than 1, the equation becomes (for
* axis=0): For each vector index (i,...,j) output[indices[i,...,j],...] -=
* updates[i,...,j,...] // if mode == "SCATTER_SUB"
*
*
* The output has the same shape as the first input.
* "indices" input must have rank less than or equal to the "updates" input and
* its shape must be a subset of the the shape of the "updates" input.
*
* e.g:
*
* container shape = (4, 3)
* indices shape = (5, 2, 3)
* updates shape = (4, 5, 2, 3)
* axis = 1
* output shape = (4, 3)
*
* container shape = (4, 4, 3)
* indices shape = (6,)
* updates shape = (4, 6, 3)
* axis = -2
* output shape = (4, 4, 3)
*
* container shape = (5,)
* indices shape = (5, 7, 5, 6)
* updates shape = (5, 7, 5, 6)
* axis = -1
* output shape = (5,)
*/
message ScatterLayerParams {
int64 axis = 1;
ScatterMode mode = 2; // mode of accumulation.
}
/*
* A layer that gathers elements from the first input, 'params', at the
* multi-indices specified by the second input, 'indices'.
*
* Requires 2 inputs and produces 1 output.
*
* 'params' = input[0], 'indices' = input[1]
*
* 'indices' is a rank K+1 tensor of shape [I_0, I_1, .., I_(K-1), I_K] which is
* viewed as a collection of indices of (I_0 * I_1 * ... * I_(K-1)) points in
* the I_K dimensional space. For instance, the multi-index of the first point
* is indices[0,0,...,0,:].
*
* Here is how the output is constructed:
*
* for i = 0,1,...,(I_0-1)
* ...
* for j = 0,1,....,(I_(K-1)-1)
* output[i,....,j,:,:,..,:] = params[indices[i,...,j,:], :,:,..,:]
*
* Hence, output shape is [I_0, I_1,...,I(K-1)] + params.shape[I_K:]
*
* output.rank = indices.rank - 1 + params.rank - indices.shape[-1]
*
* e.g:
*
* input[0] shape = (4, 2, 3, 4)
* input[1] shape = (6, 2)
* output shape = (6,) + (3, 4) = (6, 3, 4)
*
* input[0] shape = (3, 3, 3, 4, 7)
* input[1] shape = (3, 5)
* output shape = (3,) + () = (3,)
*
* input[0] shape = (5, 3, 2, 5)
* input[1] shape = (2, 7, 3, 2)
* output shape = (2, 7, 3) + (2, 5) = (2, 7, 3, 2, 5)
*
*/
message GatherNDLayerParams {}
/*
* A layer that scatters data into a new tensor according to multi-indices from
* the input. This is the inverse operation of GatherND.
*
* Requires 3 inputs and produces 1 output.
* 3 inputs, in order are denoted as "container", "indices", "updates".
*
* 'indices' is a rank K+1 tensor of shape [I_0, I_1, .., I_(K-1), I_K] which is
* viewed as a collection of indices of (I_0 * I_1 * ... * I_(K-1)) points in
* the I_K dimensional space. For instance, the multi-index of the first point
* is indices[0,0,...,0,:].
*
* container.rank >= I_K
* updates.rank = K + (container.rank - I_K)
* shape of 'updates' = [I_0, I_1,...,I(K-1)] + container.shape[I_K:]
*
* output = container
* For each vector index (i,...,j) s.t. 0<=i<I_0,..., 0<=j<I_K
* output[indices[i,...,j,:], :,:,..,:] = updates[i,....,j,:,:,..,:] // if
* mode == "SCATTER_UPDATE"
*
* The output has the same shape as the first input.
*
* e.g:
*
* container shape = (3, 2)
* indices shape = (4, 2)
* updates shape = (4,)
* output shape = (3, 2)
*
* container shape = (7, 6)
* indices shape = (4, 7, 2, 5, 1)
* updates shape = (4, 7, 2, 5, 6)
* output shape = (7, 6)
*
*/
message ScatterNDLayerParams {
ScatterMode mode = 1; // mode of accumulation.
}
/*
* Gather layer that gathers elements from the first input, along a specified
* axis, at indices specified in the second input. It is similar in
* functionality to the numpy.take_along_axis method.
*
* Requires 2 inputs and produces 1 output.
*
* Given two inputs, 'data' and 'indices', gather the slices of 'data'
* and store into output.
*
* Both inputs and output have the same rank.
* Output shape is same as the shape of 'indices'
* Shapes of 'indices' and 'data' match, except at the 'axis' dimension.
*
* This operation performs the following operation for axis=0:
* for each vector index (i,j,....,k)
* output[i,j,....,k] = data[index[i,j,....,k],j,....,k]
*
* Negative indices and negative axis are supported.
*
* e.g:
*
* data shape = (4, 4, 7)
* indices shape = (4, 5, 7)
* axis = 1
* output shape = (4, 5, 7)
*
*/
message GatherAlongAxisLayerParams {
int64 axis = 1;
}
/*
* A layer that scatters data into a new tensor according to indices from
* the input along the given axis into the output tensor.
* This is the inverse operation of GatherAlongAxis.
* It is similar in functionality to the numpy.put_along_axis method.
*
* Requires 3 inputs and produces 1 output.
* 3 inputs, in order are denoted as "container", "indices", "updates".
*
* All inputs and output have the same rank.
* Output shape is same as the shape of 'container'
* Shapes of 'indices' and 'updates' match, which is same as the shape of
* 'container' except at the 'axis' dimension.
*
* Negative indices and negative axis are supported.
*
* This operation performs the following operation for axis=0:
* output = container
* for each vector index (i,j,....,k)
* output[index[i,j,....,k],j,....,k] = updates[i,j,....,k]
*
* e.g.:
*
* container shape = (2, 5, 6)
* indices shape = (2, 2, 6)
* updates shape = (2, 2, 6)
* axis = -2
* output shape = (2, 5, 6)
*
*/
message ScatterAlongAxisLayerParams {
int64 axis = 1;
ScatterMode mode = 2; // mode of accumulation.
}
/*
* A layer that stacks the input tensors along the given axis.
* It is similar in functionality to the numpy.stack method.
*
* Requires at least 2 inputs and produces 1 output.
* All inputs must have the same shape.
* Rank of the output is 1 greater than the rank of the inputs.
*
* Negative indexing is supported for the "axis" parameter.
*
* e.g.:
*
* input shape = (2, 4, 2)
* number of inputs = 5
* axis = 3
* output shape = (2, 4, 2, 5)
*
* input shape = (2, 4, 2)
* number of inputs = 5
* axis = -2
* output shape = (2, 4, 5, 2)
*/
message StackLayerParams {
int64 axis = 1;
}
/*
* A layer that reshapes a tensor that does not alter the rank of the input.
* Order of the data is left unchanged.
*
* Requires 1 input and produces 1 output.
*
* e.g:
*
* input shape = (20,10)
* targetShape = (5,-1)
* output shape = (5,40)
*
* input shape = (20,10,5)
* targetShape = (0,2,25)
* output shape = (20,2,25)
*
* input shape = (10,3,5)
* targetShape = (25,0,-1)
* output shape = (25,3,2)
*/
message RankPreservingReshapeLayerParams {
/*
* Length of this field must be same as the input/output rank.
* It can have 0's, in which case the corresponding input dimension is kept
* intact. At most one element can be -1, in which case the output dimension
* is calculated from rest of the shape.
*/
repeated int64 targetShape = 1;
}
/*
* Constant padding layer.
* Pad the input array with a constant value, either along a single given axis
* or along a set of axes.
*
* Requires 1 or 2 inputs and produces 1 output.
* The amount of padding can be either set as a parameter ("padAmounts") or
* provided as a second input.
*
* Output rank is same as the rank of the first input.
*
* when "padToGivenOutputSizeMode" is False:
*
* output_shape[i] = input_shape[i] + padAmounts[2*i] + padAmounts[2*i+1],
* i=0,...,rank-1
*
* Examples:
*
* input shape = (20,10)
* padAmounts = [0,1,4,0]
* output shape = (21,14)
*
* input shape = (20,10,5)
* padAmounts = [0,0,3,4,0,9]
* output shape = (20,17,14)
*
*
* when "padToGivenOutputSizeMode" is True
*
* output_shape[i] = max(input_shape[i], max(padAmounts[2*i] +
* padAmounts[2*i+1])), i=0,...,rank-1
*
* input shape = (20,10)
* padAmounts = [0,21,14,0]
* output shape = (21,14)
*
* input shape = (20,10,5)
* padAmounts = [0,0,17,0,0,14]
* output shape = (20,17,14)
*/
message ConstantPaddingLayerParams {
/*
* The value to be used for padding.
*/
float value = 1;
/*
* Length of this repeated field must be twice the rank of the first input.
* 2*i-th and (2*i+1)-th values represent the amount of padding to be applied
* to the the i-th input dimension, "before" and "after" the input values,
* respectively.
*/
repeated uint64 padAmounts = 2;
/*
* When this is True, positive values in "padAmounts" are equivalent to the
* output shape. In that case only one of padAmounts[2*i] and
* padAmounts[2*i+1] can be non zero, for i=0,..,rank-1.
*/
bool padToGivenOutputSizeMode = 3;
}
/*
* A layer that returns a tensor filled with values from the normal
* distribution.
*
* Requires 1 input and produces 1 output.
*
* Parameters
* seed: seed used for the normal distribution.
* mean: mean of the normal distribution.
* stdDev: standard deviation of the normal distribution.
*
* Input
* An N-Dimensional tensor, whose values are ignored. Only the shape is used
* to infer the shape of the output.
*
* Output
* An N-Dimensional tensor with the same shape as the input tensor.
*
*/
message RandomNormalLikeLayerParams {
int64 seed = 1;
float mean = 2;
float stdDev = 3;
}
/*
* A layer that returns a tensor filled with values from the normal
* distribution.
*
* Requires no input and produces 1 output.
*
* Parameters
* seed: seed used for the normal distribution.
* mean: mean of the normal distribution.
* stdDev: standard deviation of the normal distribution.
* outputShape: shape of the output tensor.
*
* Output
* An N-Dimensional tensor of shape "outputShape".
*
*/
message RandomNormalStaticLayerParams {
int64 seed = 1;
float mean = 2;
float stdDev = 3;
repeated uint64 outputShape = 4;
}
/*
* A layer that returns a tensor filled with values from the normal
* distribution.
*
* Requires 1 input and produces 1 output.
*
* Parameters:
* seed: seed used for the normal distribution.
* mean: mean of the normal distribution.
* stdDev: standard deviation of the normal distribution.
*
* Input
* A rank 1 tensor specifying the shape of the output
*
* Output
* An N-Dimensional tensor with the shape specified by the values in the
* input tensor.
*/
message RandomNormalDynamicLayerParams {
int64 seed = 1;
float mean = 2;
float stdDev = 3;
}
/*
* A layer that returns a tensor filled with values from the uniform
* distribution.
*
* Requires 1 input and produces 1 output.
*
* Parameters
* seed: seed used for the uniform distribution.
* minVal: lower bound on the range of random values for the uniform
* distribution. maxVal: upper bound on the range of random values for the
* uniform distribution.
*
* Input
* An N-Dimensional tensor, whose values are ignored. Only the shape is used
* to infer the shape of the output.
*
* Output
* An N-Dimensional tensor with the same shape as the input tensor.
*
*/
message RandomUniformLikeLayerParams {
int64 seed = 1;
float minVal = 2;
float maxVal = 3;
}
/*
* A layer that returns a tensor filled with values from the uniform
* distribution.
*
* Requires no input and produces 1 output.
*
* Parameters
* seed: seed used for the uniform distribution.
* minVal: lower bound on the range of random values for the uniform
* distribution. maxVal: upper bound on the range of random values for the
* uniform distribution. outputShape: shape of the output tensor.
*
* Output
* An N-Dimensional tensor of shape "outputShape".
*
*/
message RandomUniformStaticLayerParams {
int64 seed = 1;
float minVal = 2;
float maxVal = 3;
repeated uint64 outputShape = 4;
}
/*
* A layer that returns a tensor filled with values from the uniform
* distribution.
*
* Requires 1 input and produces 1 output.
*
* Parameters:
* seed: seed used for the uniform distribution.
* minVal: lower bound on the range of random values for the uniform
* distribution. maxVal: upper bound on the range of random values for the
* uniform distribution.
*
* Input
* A rank 1 tensor specifying the shape of the output
*
* Output
* An N-Dimensional tensor with the shape specified by the values in the
* input tensor.
*
*/
message RandomUniformDynamicLayerParams {
int64 seed = 1;
float minVal = 2;
float maxVal = 3;
}
/*
* A layer that returns a tensor filled with values from the Bernoulli
* distribution.
*
* Requires 1 input and produces 1 output.
*
* Parameters
* seed: seed used for the Bernoulli distribution.
* prob: probability of a 1 event.
*
* Input
* An N-Dimensional tensor, whose values are ignored. Only the shape is used
* to infer the shape of the output.
*
* Output
* An N-Dimensional tensor with the same shape as the input tensor.
*
*/
message RandomBernoulliLikeLayerParams {
int64 seed = 1;
float prob = 2;
}
/*
* A layer that returns a tensor filled with values from the Bernoulli
* distribution.
*
* Requires no input and produces 1 output.
*
* Parameters
* seed: seed used for the Bernoulli distribution.
* prob: probability of a 1 event.
* outputShape: shape of the output tensor.
*
* Output
* An N-Dimensional tensor of shape "outputShape".
*/
message RandomBernoulliStaticLayerParams {
int64 seed = 1;
float prob = 2;
repeated uint64 outputShape = 3;
}
/*
* A layer that returns a tensor filled with values from the Bernoulli
* distribution.
*
* Requires 1 input and produces 1 output.
*
* Parameters:
* seed: seed used for the Bernoulli distribution.
* prob: probability of a 1 event.
*
* Input
* A rank 1 tensor specifying the shape of the output
*
* Output
* An N-Dimensional tensor with the shape specified by the values in the
* input tensor.
*/
message RandomBernoulliDynamicLayerParams {
int64 seed = 1;
float prob = 2;
}
/*
* A layer that returns a tensor of the specified shape filled with values from
* the categorical distribution.
*
* Requires 1 input and produces 1 output.
*
* Parameter:
* seed: seed used for the categorical distribution.
* numSamples: number of samples to draw.
* isLogits: true if the inputs are logits, false if the inputs are
* probabilities. eps: default value is 1e-10. temperature: default value
* is 1.0.
*
* Input tensor shape = [D_1, D_2, ... , D_(R-1), D_R] (Rank = R)
* Then the shape of the output is [D_1, D_2, ... , D_(R-1), numSamples] (Rank =
* R)
*
*/
message CategoricalDistributionLayerParams {
int64 seed = 1;
int64 numSamples = 2;
bool isLogits = 3;
float eps = 4;
float temperature = 5;
}
/*
* A layer that performs reduction with L1 normalization operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceL1LayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that performs reduction with L2 normalization operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceL2LayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that performs reduction with max operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceMaxLayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that performs reduction with min operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceMinLayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that performs reduction with sum operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceSumLayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that performs reduction with prod operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceProdLayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that performs reduction with mean operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceMeanLayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that performs reduction with logSum operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceLogSumLayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that performs reduction with logSumExp operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceSumSquareLayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that performs reduction with logSumExp operation.
*
* Negative indexing is supported.
* Requires 1 input and produces 1 output.
*
* Parameters:
* axes: dimensions along which to perform reduction
* keepDims: if True, keep the reduced dimensions (value will be 1),
* otherwise, reduced dimensions are squeezed reduceAll: ignore the "axes"
* parameter, perform reduction along all axes
*
*/
message ReduceLogSumExpLayerParams {
repeated int64 axes = 1;
bool keepDims = 2;
bool reduceAll = 3;
}
/*
* A layer that increases the rank of the input tensor by adding unit
* dimensions.
*
* Requires 1 input and produces 1 output.
*
* e.g.:
*
* input shape = (10,5)
* axes = (0,1)
* output shape = (1,1,10,5)
*
* input shape = (10,5)
* axes = (0,2)
* output shape = (1,10,1,5)
*
* input shape = (10,5)
* axes = (-2,-1)
* output shape = (10,5,1,1)
*
*/
message ExpandDimsLayerParams {
/*
* Axis values provided here get dimension 1 in the output tensor.
* Negative indexing is supported.
*/
repeated int64 axes = 1;
}
/*
* A layer that flattens the input tensor into a 2-dimensional matrix.
*
* Requires 1 input and produces 1 output.
* Output tensor is always rank 2.
*
* First dimension of output is the product of all the dimensions in
* input[:axis] ("axis" is exclusive) Second dimension of output is the product
* of all the dimensions in input[axis:] ("axis" is inclusive)
*
* e.g.:
* input shape: (3,)
* axis: -1
* output shape: (1, 3)
*
* input shape: (3,)
* axis: 1
* output shape: (3, 1)
*
* input shape: (4, 3)
* axis: -1
* output shape: (4, 3)
*
* input shape: (5, 2)
* axis: 0
* output shape: (1, 10)
*
* input shape: (5, 5, 3)
* axis: -2
* output shape: (5, 15)
*
* input shape: (2, 3, 2)
* axis: -1
* output shape: (6, 2)
*
*/
message FlattenTo2DLayerParams {
int64 axis = 1;
}
/*
* A layer that reshapes a tensor.
*
* Requires 1 input and produces 1 output.
*
* Output tensor is the reshaped version of the input and has shape as specified
* in the parameter "targetShape".
*
*/
message ReshapeStaticLayerParams {
repeated int64 targetShape = 1;
}
/*
* A layer that reshapes a tensor.
*
* Requires 2 inputs and produces 1 output.
*
* First input is reshaped to produce the output, while the second input is only
* used to determine the shape of the output. Values of the second input are not
* used.
*
* Output is a tensor with the same shape as the second input.
*
*/
message ReshapeLikeLayerParams {}
/*
* A layer that reshapes a tensor.
*
* Requires 2 inputs and produces 1 output.
*
* First input is the one that is reshaped to produce the output.
* Second input is a rank 1 tensor specifying the shape of the output.
* Output tensor has shape as specified by the values in the 2nd input tensor.
*/
message ReshapeDynamicLayerParams {}
/*
* A layer that decreases the rank of the input tensor by removing unit
* dimensions.
*
* Requires 1 input and produces 1 output.
*
* Output rank is one less than input rank, if input rank is more than 1.
* If input rank is 1, output rank is also 1.
*
* e.g.:
*
* input shape = (1,1,10,5)
* axes = (0,1)
* output shape = (10,5)
*
* input shape = (1,10,5,1)
* axes = (0,3)
* output shape = (10,5)
*
* input shape = (10,5,1,1)
* axes = (-2,-1)
* output shape = (10,5)
*
* input shape = (1,)
* axes = (0)
* output shape = (1,)
*
*/
message SqueezeLayerParams {
/*
* Axis values provided here get removed from the input tensor.
* Negative indexing is supported.
*/
repeated int64 axes = 1;
bool squeezeAll = 2; // if true squeeze all dimensions that are 1.
}
/*
* A layer that returns top K (or bottom K) values and the corresponding indices
* of the input along a given axis.
*
* Requires 1 or 2 inputs and produces 2 outputs.
*
* The second input is the value of the K, and is optional.
* If there is only one input, value of K that is specified in the layer
* parameter is used.
*
* Both outputs have the same rank as the first input.
* Second input must correspond to a scalar tensor.
*
* e.g.:
*
* first input's shape = (45, 34, 10, 5)
* axis = 1
* output shape, for both outputs = (45, K, 10, 5)
*
*/
message TopKLayerParams {
int64 axis = 1; // negative indexing is supported
uint64 K = 2; // is ignored if a second input is present.
bool useBottomK =
3; // if true, bottom K (values, indices) are returned instead
}
/*
* A layer that returns the indices of the maximum value along a specified axis
* in a tensor.
*
* Requires 1 input and produces 1 output. Negative indexing is supported.
*
* Output has the same rank as the input if "removeDim" is False (default).
* Output has rank one less than the input if "removeDim" is True and input rank
* is more than 1.
*
* e.g.:
*
* input shape = (45, 34, 10, 5)
* axis = -2
* output shape = (45, 1, 10, 5), if removeDim = False (default)
* output shape = (45, 10, 5), if removeDim = True
*
* input shape = (5,)
* axis = 0
* output shape = (1,), if removeDim = False or True
*
*/
message ArgMaxLayerParams {
int64 axis = 1;
bool removeDim = 2;
}
/*
* A layer that returns the indices of the minimum value along a specified axis
* in a tensor.
*
* Requires 1 input and produces 1 output. Negative indexing is supported.
*
* Output has the same rank as the input if "removeDim" is False (default).
* Output has rank one less than the input if "removeDim" is True and input rank
* is more than 1.
*
* e.g.:
*
* input shape = (45, 34, 10, 5)
* axis = -2
* output shape = (45, 1, 10, 5), if removeDim = False (default)
* output shape = (45, 10, 5), if removeDim = True
*
* input shape = (5,)
* axis = 0
* output shape = (1,), if removeDim = False or True
*
*/
message ArgMinLayerParams {
int64 axis = 1;
bool removeDim = 2;
}
/*
* A layer layer that splits the input tensor into multiple output tensors,
* along the specified axis.
*
* The layer either uniformly splits the input tensor into ``num_splits``
* tensors, or splits according to the given split sizes in ``split_sizes``.
* Supports unequal splits and negative indexing.
*
* Requires 1 input and produces at least 2 outputs.
* Rank of all the outputs is same as that of the input.
*
* If parameter "splitSizes" is provided, value of the parameter "numSplits" is
* ignored, since in that case "numSplits" is automatically inferred to be the
* length of "splitSizes".
*
*
* e.g.:
* input shape: (5, 3, 4)
* axis = -3, split_sizes = [3, 2]
* output shape: (3, 3, 4)
* output shape: (2, 3, 4)
*/
message SplitNDLayerParams {
int64 axis = 1;
uint64 numSplits = 2;
repeated uint64 splitSizes = 3;
}
/*
* A layer that performs element-wise ceil operation on the input tensor that
* rounds the value to the smallest integer not less than x.
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message CeilLayerParams {}
/*
* A layer that performs element-wise round operation on the input tensor
* that rounds the value to the nearest integer.
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message RoundLayerParams {}
/*
* A layer that performs element-wise floor operation on the input tensor
* that rounds the value to the largest integer not greater than x.
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message FloorLayerParams {}
/*
* A layer that performs element-wise sign operation (+1 for positive values,
* -1 for negative values, 0 for zeros).
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message SignLayerParams {}
/*
* A layer that performs element-wise clip operation. Clip the values in the
* input tensor to the threshold values [min_value, max_value].
*
* Requires 1 input and produces 1 output.
*
* Parameter minVal: the minimum threshold.
* Parameter maxVal: the maximum threshold.
*
* output = min(max(input, minVal), maxVal)
*
* Output shape is same as the input.
*/
message ClipLayerParams {
float minVal = 1;
float maxVal = 2;
}
/*
* A layer that extracts a slice of size ``(end - begin) / stride``
* from the given input tensor.
* Support negative indexing and negative strides.
*
* Requires 1 input and produces 1 output.
* Output rank is same as the input rank.
*
* Value of beginIds, beginMasks, endIds, endMasks, strides are required
* parameters. Lengths of all the parameters must equal the rank of the input.
*
* i-th element of "beginIds" is ignored and assumed to be 0 if the i-th element
* of "beginMasks" is True
*
* i-th element of "endIds" is ignored and assumed to be -1 if the i-th element
* of "endMasks" is True
*
* e.g.:
* if i-th element of "squeezeMasks" is set to True, only beginIds[i] would be
* sliced out, and all other masks and inputs are ignored.
*
* e.g. (without squeezeMasks):
* input shape: (5, 5, 5)
* beginIds: [1, 2, 3]
* beginMasks: [True, False, True]
* endIds: [3, -3, 2]
* endMasks: [False, True, True]
* strides: [2, 2, 2]
* SqueezeMasks: [False, False, False]
* output shape: (2, 2, 3)
* This is equivalent to input[:3:2, 2::2, ::2]
*
* e.g. (with squeezeMasks):
* input shape: (5, 5, 5)
* beginIds: [1, 2, 3]
* beginMasks: [True, False, True]
* endIds: [3, -3, 2]
* endMasks: [False, True, True]
* strides: [2, 2, 2]
* SqueezeMasks: [False, True, False]
* output shape: (2, 3)
* This is equivalent to input[:3:2, 2, ::2]
*
*/
message SliceStaticLayerParams {
repeated int64 beginIds = 1;
repeated bool beginMasks = 2;
repeated int64 endIds = 3;
repeated bool endMasks = 4;
repeated int64 strides = 5;
repeated bool squeezeMasks = 6;
}
/*
* A layer that extracts a slice of size ``(end - begin) / stride``
* from the given input tensor.
* Support negative indexing and negative strides.
* See "SliceStaticLayerParams" for the description and an example of the
* functionality of the layer.
*
* Requires 2 to 7 inputs and produces 1 output.
* Rank of the output is same as the rank of the first input unless squeezeMask
* is set.
*
* Value of beginIds, beginMasks, endIds, endMasks, strides can be passed in
* either as dynamic inputs or as static parameters. Lengths of all the
* parameters or inputs from 2-6 must equal the rank of the first input.
*
* The 2nd input represents the "beginIds".
* The 3rd input, if present, corresponds to "endIds". In this case the value of
* the "endIds" parameter is ignored. The 4th input, if present, corresponds to
* "strides". In this case the value of the "strides" parameter is ignored. The
* 5th input, if present, corresponds to "beginMasks". In this case the value of
* the "beginMasks" parameter is ignored. The 6th input, if present, corresponds
* to "endMasks". In this case the value of the "endMasks" parameter is ignored.
* The 7th input, if present, corresponds to "squeezeMasks". In this case the
* value of the "squeezeMasks" parameter is ignored.
*
*/
message SliceDynamicLayerParams {
repeated bool beginMasks = 2;
repeated int64 endIds = 3;
repeated bool endMasks = 4;
repeated int64 strides = 5;
repeated bool squeezeMasks = 6;
}
/*
* A layer that constructs a tensor by repeating the input tensor multiple
* number of times.
*
* Requires 1 or 2 inputs and produces 1 output.
* Output rank is same as the input rank.
*
* If two inputs are provided, second input is used as "reps"
* and "reps" parameter is ignored.
*
* If only one input is provided,
* length of the "reps" parameter must be at least 1 and
* not greater than the rank of the input.
* If it is less than the input rank, it is made equal to the input rank by
* prepending 1's to it.
*
* e.g.:
*
* input shape = (2, 4, 2)
* reps = (1, 2, 6)
* output shape = (2, 8, 12)
*
* input shape = (2, 4, 2)
* reps = (6)
* reps after prepending ones = (1, 1, 6)
* output shape = (2, 4, 12)
*
* input shape = (2, 4, 2)
* second input = [1, 2, 6] -> shape: (3,)
* reps = N/A [Ignored]
* output shape = (2, 8, 12)
*
*/
message TileLayerParams {
repeated uint64 reps = 1;
}
/*
* A layer that returns the shape of an input tensor.
*
* Requires 1 input and produces 1 output.
*
* Input: a tensor.
* Output: a vector of length R, where R is the rank of the input tensor
* Output is always a rank 1 tensor.
*/
message GetShapeLayerParams {}
/*
* A layer that computes the Gauss error function,
* which is defined as:
*
* .. math::
* f(x) = \dfrac{1}{\sqrt{\pi}}\int_{-x}^{x}{e^{-t^2}dt}
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*/
message ErfLayerParams {}
/*
* A layer that evaluates the Gaussian Error Linear Unit (GELU) activation.
* Following equations are used to compute the activation based on the value of
* the "mode" parameter:
*
* mode == 'EXACT':
* .. math::
* f(x) = 0.5x\left ( 1+\rm{erf}\left ( \frac{x}{\sqrt{2}} \right ) \right )
*
* mode == 'TANH_APPROXIMATION':
* .. math::
* f(x) = 0.5x\left ( 1+\rm{tanh}\left ( \sqrt{2/\pi}\left ( x + 0.044715x^3
* \right ) \right ) \right )
*
* mode == 'SIGMOID_APPROXIMATION':
* .. math::
* f(x) = x*\rm{sigmoid}(1.702x)
*
* Requires 1 input and produces 1 output.
* Output shape is same as the input.
*
*/
message GeluLayerParams {
enum GeluMode {
EXACT = 0;
TANH_APPROXIMATION = 1;
SIGMOID_APPROXIMATION = 2;
}
GeluMode mode = 1; // mode of GELU operation.
}
/*
* RangeStatic layer that returns a tensor that contains evenly spaced values.
* It is similar in functionality to the numpy.arange method.
*
* Requires no input and produces 1 output.
* Output is a rank 1 tensor.
*/
message RangeStaticLayerParams {
float endValue = 1;
float startValue = 2;
float stepSizeValue = 3;
}
/*
* A layer that returns a tensor that contains evenly spaced values.
* Its functionality is similar to the numpy.arange method.
*
* Requires at least 1 input, up to a maximum of 3 inputs.
* Produces 1 output, which is a rank 1 tensor.
*
* Each input must be a scalar, or rank 1 and shape (1,).
*
* The first input represents the "endValue".
* The second input, if present, corresponds to "startValue". In this case the
* value of the "startValue" parameter is ignored. The third input, if present,
* corresponds to "stepSizeValue". In this case the value of the "stepSizeValue"
* parameter is ignored.
*
*/
message RangeDynamicLayerParams {
float startValue = 2;
float stepSizeValue = 3;
}
/*
* A layer that returns a tensor containing all windows of size ``windowSize``
* separated by ``step`` along the dimension ``axis``.
*
* .. code::
*
* y = SlidingWindows(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* An N-Dimensional tensor.
*
* Output
* An (N+1)-Dimensional tensor.
*
* This operation behaves as following:
* - if axis = 0 & input is rank 1 (L,). Output shape will be (M, W).
* - if axis = 1 & input is rank 3 (B1, L, C1). Output shape will be (B1,
* M, W, C1)
* - if axis = 2 & input is rank 5 (B1, B2, L, C1, C2) --> (B1 * B2, L, C1
* * C2) --> (B1 * B2, M, W, C1 * C2). Output shape will be (B1, B2, M, W, C1,
* C2)
* - etc.
* where
* - L, C, B refer to input length, feature dimension length & batch size
* respectively
* - W is the window size.
* - M is the number of windows/slices calculated as M = (L - W) / step + 1
*/
message SlidingWindowsLayerParams {
int64 axis = 1;
uint64 windowSize = 2;
uint64 step = 3;
}
/*
* A layer that applies layer normalization over the input tensor.
*
* Requires 1 input and produces 1 output.
*
* output = gamma * (input - computed_mean) / (sqrt(computed_variance + eps)) +
* beta
*
* Parameters
* normalizedShape: subset of the input shape, along with layer norm is
* performed, rest of the input shape is treated as the batch dimension. The
* mean and variance are computed for the input, over the last few dimensions as
* specified by the normalizedShape parameter. gamma: must have shape =
* "normalizedShape" beta: must have shape = "normalizedShape" eps: small
* constant to avoid division by 0
*
* Output shape is same as the input.
*
* e.g.:
* input shape = (10,5)
* normalized shape = (5,) or (10,5)
*
* input shape = (10,5,6,7)
* normalized shape = (7,) or (6,7) or (5,6,7) or (10,5,6,7)
*/
message LayerNormalizationLayerParams {
repeated int64 normalizedShape = 1;
float eps = 2;
WeightParams gamma = 3;
WeightParams beta = 4;
}
/*
* Non maximum suppression (NMS) layer.
* Applies the non maximum suppression algorithm to input bounding box
* coordinates. The effect of this layer is similar to the functionality of the
* "NonMaximumSuppression" model type (for details please see
* NonMaximumSuppression.proto) with a couple of differences. One, this is a
* layer in a neural network model, whereas that is a different model type.
* Second, this layer supports a batch of bounding boxes.
*
* The NMS layer requires at least 2 inputs, and up to a maximum of 5 inputs. It
* produces 4 outputs. Following is the description of inputs and outputs:
*
* input 1, shape (B,N,4): coordinates of N boxes, for a batch size B.
* input 2, shape (B,N,C): class scores for each box. C can be 1 when there is
* only 1 score per box, i.e., no class specific score.
*
* input 3, optional, shape (1,): IoU threshold. When present, it overwrites the
* value provided in layer parameter "iouThreshold". input 4, optional, shape
* (1,): Score threshold. When present, it overwrites the value provided in
* layer parameter "scoreThreshold". input 5, optional, shape (1,): Maximum
* number of boxes. When present, it overwrites the value provided in layer
* parameter "maxBoxes".
*
* output 1, shape (B,maxBoxes,4): box coordinates, corresponding to the
* surviving boxes. output 2, shape (B,maxBoxes,C): box scores, corresponding to
* the surviving boxes. output 3, shape (B,maxBoxes): indices of the surviving
* boxes. Hence it will have values in the range [0,N-1], except for padding.
* output 4, shape (B,): number of boxes selected after the NMS algorithm, for
* each batch.
*
* When surviving boxes are less than "maxBoxes", the first 3 outputs are
* padded. For the first two outputs, the padding is done using values 0,
* whereas for the third output the padding value used is -1, since the output
* values represent indices.
*
* If no box survives, that is, all the scores are below the "scoreThreshold",
* then for that batch, number of boxes (value of the fourth output) will be 1.
* The first 3 outputs will correspond to the box with the highest score. This
* is to avoid generating an "empty" output.
*
* The four values that describe the box dimensions are (in order):
*
* - x (center location of the box along the horizontal axis)
* - y (center location of the box along the vertical axis)
* - width (size of box along the horizontal axis)
* - height (size of box on along the vertical axis)
*
* In each batch,
* the N scores for N boxes, used for suppression, are generated by taking the
* max of the matrix (N,C) along the columns. If "perClassSuppression" flag is
* false, suppression happens across all classes. If "perClassSuppression" flag
* is true, each box is assigned to the class with the highest score and then
* the suppression happens separately for boxes within the same class.
*
* Note that the 4th output can be used to dynamically slice the first 3
* outputs, in case the padded outputs are not required.
*
*/
message NonMaximumSuppressionLayerParams {
/*
* The intersection over union (IoU) threshold over which boxes are
* suppressed.
*/
float iouThreshold = 1;
/*
* Before IoU suppression is performed, boxes with class scores below this
* threshold are rejected.
*/
float scoreThreshold = 2;
/*
* The maximum number of boxes to be given out as output.
* If the number of surviving boxes are less, output is padded up to this
* number.
*/
uint64 maxBoxes = 3;
/*
* If true, suppression is performed independently within boxes of each class.
*/
bool perClassSuppression = 4;
}
/*
* A layer that performs element-wise clamped ReLU operation.
*
* Requires 1 input and produces 1 output.
*
* This function has the following formula:
*
* .. math::
* f(x) = \begin{cases}
* \text{min}(\text{beta},x) \;\; \text{if} \;\; x \geq 0\\
* \text{min}(\text{beta} ,\text{alpha}\cdot x) \;\; \text{if}
* \;\; x<0
* \end{cases}
*
* Output shape is same as the input.
*
* Available (iOS >= 14, macOS >= 11.0, watchOS >= 7)
*/
message ClampedReLULayerParams {
float alpha = 1;
float beta = 2;
}
/*
* A layer that returns the indices that would sort the input tensor, along a
* specified axis.
*
* Requires 1 input and produces 1 output.
*
* Output has the same rank and shape as the input.
*
* Value of "axis" must be positive and less than the rank of the input.
*
* e.g.:
*
* input shape = (5,)
* axis = 0
* input values = [3.1, 5.4, 32.9, 3.2, 77.0]
* output shape = (5,)
* output values = [0, 3, 1, 2, 4], descending = False
* output values = [4, 2, 1, 3, 0], descending = True
*
* input shape = (2,3)
* axis = 1
* input values = [[3, 5, 32], [3, 77, 6]]
* output shape = (2,3)
* output values = [[0, 1, 2], [0, 2, 1]], descending = False
* output values = [[2, 1, 0], [1, 2, 0]], descending = True
*
*/
message ArgSortLayerParams {
int64 axis = 1; // must be between [0, input_rank - 1]
bool descending = 2;
}
/*
* A layer that does slice operation by providing size to be extracted
* from the given input tensor.
*
* Requires 2 inputs and produces 1 output.
* Rank of the output is same as the rank of the first input.
*
* The 1st input represents the tensor to be sliced.
* The 2nd input represents the beginning index to be sliced from.
*
* Example:
* Input 1: x (x.shape = (2, 3, 4))
* Input 2: begin
* size: 2
* axis: 1
*
* Output: x[:, begin:begin+2, :]
*
*/
message SliceBySizeLayerParams {
int64 size = 2;
int64 axis = 3;
}
// Neural Network Specializations
// ------------------------------
/*
* A neural network specialized as a classifier.
*/
message NeuralNetworkClassifier {
repeated NeuralNetworkLayer layers = 1;
repeated NeuralNetworkPreprocessing preprocessing = 2;
// use this enum value to determine the input tensor shapes to the neural
// network, for multiarray inputs
NeuralNetworkMultiArrayShapeMapping arrayInputShapeMapping = 5;
// use this enum value to determine the input tensor shapes to the neural
// network, for image inputs
NeuralNetworkImageShapeMapping imageInputShapeMapping = 6;
NetworkUpdateParameters updateParams = 10;
// The set of labels for every possible class.
oneof ClassLabels {
StringVector stringClassLabels = 100;
Int64Vector int64ClassLabels = 101;
}
// The name of the output blob containing the probability of each class.
// In other words, the score vector. Must be a 1-D tensor with the same
// number and order of elements as ClassLabels.
string labelProbabilityLayerName = 200;
}
/*
* A layer that computes the one hot representation of the input.
*
* Requires 1 or 2 inputs and produces 1 output.
* Rank of the output is one more than the first input.
* If the second input is present, it is used to determine the value of
* "oneHotVectorSize" and the parameter "oneHotVectorSize" is ignored.
*
* Input values correspond to indices and should typically be in the range
* [0,"oneHotVectorSize" -1]. If it is outside this range, a vector of all
* "offValue" will be chosen.
*
* Typically one hot vectors contain 0s everywhere, except 1 at the index that
* the input corresponds to. However, instead of 0, any float value could be
* generated by using the "offValue" parameter. Similarly, instead of 1, any
* other value can be used by employing the "onValue" parameter.
*
* e.g.:
* input shape: (10,), "oneHotVectorSize" : 32, axis=-1, then output shape will
* be (10,32) input shape: (10,23), "oneHotVectorSize" : 32, axis=1, then output
* shape will be (10,32,23) input shape: (10,), "oneHotVectorSize" : 32, axis=0,
* then output shape will be (32,10)
*
* input shape: (2,), "oneHotVectorSize" : 4, axis=-1, then output shape will be
* (2,4) say input values = [2, 0], and "onValue" = 5, and "offValue" = -1, then
* output will be:
* [-1, -1, 5, -1
* 5, -1, -1, -1]
*
* say input values = [2, -1], and "onValue" = 5, and "offValue" = -1, then
* output will be:
* [-1, -1, 5, -1
* -1, -1, -1, -1]
*
* Available (iOS >= 14, macOS >= 11.0, watchOS >= 7)
*/
message OneHotLayerParams {
uint64 oneHotVectorSize = 1; // size of the one hot vector
int64 axis = 2; // negative indexing is supported. It refers to the axis in
// the output tensor.
float onValue = 3;
float offValue = 4;
}
/*
* A layer that computes the cumsum values of the input along a given axis.
*
* Requires 1 or 2 inputs and produces 1 output.
*
* Output shape and rank is same as the first input.
* If the second input is present, it is used to determine the value of "axis"
* and the parameter "axis" is ignored.
*
* e.g.:
* Input shape = (3,), values it has: [4, 6, 7]
*
* Then output values will be:
*
* if "excludeFinalSum" = False and "reverse" = False:
* output values : [4, 10, 17]
*
* if "excludeFinalSum" = True and "reverse" = False:
* output values : [0, 4, 10]
*
* if "excludeFinalSum" = False and "reverse" = True:
* output values : [17, 13, 7]
*
* if "excludeFinalSum" = True and "reverse" = True:
* output values : [13, 7, 0]
*
*
* Available (iOS >= 14, macOS >= 11.0, watchOS >= 7)
*/
message CumSumLayerParams {
int64 axis = 1; // negative indexing is supported
// if true, the first element of the output is 0, and the last element
// contains the sum of the input up to the penultimate value if false, the
// first element of the output is same as the input and the last element is
// the sum of all the input values (this behavior is reversed when "reverse"
// flag is True)
bool excludeFinalSum = 2;
bool reverse = 3; // if true, cumsum is performed in the opposite direction
}
/*
* A neural network specialized as a regressor.
*/
message NeuralNetworkRegressor {
repeated NeuralNetworkLayer layers = 1;
repeated NeuralNetworkPreprocessing preprocessing = 2;
// use this enum value to determine the input tensor shapes to the neural
// network, for multiarray inputs
NeuralNetworkMultiArrayShapeMapping arrayInputShapeMapping = 5;
// use this enum value to determine the input tensor shapes to the neural
// network, for image inputs
NeuralNetworkImageShapeMapping imageInputShapeMapping = 6;
NetworkUpdateParameters updateParams = 10;
}
// ---------------------------------------------------------
// On-device Training related messages
// ---------------------------------------------------------
/*
* Details on how the network will be updated
*/
message NetworkUpdateParameters {
repeated LossLayer lossLayers = 1;
Optimizer optimizer = 2;
Int64Parameter epochs = 3;
/*
* Describes whether to shuffle the batch of data between epochs.
*/
BoolParameter shuffle = 10;
/*
* The seed to be used in an associated random number generator.
*/
Int64Parameter seed = 20;
}
/*
* Loss layer - categorical cross entropy and mean squared error are the only
* supported loss functions currently
*/
message LossLayer {
string name = 1;
oneof LossLayerType {
CategoricalCrossEntropyLossLayer categoricalCrossEntropyLossLayer = 10;
MeanSquaredErrorLossLayer meanSquaredErrorLossLayer = 11;
}
}
/*
* Categorical cross entropy loss layer
* Categorical cross entropy is used for single label categorization (only one
* category is applicable for each data point).
*
* The input is a vector of length N representing the distribution over N
* categories. It must be the output of a softmax.
*
* The target is a single value representing the true category or class label.
* If the target is the predictedFeatureName of a neural network classifier it
* will be inverse mapped to the corresponding categorical index for you.
*
* math:
* Loss_{CCE}(input, target) = -\sum_{i=1}^{N} (target == i) log( input[i] ) = -
* log (input[target])
*/
message CategoricalCrossEntropyLossLayer {
string input = 1;
string target = 2;
}
/*
* Mean squared error loss layer,
* specifying input and target
*/
message MeanSquaredErrorLossLayer {
string input = 1;
string target = 2;
}
/*
* Optimizer - stochastic gradient descent and adam are the only supported
* optimizers currently
*/
message Optimizer {
oneof OptimizerType {
SGDOptimizer sgdOptimizer = 10;
AdamOptimizer adamOptimizer = 11;
}
}
/*
* Stochastic gradient descent optimizer,
* specifying configurable learning rate, mini batch size, and momentum
*/
message SGDOptimizer {
DoubleParameter learningRate = 1;
Int64Parameter miniBatchSize = 2;
DoubleParameter momentum = 3;
}
/*
* Adam optimizer,
* specifying configurable learning rate, mini batch size, betas, and eps
*/
message AdamOptimizer {
DoubleParameter learningRate = 1;
Int64Parameter miniBatchSize = 2;
DoubleParameter beta1 = 3;
DoubleParameter beta2 = 4;
DoubleParameter eps = 5;
}
|