{"id":324768,"date":"2021-06-11T09:00:43","date_gmt":"2021-06-11T09:00:43","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324768"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324768","title":{"rendered":"\u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u043c \u043d\u043e\u043c\u0435\u0440\u0430 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u0435\u0439. \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 multihead-\u043c\u043e\u0434\u0435\u043b\u0438 \u0432 Catalyst"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0424\u0438\u043a\u0441\u0430\u0446\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0439, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0440\u043e\u0437\u044b\u0441\u043a \u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u0435\u0439 \u2013 \u043b\u0438\u0448\u044c \u0447\u0430\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u043e\u043c\u0435\u0440 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044f (\u0433\u043e\u0441\u0443\u0434\u0430\u0440\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0437\u043d\u0430\u043a \u0438\u043b\u0438 \u0413\u0420\u0417).&nbsp;<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/catalyst-team\/catalyst\/\"><u>Catalyst<\/u><\/a> \u2013 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0434\u043b\u044f Pytorch. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u043e\u0434\u0430 \u2013 \u0446\u0438\u043a\u043b\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043c\u0435\u0442\u0440\u0438\u043a, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0447\u0435\u043a-\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u2013 \u0438 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/48d\/22b\/d5b\/48d22bd5bc89bac59e22d8405dd15541.png\" width=\"780\" height=\"440\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0443\u0442\u0435\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0438\u043b\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 image-to-text. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0432\u044b\u0445\u043e\u0434\u0430\u043c\u0438 (multihead-\u043c\u043e\u0434\u0435\u043b\u044c). \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0432\u043e\u0437\u044c\u043c\u0451\u043c <a href=\"https:\/\/nomeroff.net.ua\/datasets\/autoriaNumberplateOcrRu-2020-10-12.zip\"><u>\u0434\u0430\u0442\u0430\u0441\u0435\u0442<\/u><\/a> \u0441 \u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u043c\u0438 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/ria-com\/nomeroff-net\"><u>Nomeroff Net<\/u><\/a>. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438\u0437 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043d\u0430 \u0440\u0438\u0441. 1.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/24b\/10d\/c3b\/24b10dc3b2cfb33dd0751c1a71ff829e.png\" width=\"1200\" height=\"200\"><figcaption><\/figcaption><\/figure>\n<p><em>\u0420\u0438\u0441. 1. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438\u0437 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430<\/em>  <\/p>\n<h2>\u041e\u0431\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0413\u0420\u0417, \u0430 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u044d\u043a\u0441\u0442\u0440\u0430\u043a\u0442\u043e\u0440\u0430 \u0444\u0438\u0447\u0435\u0439 \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u201c\u0433\u043e\u043b\u043e\u0432\u201d. \u0412 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0413\u0420\u0417 \u0438\u0437 8 \u0438 9 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0433\u043e\u043b\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0432\u044f\u0442\u044c. \u041a\u0430\u0436\u0434\u0430\u044f \u0433\u043e\u043b\u043e\u0432\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b \u0438\u0437 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430 \u201c1234567890ABEKMHOPCTYX\u201d, \u043f\u043b\u044e\u0441 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u201c-\u201d (\u0434\u0435\u0444\u0438\u0441) \u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0434\u0435\u0432\u044f\u0442\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u0432 \u0432\u043e\u0441\u044c\u043c\u0438\u0437\u043d\u0430\u0447\u043d\u044b\u0445 \u0413\u0420\u0417. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0440\u0438\u0441. 2.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ec6\/04b\/d72\/ec604bd72ba81d78ac8c9ddc47803c44.png\" width=\"1200\" height=\"200\"><figcaption><\/figcaption><\/figure>\n<p><em>\u0420\u0438\u0441. 2. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043c\u043e\u0434\u0435\u043b\u0438<\/em>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 loss-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043e\u0437\u044c\u043c\u0451\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044e. \u0411\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0451 \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u043e\u043b\u043e\u0432\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u043b\u043e\u0441\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438. \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u2013 Adam. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0430\u043a\u0436\u0435 OneCycleLRWithWarmup \u043a\u0430\u043a \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a leraning rate. \u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430 \u2013 128. \u0414\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0432 10 \u044d\u043f\u043e\u0445.&nbsp;<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a \u0435\u0434\u0438\u043d\u043e\u043c\u0443 \u0440\u0430\u0437\u043c\u0435\u0440\u0443.<\/p>\n<h2>\u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0434\u0430. \u041a\u043b\u0430\u0441\u0441 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 (\u043b\u0438\u0441\u0442\u0438\u043d\u0433 1) \u0432 \u043e\u0431\u0449\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0434\u043b\u044f CV-\u0437\u0430\u0434\u0430\u0447 \u043d\u0430 Pytorch. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u0438\u0442 \u043b\u0438\u0448\u044c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0434\u043e\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0430\u0440\u0433\u0435\u0442\u0430. \u0412 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 <em>label_encoder<\/em> \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430 \u0432 \u0438\u0445 \u043a\u043e\u0434\u044b \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e. <\/p>\n<pre><code class=\"python\">class NpOcrDataset(Dataset):    def __init__(self, data_path, transform, label_encoder):        super().__init__()        self.data_path = data_path        self.image_fnames = glob.glob(os.path.join(data_path, \"img\", \"*.png\"))        self.transform = transform        self.label_encoder = label_encoder      def __len__(self):        return len(self.image_fnames)      def __getitem__(self, idx):        img_fname = self.image_fnames[idx]        img = cv2.imread(img_fname)        if self.transform:            transformed = self.transform(image=img)            img = transformed[\"image\"]        img = img.transpose(2, 0, 1)               label_fname = os.path.join(self.data_path, \"ann\",                                   os.path.basename(img_fname).replace(\".png\", \".json\"))        with open(label_fname, \"rt\") as label_file:            label_struct = json.load(label_file)            label = label_struct[\"description\"]        label = self.label_encoder.encode(label)          return img, [c for c in label]<\/code><\/pre>\n<p><em>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 1. \u041a\u043b\u0430\u0441\u0441 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430<\/em>  <\/p>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 (\u043b\u0438\u0441\u0442\u0438\u043d\u0433 2) \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/rwightman\/pytorch-image-models\"><u>PyTorch Image Models<\/u><\/a> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0441\u0442\u0440\u0430\u043a\u0442\u043e\u0440\u0430 \u0444\u0438\u0447\u0435\u0439. \u041a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0433\u043e\u043b\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <em>ModuleList<\/em>, \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0431\u044b\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0443. \u041b\u043e\u0433\u0438\u0442\u044b \u0441 \u0432\u044b\u0445\u043e\u0434\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0433\u043e\u043b\u043e\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u043c.<\/p>\n<pre><code class=\"python\">class MultiheadClassifier(nn.Module):    def __init__(self, backbone_name, backbone_pretrained, input_size, num_heads, num_classes):        super().__init__()          self.backbone = timm.create_model(backbone_name, backbone_pretrained, num_classes=0)        backbone_out_features_num = self.backbone(torch.randn(1, 3, input_size[1], input_size[0])).size(1)          self.heads = nn.ModuleList([            nn.Linear(backbone_out_features_num, num_classes) for _ in range(num_heads)        ])       def forward(self, x):        features = self.backbone(x)        logits = [head(features) for head in self.heads]        return logits<\/code><\/pre>\n<p><em>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 2. \u041a\u043b\u0430\u0441\u0441 \u043c\u043e\u0434\u0435\u043b\u0438<\/em>  <\/p>\n<p>\u0426\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u0432\u0435\u043d\u043e\u043c, \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <em>Runner<\/em>. \u041e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u043d\u0430\u0434 \u0446\u0438\u043a\u043b\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f-\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f multihead-\u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <em>handle_batch<\/em> \u0438 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <em>handle_batch<\/em>, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0431\u0430\u0442\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u044b \u0432 \u043d\u0451\u043c \u0431\u0443\u0434\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0430\u0442\u0447\u0430, \u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u2013 \u0440\u0430\u0441\u0447\u0451\u0442 \u043b\u043e\u0441\u0441\u0430, \u043c\u0435\u0442\u0440\u0438\u043a \u0438 \u0442.\u0434. \u2013 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432. \u041a\u043e\u0434 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3.<\/p>\n<pre><code class=\"python\">class MultiheadClassificationRunner(dl.Runner):    def __init__(self, num_heads, *args, **kwargs):        super().__init__(*args, **kwargs)        self.num_heads = num_heads      def handle_batch(self, batch):        x, targets = batch        logits = self.model(x)               batch_dict = { \"features\": x }        for i in range(self.num_heads):            batch_dict[f\"targets{i}\"] = targets[i]        for i in range(self.num_heads):            batch_dict[f\"logits{i}\"] = logits[i]               self.batch = batch_dict<\/code><\/pre>\n<p><em>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f runner\u2019\u0430<\/em>  <\/p>\n<p>\u041a\u043e\u043b\u0431\u044d\u043a\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:  <\/p>\n<ul>\n<li>\n<p><em>CriterionCallback<\/em> \u2013 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043b\u043e\u0441\u0441\u0430. \u041d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0433\u043e\u043b\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><em>MetricAggregationCallback<\/em> \u2013 \u0434\u043b\u044f \u0430\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u0438 \u043b\u043e\u0441\u0441\u043e\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0433\u043e\u043b\u043e\u0432 \u0432 \u0435\u0434\u0438\u043d\u044b\u0439 \u043b\u043e\u0441\u0441 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><em>OptimizerCallback<\/em> \u2013 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><em>SchedulerCallback<\/em> \u2013 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 LR Scheduler\u2019\u0430.<\/p>\n<\/li>\n<li>\n<p><em>AccuracyCallback<\/em> \u2013 \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0433\u043e\u043b\u043e\u0432 \u0432 \u0445\u043e\u0434\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><em>CheckpointCallback<\/em> \u2013 \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0435 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0434, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 4.  <\/p>\n<pre><code class=\"python\">def get_runner_callbacks(num_heads, num_classes_per_head, class_names, logdir):    cbs = [        *[            dl.CriterionCallback(                metric_key=f\"loss{i}\",                input_key=f\"logits{i}\",                target_key=f\"targets{i}\"            )            for i in range(num_heads)        ],        dl.MetricAggregationCallback(            metric_key=\"loss\",            metrics=[f\"loss{i}\" for i in range(num_heads)],            mode=\"mean\"        ),        dl.OptimizerCallback(metric_key=\"loss\"),        dl.SchedulerCallback(),        *[            dl.AccuracyCallback(                input_key=f\"logits{i}\",                target_key=f\"targets{i}\",                num_classes=num_classes_per_head,                suffix=f\"{i}\"            )            for i in range(num_heads)        ],        dl.CheckpointCallback(            logdir=os.path.join(logdir, \"checkpoints\"),            loader_key=\"valid\",            metric_key=\"loss\",            minimize=True,            save_n_best=1        )    ]       return cbs<\/code><\/pre>\n<p><em>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 4. \u041a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432<\/em><\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0434\u043b\u044f Pytorch \u0438 Catalyst, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u043c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u0445 \u0437\u0434\u0435\u0441\u044c. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a \u0441\u0442\u0430\u0442\u044c\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d <a href=\"https:\/\/github.com\/articles-simbirsoft\/lp_ocr_multihead\"><u>\u043d\u0430 GitHub<\/u><\/a>.<\/p>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430<\/h2>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/559\/ccf\/119\/559ccf119b5491cbed8c993e2f24762a.png\" width=\"1200\" height=\"432\"><figcaption><\/figcaption><\/figure>\n<p><em>\u0420\u0438\u0441. 3. \u0413\u0440\u0430\u0444\u0438\u043a \u043b\u043e\u0441\u0441-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u0440\u0430\u043d\u0436\u0435\u0432\u0430\u044f \u043b\u0438\u043d\u0438\u044f \u2013 train loss, \u0441\u0438\u043d\u044f\u044f \u2013 valid loss<\/em>  <\/p>\n<p>\u0412 \u0441\u043f\u0438\u0441\u043a\u0435 \u043d\u0438\u0436\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0430 \u043d\u0430 \u0442\u0435\u0441\u0442-\u0441\u0435\u0442\u0435:  <\/p>\n<ul>\n<li>\n<p>Incorrect prediction: T970XT23- instead of T970XO123<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: X399KT161 instead of X359KT163<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: E166EP133 instead of E166EP123<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: X225YY96- instead of X222BY96-<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: X125KX11- instead of X125KX14-<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: X365PC17- instead of X365PC178<\/p>\n<\/li>\n<\/ul>\n<p>\u0417\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0442\u0438\u043f\u044b: \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u043a\u0432\u044b \u0438 \u0446\u0438\u0444\u0440\u044b \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0413\u0420\u0417, \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0435 \u0446\u0438\u0444\u0440\u044b \u043a\u043e\u0434\u0430 \u0440\u0435\u0433\u0438\u043e\u043d\u0430, \u043b\u0438\u0448\u043d\u044f\u044f \u0446\u0438\u0444\u0440\u0430 \u0432 \u043a\u043e\u0434\u0435 \u0440\u0435\u0433\u0438\u043e\u043d\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0432\u0435\u0440\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0446\u0438\u0444\u0440\u044b.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 multihead-\u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0413\u0420\u0417 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 Catalyst. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u043d\u043d\u0435\u0440 \u0438 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432 \u0434\u043b\u044f \u043d\u0435\u0433\u043e. \u041c\u043e\u0434\u0435\u043b\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0431\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<p><strong>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041d\u0430\u0434\u0435\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043d\u0430\u0448 \u043e\u043f\u044b\u0442 \u0431\u044b\u043b \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u0435\u043d.&nbsp;<\/strong><\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0430\u0448\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c\u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/529580\/\"><u>Data Science: \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/u><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/501882\/\"><u>\u041a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0437\u0440\u0435\u043d\u0438\u044f: \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0438\u0434\u0435\u043e \u0432 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u043c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OpenCV.js<\/u><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/529580\/\"><u>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u0443\u044e \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044e \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430<\/u><\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/561866\/\"> https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/561866\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0424\u0438\u043a\u0441\u0430\u0446\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0439, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0440\u043e\u0437\u044b\u0441\u043a \u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u0435\u0439 \u2013 \u043b\u0438\u0448\u044c \u0447\u0430\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u043e\u043c\u0435\u0440 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u044f (\u0433\u043e\u0441\u0443\u0434\u0430\u0440\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0437\u043d\u0430\u043a \u0438\u043b\u0438 \u0413\u0420\u0417).&nbsp;<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/catalyst-team\/catalyst\/\"><u>Catalyst<\/u><\/a> \u2013 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0434\u043b\u044f Pytorch. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u043e\u0434\u0430 \u2013 \u0446\u0438\u043a\u043b\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043c\u0435\u0442\u0440\u0438\u043a, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0447\u0435\u043a-\u043f\u043e\u0438\u043d\u0442\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u2013 \u0438 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0435.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0443\u0442\u0435\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0438\u043b\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 image-to-text. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0432\u044b\u0445\u043e\u0434\u0430\u043c\u0438 (multihead-\u043c\u043e\u0434\u0435\u043b\u044c). \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u0432\u043e\u0437\u044c\u043c\u0451\u043c <a href=\"https:\/\/nomeroff.net.ua\/datasets\/autoriaNumberplateOcrRu-2020-10-12.zip\"><u>\u0434\u0430\u0442\u0430\u0441\u0435\u0442<\/u><\/a> \u0441 \u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u0438\u043c\u0438 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/ria-com\/nomeroff-net\"><u>Nomeroff Net<\/u><\/a>. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438\u0437 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043d\u0430 \u0440\u0438\u0441. 1.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><em>\u0420\u0438\u0441. 1. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438\u0437 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430<\/em>  <\/p>\n<h2>\u041e\u0431\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0413\u0420\u0417, \u0430 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u044d\u043a\u0441\u0442\u0440\u0430\u043a\u0442\u043e\u0440\u0430 \u0444\u0438\u0447\u0435\u0439 \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u201c\u0433\u043e\u043b\u043e\u0432\u201d. \u0412 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0413\u0420\u0417 \u0438\u0437 8 \u0438 9 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0433\u043e\u043b\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0432\u044f\u0442\u044c. \u041a\u0430\u0436\u0434\u0430\u044f \u0433\u043e\u043b\u043e\u0432\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b \u0438\u0437 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430 \u201c1234567890ABEKMHOPCTYX\u201d, \u043f\u043b\u044e\u0441 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u201c-\u201d (\u0434\u0435\u0444\u0438\u0441) \u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0434\u0435\u0432\u044f\u0442\u043e\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u0432 \u0432\u043e\u0441\u044c\u043c\u0438\u0437\u043d\u0430\u0447\u043d\u044b\u0445 \u0413\u0420\u0417. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0441\u0445\u0435\u043c\u0430\u0442\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0440\u0438\u0441. 2.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><em>\u0420\u0438\u0441. 2. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043c\u043e\u0434\u0435\u043b\u0438<\/em>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 loss-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043e\u0437\u044c\u043c\u0451\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044e. \u0411\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0451 \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u043e\u043b\u043e\u0432\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u043b\u043e\u0441\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438. \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u2013 Adam. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u0430\u043a\u0436\u0435 OneCycleLRWithWarmup \u043a\u0430\u043a \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a leraning rate. \u0420\u0430\u0437\u043c\u0435\u0440 \u0431\u0430\u0442\u0447\u0430 \u2013 128. \u0414\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0432 10 \u044d\u043f\u043e\u0445.&nbsp;<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a \u0435\u0434\u0438\u043d\u043e\u043c\u0443 \u0440\u0430\u0437\u043c\u0435\u0440\u0443.<\/p>\n<h2>\u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0434\u0430. \u041a\u043b\u0430\u0441\u0441 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 (\u043b\u0438\u0441\u0442\u0438\u043d\u0433 1) \u0432 \u043e\u0431\u0449\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0434\u043b\u044f CV-\u0437\u0430\u0434\u0430\u0447 \u043d\u0430 Pytorch. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u0438\u0442 \u043b\u0438\u0448\u044c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0434\u043e\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0430\u0440\u0433\u0435\u0442\u0430. \u0412 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 <em>label_encoder<\/em> \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043c\u0435\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u0430 \u0432 \u0438\u0445 \u043a\u043e\u0434\u044b \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e. <\/p>\n<pre><code class=\"python\">class NpOcrDataset(Dataset):    def __init__(self, data_path, transform, label_encoder):        super().__init__()        self.data_path = data_path        self.image_fnames = glob.glob(os.path.join(data_path, \"img\", \"*.png\"))        self.transform = transform        self.label_encoder = label_encoder      def __len__(self):        return len(self.image_fnames)      def __getitem__(self, idx):        img_fname = self.image_fnames[idx]        img = cv2.imread(img_fname)        if self.transform:            transformed = self.transform(image=img)            img = transformed[\"image\"]        img = img.transpose(2, 0, 1)               label_fname = os.path.join(self.data_path, \"ann\",                                   os.path.basename(img_fname).replace(\".png\", \".json\"))        with open(label_fname, \"rt\") as label_file:            label_struct = json.load(label_file)            label = label_struct[\"description\"]        label = self.label_encoder.encode(label)          return img, [c for c in label]<\/code><\/pre>\n<p><em>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 1. \u041a\u043b\u0430\u0441\u0441 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430<\/em>  <\/p>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 (\u043b\u0438\u0441\u0442\u0438\u043d\u0433 2) \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/rwightman\/pytorch-image-models\"><u>PyTorch Image Models<\/u><\/a> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0441\u0442\u0440\u0430\u043a\u0442\u043e\u0440\u0430 \u0444\u0438\u0447\u0435\u0439. \u041a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0433\u043e\u043b\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <em>ModuleList<\/em>, \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0431\u044b\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0443. \u041b\u043e\u0433\u0438\u0442\u044b \u0441 \u0432\u044b\u0445\u043e\u0434\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0433\u043e\u043b\u043e\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u043c.<\/p>\n<pre><code class=\"python\">class MultiheadClassifier(nn.Module):    def __init__(self, backbone_name, backbone_pretrained, input_size, num_heads, num_classes):        super().__init__()          self.backbone = timm.create_model(backbone_name, backbone_pretrained, num_classes=0)        backbone_out_features_num = self.backbone(torch.randn(1, 3, input_size[1], input_size[0])).size(1)          self.heads = nn.ModuleList([            nn.Linear(backbone_out_features_num, num_classes) for _ in range(num_heads)        ])       def forward(self, x):        features = self.backbone(x)        logits = [head(features) for head in self.heads]        return logits<\/code><\/pre>\n<p><em>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 2. \u041a\u043b\u0430\u0441\u0441 \u043c\u043e\u0434\u0435\u043b\u0438<\/em>  <\/p>\n<p>\u0426\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u0432\u0435\u043d\u043e\u043c, \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u043c \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <em>Runner<\/em>. \u041e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u043d\u0430\u0434 \u0446\u0438\u043a\u043b\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f-\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f multihead-\u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <em>handle_batch<\/em> \u0438 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <em>handle_batch<\/em>, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0431\u0430\u0442\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u044b \u0432 \u043d\u0451\u043c \u0431\u0443\u0434\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0430\u0442\u0447\u0430, \u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u2013 \u0440\u0430\u0441\u0447\u0451\u0442 \u043b\u043e\u0441\u0441\u0430, \u043c\u0435\u0442\u0440\u0438\u043a \u0438 \u0442.\u0434. \u2013 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432. \u041a\u043e\u0434 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3.<\/p>\n<pre><code class=\"python\">class MultiheadClassificationRunner(dl.Runner):    def __init__(self, num_heads, *args, **kwargs):        super().__init__(*args, **kwargs)        self.num_heads = num_heads      def handle_batch(self, batch):        x, targets = batch        logits = self.model(x)               batch_dict = { \"features\": x }        for i in range(self.num_heads):            batch_dict[f\"targets{i}\"] = targets[i]        for i in range(self.num_heads):            batch_dict[f\"logits{i}\"] = logits[i]               self.batch = batch_dict<\/code><\/pre>\n<p><em>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f runner\u2019\u0430<\/em>  <\/p>\n<p>\u041a\u043e\u043b\u0431\u044d\u043a\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:  <\/p>\n<ul>\n<li>\n<p><em>CriterionCallback<\/em> \u2013 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043b\u043e\u0441\u0441\u0430. \u041d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0433\u043e\u043b\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><em>MetricAggregationCallback<\/em> \u2013 \u0434\u043b\u044f \u0430\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u0438 \u043b\u043e\u0441\u0441\u043e\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0433\u043e\u043b\u043e\u0432 \u0432 \u0435\u0434\u0438\u043d\u044b\u0439 \u043b\u043e\u0441\u0441 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><em>OptimizerCallback<\/em> \u2013 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><em>SchedulerCallback<\/em> \u2013 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 LR Scheduler\u2019\u0430.<\/p>\n<\/li>\n<li>\n<p><em>AccuracyCallback<\/em> \u2013 \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0433\u043e\u043b\u043e\u0432 \u0432 \u0445\u043e\u0434\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p><em>CheckpointCallback<\/em> \u2013 \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u0435 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0434, \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 4.  <\/p>\n<pre><code class=\"python\">def get_runner_callbacks(num_heads, num_classes_per_head, class_names, logdir):    cbs = [        *[            dl.CriterionCallback(                metric_key=f\"loss{i}\",                input_key=f\"logits{i}\",                target_key=f\"targets{i}\"            )            for i in range(num_heads)        ],        dl.MetricAggregationCallback(            metric_key=\"loss\",            metrics=[f\"loss{i}\" for i in range(num_heads)],            mode=\"mean\"        ),        dl.OptimizerCallback(metric_key=\"loss\"),        dl.SchedulerCallback(),        *[            dl.AccuracyCallback(                input_key=f\"logits{i}\",                target_key=f\"targets{i}\",                num_classes=num_classes_per_head,                suffix=f\"{i}\"            )            for i in range(num_heads)        ],        dl.CheckpointCallback(            logdir=os.path.join(logdir, \"checkpoints\"),            loader_key=\"valid\",            metric_key=\"loss\",            minimize=True,            save_n_best=1        )    ]       return cbs<\/code><\/pre>\n<p><em>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 4. \u041a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432<\/em><\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0434\u043b\u044f Pytorch \u0438 Catalyst, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u043c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u0445 \u0437\u0434\u0435\u0441\u044c. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a \u0441\u0442\u0430\u0442\u044c\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d <a href=\"https:\/\/github.com\/articles-simbirsoft\/lp_ocr_multihead\"><u>\u043d\u0430 GitHub<\/u><\/a>.<\/p>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430<\/h2>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><em>\u0420\u0438\u0441. 3. \u0413\u0440\u0430\u0444\u0438\u043a \u043b\u043e\u0441\u0441-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u0440\u0430\u043d\u0436\u0435\u0432\u0430\u044f \u043b\u0438\u043d\u0438\u044f \u2013 train loss, \u0441\u0438\u043d\u044f\u044f \u2013 valid loss<\/em>  <\/p>\n<p>\u0412 \u0441\u043f\u0438\u0441\u043a\u0435 \u043d\u0438\u0436\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0430 \u043d\u0430 \u0442\u0435\u0441\u0442-\u0441\u0435\u0442\u0435:  <\/p>\n<ul>\n<li>\n<p>Incorrect prediction: T970XT23- instead of T970XO123<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: X399KT161 instead of X359KT163<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: E166EP133 instead of E166EP123<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: X225YY96- instead of X222BY96-<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: X125KX11- instead of X125KX14-<\/p>\n<\/li>\n<li>\n<p>Incorrect prediction: X365PC17- instead of X365PC178<\/p>\n<\/li>\n<\/ul>\n<p>\u0417\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0442\u0438\u043f\u044b: \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u043a\u0432\u044b \u0438 \u0446\u0438\u0444\u0440\u044b \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0413\u0420\u0417, \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0435 \u0446\u0438\u0444\u0440\u044b \u043a\u043e\u0434\u0430 \u0440\u0435\u0433\u0438\u043e\u043d\u0430, \u043b\u0438\u0448\u043d\u044f\u044f \u0446\u0438\u0444\u0440\u0430 \u0432 \u043a\u043e\u0434\u0435 \u0440\u0435\u0433\u0438\u043e\u043d\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u0432\u0435\u0440\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0446\u0438\u0444\u0440\u044b.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 multihead-\u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0413\u0420\u0417 \u0430\u0432\u0442\u043e\u043c\u043e\u0431\u0438\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 Catalyst. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u043d\u043d\u0435\u0440 \u0438 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u043b\u0431\u044d\u043a\u043e\u0432 \u0434\u043b\u044f \u043d\u0435\u0433\u043e. \u041c\u043e\u0434\u0435\u043b\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043e\u0431\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<p><strong>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041d\u0430\u0434\u0435\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043d\u0430\u0448 \u043e\u043f\u044b\u0442 \u0431\u044b\u043b \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u0435\u043d.&nbsp;<\/strong><\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0430\u0448\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c\u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/529580\/\"><u>Data Science: \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/u><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/501882\/\"><u>\u041a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0437\u0440\u0435\u043d\u0438\u044f: \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0438\u0434\u0435\u043e \u0432 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u043c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OpenCV.js<\/u><\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/529580\/\"><u>\u0422\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0440\u043d\u0443\u044e \u043a\u0440\u043e\u0441\u0441-\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044e \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430<\/u><\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/561866\/\"> https:\/\/habr.com\/ru\/company\/simbirsoft\/blog\/561866\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-324768","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324768","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=324768"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324768\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}