{"id":297796,"date":"2020-01-28T09:00:26","date_gmt":"2020-01-28T09:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297796"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297796","title":{"rendered":"\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u043e\u0442\u043e \u0432 \u043a\u043e\u043c\u0438\u043a\u0441. \u0427\u0430\u0441\u0442\u044c \u0442\u0440\u0435\u0442\u044c\u044f. Serverless GPU \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u043c\u043e\u0434\u0435\u043b\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/485824\/\">\n<p><a href=\"https:\/\/habr.com\/ru\/post\/479218\/\">-&gt; \u0427\u0430\u0441\u0442\u044c 1<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/483168\/\">-&gt; \u0427\u0430\u0441\u0442\u044c 2<\/a><\/p>\n<p>  <\/p>\n<p>\u041d\u0443, \u043e\u0442\u0434\u043e\u0445\u043d\u0443\u043b\u0438 \u0438 \u0445\u0432\u0430\u0442\u0438\u0442. \u0421 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c! <\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0435\u0440\u0438\u044f\u0445 \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0431\u0443\u0447\u0438\u043b\u0438 \u0441\u0432\u043e\u044e \u043f\u0435\u0440\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c.<br \/>  \u0417\u0430\u0442\u0435\u043c, \u0443\u0436\u0430\u0441\u043d\u0443\u0432\u0448\u0438\u0441\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c, \u043e\u0431\u0443\u0447\u0438\u043b\u0438 \u0435\u0449\u0435 \u0441 \u0434\u0435\u0441\u044f\u0442\u043e\u043a.<br \/>  \u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u0448\u0435 \u0442\u0432\u043e\u0440\u0435\u043d\u0438\u0435 \u043c\u0438\u0440\u0443!<a name=\"habracut\"><\/a><\/p>\n<p>  <\/p>\n<h2 id=\"eksport-modeli\">\u042d\u043a\u0441\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0435\u043b\u0438<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0435\u0440\u0435\u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0432 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0444\u043e\u0440\u043c\u0430\u0442, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0442\u0430\u0449\u0438\u0442\u044c \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0430 \u0445\u043e\u0441\u0442\u0438\u043d\u0433.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0430\u0439\u043b\u0438\u043a \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c *.py \u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043a\u043e\u0434 \u0438\u0437-\u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u0430 \u043d\u0438\u0436\u0435.<br \/>  \u041f\u0443\u0441\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 jit.py:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u0437\u0434\u0443\u043c\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u0442\u044c, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 path, output_path \u043d\u0430 \u0441\u0432\u043e\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u0417\u0430\u043c\u0435\u043d\u044f\u0435\u043c path \u043d\u0430 \u043f\u0443\u0442\u044c \u043a \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 # \u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0444\u0430\u0439\u043b *G_A.pth - \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0444\u043e\u0442\u043e -&gt; \u043a\u043e\u043c\u0438\u043a\u0441 # output_path - \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 # \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u043c \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c *.jit, \u0433\u043b\u0430\u0432\u043d\u043e\u0435 - \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c, \u043a\u0443\u0434\u0430 \u043c\u044b \u0435\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438  path= '\/checkpoints\/resnet9_nowd_nodo_128to400_c8\/60_net_G_A.pth' output_path ='\/checkpoints\/resnet9_nowd_nodo_128to400_c8\/resnet9_nowd_nodo_128to400_c8_160-50-60_1.jit'  import torch from torch import nn  class ResnetGenerator(nn.Module):     &quot;&quot;&quot;Resnet-based generator that consists of Resnet blocks between a few downsampling\/upsampling operations.      We adapt Torch code and idea from Justin Johnson's neural style transfer project(https:\/\/github.com\/jcjohnson\/fast-neural-style)     &quot;&quot;&quot;      def __init__(self, input_nc, output_nc, ngf=64, norm_layer=nn.BatchNorm2d, use_dropout=False, n_blocks=6, padding_type='reflect'):         &quot;&quot;&quot;Construct a Resnet-based generator          Parameters:             input_nc (int)      -- the number of channels in input images             output_nc (int)     -- the number of channels in output images             ngf (int)           -- the number of filters in the last conv layer             norm_layer          -- normalization layer             use_dropout (bool)  -- if use dropout layers             n_blocks (int)      -- the number of ResNet blocks             padding_type (str)  -- the name of padding layer in conv layers: reflect | replicate | zero         &quot;&quot;&quot;         assert(n_blocks &gt;= 0)         super(ResnetGenerator, self).__init__()         if type(norm_layer) == functools.partial:             use_bias = norm_layer.func == nn.InstanceNorm2d         else:             use_bias = norm_layer == nn.InstanceNorm2d          model = [nn.ReflectionPad2d(3),                  nn.Conv2d(input_nc, ngf, kernel_size=7, padding=0, bias=use_bias),                  norm_layer(ngf),                  nn.ReLU(True)]          n_downsampling = 2         for i in range(n_downsampling):  # add downsampling layers             mult = 2 ** i             model += [nn.Conv2d(ngf * mult, ngf * mult * 2, kernel_size=3, stride=2, padding=1, bias=use_bias),                       norm_layer(ngf * mult * 2),                       nn.ReLU(True)]          mult = 2 ** n_downsampling         for i in range(n_blocks):       # add ResNet blocks              model += [ResnetBlock(ngf * mult, padding_type=padding_type, norm_layer=norm_layer, use_dropout=use_dropout, use_bias=use_bias)]          for i in range(n_downsampling):  # add upsampling layers             mult = 2 ** (n_downsampling - i)             model += [nn.ConvTranspose2d(ngf * mult, int(ngf * mult \/ 2),                                          kernel_size=3, stride=2,                                          padding=1, output_padding=1,                                          bias=use_bias),                       norm_layer(int(ngf * mult \/ 2)),                       nn.ReLU(True)]         model += [nn.ReflectionPad2d(3)]         model += [nn.Conv2d(ngf, output_nc, kernel_size=7, padding=0)]         model += [nn.Tanh()]          self.model = nn.Sequential(*model)      def forward(self, input):         &quot;&quot;&quot;Standard forward&quot;&quot;&quot;         return self.model(input)  class ResnetBlock(nn.Module):     &quot;&quot;&quot;Define a Resnet block&quot;&quot;&quot;      def __init__(self, dim, padding_type, norm_layer, use_dropout, use_bias):         &quot;&quot;&quot;Initialize the Resnet block          A resnet block is a conv block with skip connections         We construct a conv block with build_conv_block function,         and implement skip connections in &lt;forward&gt; function.         Original Resnet paper: https:\/\/arxiv.org\/pdf\/1512.03385.pdf         &quot;&quot;&quot;         super(ResnetBlock, self).__init__()         self.conv_block = self.build_conv_block(dim, padding_type, norm_layer, use_dropout, use_bias)      def build_conv_block(self, dim, padding_type, norm_layer, use_dropout, use_bias):         &quot;&quot;&quot;Construct a convolutional block.          Parameters:             dim (int)           -- the number of channels in the conv layer.             padding_type (str)  -- the name of padding layer: reflect | replicate | zero             norm_layer          -- normalization layer             use_dropout (bool)  -- if use dropout layers.             use_bias (bool)     -- if the conv layer uses bias or not          Returns a conv block (with a conv layer, a normalization layer, and a non-linearity layer (ReLU))         &quot;&quot;&quot;         conv_block = []         p = 0         if padding_type == 'reflect':             conv_block += [nn.ReflectionPad2d(1)]         elif padding_type == 'replicate':             conv_block += [nn.ReplicationPad2d(1)]         elif padding_type == 'zero':             p = 1         else:             raise NotImplementedError('padding [%s] is not implemented' % padding_type)          conv_block += [nn.Conv2d(dim, dim, kernel_size=3, padding=p, bias=use_bias), norm_layer(dim), nn.ReLU(True)]         if use_dropout:             conv_block += [nn.Dropout(0.5)]          p = 0         if padding_type == 'reflect':             conv_block += [nn.ReflectionPad2d(1)]         elif padding_type == 'replicate':             conv_block += [nn.ReplicationPad2d(1)]         elif padding_type == 'zero':             p = 1         else:             raise NotImplementedError('padding [%s] is not implemented' % padding_type)         conv_block += [nn.Conv2d(dim, dim, kernel_size=3, padding=p, bias=use_bias), norm_layer(dim)]          return nn.Sequential(*conv_block)      def forward(self, x):         &quot;&quot;&quot;Forward function (with skip connections)&quot;&quot;&quot;         out = x + self.conv_block(x)  # add skip connections         return out  import functools  norm_layer = functools.partial(nn.InstanceNorm2d, affine=False, track_running_stats=False)  model = ResnetGenerator(3,3,64, norm_layer=norm_layer, use_dropout=False, n_blocks=9)  model.load_state_dict(torch.load(path)) model.eval() model.cuda() model.half()  trace_input = torch.ones(1,3,256,256).cuda() model = model.eval() jit_model = torch.jit.trace(model.float(), trace_input)  torch.jit.save(jit_model, output_path)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u0417\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 \u0441\u0432\u043e\u0438: <\/p>\n<p>  <\/p>\n<ul>\n<li><strong>path<\/strong> \u2014 \u043f\u0443\u0442\u044c \u043a \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438.<br \/>  \u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0444\u0430\u0439\u043b *G_A.pth \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0444\u043e\u0442\u043e -&gt; \u043a\u043e\u043c\u0438\u043a\u0441.<\/li>\n<li><strong>output_path<\/strong> \u2014 \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u043c, \u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435\u043c *.jit, \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c, \u043a\u0443\u0434\u0430 \u043c\u044b \u0435\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<blockquote><p>\u041d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u044d\u043f\u043e\u0445\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0432\u043e\u0437\u044c\u043c\u0438\u0442\u0435 \u0442\u043e\u0442, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u0432\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e. <\/p><\/blockquote>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 \u0441 \u043d\u0430\u0448\u0438\u043c \u0444\u0430\u0439\u043b\u043e\u043c \u0438 \u043f\u0438\u0448\u0435\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">python jit.py <\/code><\/pre>\n<p>  <\/p>\n<p>Voila! \u041c\u043e\u0434\u0435\u043b\u044c \u0433\u043e\u0442\u043e\u0432\u0430 \u043a \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0443 \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043c\u0438\u0440\u043e\u043c. <\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e torch jit<\/b><\/p>\n<div class=\"spoiler_text\">\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f: <a href=\"https:\/\/pytorch.org\/docs\/stable\/jit.html\" rel=\"nofollow\">https:\/\/pytorch.org\/docs\/stable\/jit.html<\/a><br \/>  \u0415\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u043a\u0440\u0430\u0442\u043a\u0438\u043c, \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0432 jit \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043d\u0435 \u0442\u0430\u0449\u0438\u0442\u044c \u0437\u0430 \u0441\u043e\u0431\u043e\u0439 \u0441\u0440\u0435\u0434\u0443 python, \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0430 \u043c\u043e\u0433\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041a\u0440\u043e\u043c\u0435 torch, \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f.<br \/>  \u0425\u043e\u0442\u044c \u043c\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u0445\u043e\u0441\u0442\u0438\u0442\u044c \u0435\u0435 \u0432 python-\u0441\u0440\u0435\u0434\u0435, jit-\u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. <\/p>\n<\/div>\n<\/div>\n<p>  <\/p>\n<h2 id=\"vybor-hostinga\">\u0412\u044b\u0431\u043e\u0440 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0430<\/h2>\n<p>  <\/p>\n<blockquote><p>\u0411\u0443\u0434\u0443 \u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043a\u0440\u043e\u0432\u0435\u043d\u0435\u043d \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u044e\u0441\u044c: \u043c\u043e\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 deep learning enthusiast \u043f\u043e\u0433\u0438\u0431 \u0433\u0434\u0435-\u0442\u043e \u043d\u0430 \u0432\u0442\u043e\u0440\u043e\u043c \u0447\u0430\u0441\u0443 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433\u0430 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 GPU. \u0422\u0430\u043a \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0435\u0442 \u043c\u043d\u0435 \u043d\u0435\u0434\u043e\u0440\u043e\u0433\u043e\u0439 Serverless GPU \u0445\u043e\u0441\u0442\u0438\u043d\u0433, \u044f \u0431\u0443\u0434\u0443 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u0435\u043b\u0435\u043d.<\/p><\/blockquote>\n<p>\u041f\u043b\u0430\u0442\u0438\u0442\u044c \u0437\u0430 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u044f \u043d\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043a\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e serverless \u0440\u0435\u0448\u0435\u043d\u0438\u044f. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043c\u0443\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043f\u043e\u043b\u0437\u043d\u043e\u0432\u0435\u043d\u0438\u0439 \u043f\u043e \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u043c \u0442\u0430\u0440\u0438\u0444\u043d\u044b\u043c \u043f\u043b\u0430\u043d\u0430\u043c \u0433\u0443\u0433\u043b\u0430 \u0438 \u0430\u043c\u0430\u0437\u043e\u043d\u0430 \u043c\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 algorithmia.com<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e: <\/p>\n<p>  <\/p>\n<ul>\n<li>\n<p><strong>Web IDE<\/strong> \u2014 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0434\u043b\u044f \u0447\u0430\u0439\u043d\u0438\u043a\u043e\u0432, \u0445\u043e\u0442\u044c \u0438 \u0436\u0443\u0442\u043a\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0436\u0434\u0430\u0442\u044c \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0431\u0438\u043b\u0434\u0430. \u0412\u043d\u0435 \u0440\u0430\u043c\u043e\u043a \u044d\u0442\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u044f \u0431\u044b \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432. <\/p>\n<p>  <\/li>\n<li>\n<p><strong>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0446\u0438\u0439 <\/strong> \u2014 \u0441\u043b\u043e\u0436\u043d\u043e \u0443\u043c\u0435\u0440\u0435\u0442\u044c \u043e\u0442 \u043f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0440\u043e\u0441\u0442\u0438, \u043d\u0435 \u0434\u043e\u0447\u0438\u0442\u0430\u0432 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432. <\/p>\n<p>  <\/li>\n<li>\n<p><strong>\u041d\u0443 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442<\/strong> \u2014 \u0437\u0430 \u043f\u043e\u0447\u0442\u0438 \u0443\u0436\u0435 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u044f \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441. <\/p>\n<p>  <\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0425\u043e\u0442\u044c \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0438 \u0434\u0430\u044e\u0442 \u043c\u0435\u043d\u044c\u0448\u0435, \u0447\u0435\u043c \u043f\u0440\u043e\u0448\u043b\u044b\u043c \u043b\u0435\u0442\u043e\u043c, \u044d\u0442\u043e\u0433\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0438 \u0443\u0436 \u0442\u043e\u0447\u043d\u043e \u043d\u0430 \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043c\u0435\u0441\u044f\u0446\u0430 \u043d\u0430\u043a\u0438\u0434\u044b\u0432\u0430\u044e\u0442 \u0435\u0449\u0435 \u043a\u0440\u0435\u0434\u0438\u0442\u043e\u0432, \u0447\u0442\u043e \u043d\u0435 \u0440\u0430\u0437 \u0441\u043f\u0430\u0441\u0430\u043b\u043e \u043c\u0435\u043d\u044f \u043e\u0442 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043e\u0440\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0418\u0437 \u043c\u0438\u043d\u0443\u0441\u043e\u0432 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u044b \u0442\u0430\u043c \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0440\u044b\u0435 Tesla K80 \u043d\u0430 12GB RAM, \u0447\u0442\u043e \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u043e\u043a\u0430 \u043c\u044b \u0434\u043e\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0434\u043e \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430, \u043c\u044b \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. <\/p>\n<p>  <\/p>\n<h2 id=\"deploy-modeli\">\u0414\u0435\u043f\u043b\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/h2>\n<p>  <\/p>\n<p>\u041d\u0443 \u0447\u0442\u043e, \u0432 \u0431\u043e\u0439!<\/p>\n<p>  <\/p>\n<h3 id=\"registraciya\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u0418\u0434\u0435\u043c \u043d\u0430 <a href=\"https:\/\/algorithmia.com\/signup\" rel=\"nofollow\">https:\/\/algorithmia.com\/signup<\/a> \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u0441\u044f. \u041d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0430, \u043a\u0430\u043a\u0443\u044e \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u044e\\\u0442\u0438\u043f \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0437\u043e\u043b\u043e\u0442\u043e\u043d\u043e\u0441\u043d\u043e\u0435 \u043a\u043e\u043c\u0431\u043e, \u0434\u0430\u044e\u0449\u0435\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043a\u0440\u0435\u0434\u0438\u0442\u043e\u0432, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0430\u0439\u0442\u0435 \u0437\u043d\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0445!<\/p>\n<p>  <\/p>\n<h3 id=\"zagruzka-modeli\">\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438<\/h3>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u043e\u043a\u0430\u0436\u0435\u043c\u0441\u044f \u0432 \u0441\u0432\u043e\u0435\u043c \u043f\u0440\u043e\u0444\u0438\u043b\u0435.<br \/>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0430\u043f\u043a\u0438 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442.<br \/>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c Data Sources \u0432 \u043c\u0435\u043d\u044e \u0441\u043b\u0435\u0432\u0430.<\/p>\n<p>  <\/p>\n<p>\u041a\u043b\u0438\u043a\u0430\u0435\u043c New Data Source -&gt; Hosted Data Collection<br \/>  \u041d\u0430\u0437\u043e\u0432\u0435\u043c \u043f\u0430\u043f\u043a\u0443 \u201cMy Models\u201d.<br \/>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043d\u0430\u0441 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u0438\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u043d\u0430\u0448\u0438\u0445 \u043f\u0430\u043f\u043e\u043a. <\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u043f\u0430\u043f\u043a\u0443: New Collection -&gt; \u201cphoto2comics_out\u201d<\/p>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u0441\u0432\u0435\u0436\u0435\u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c!<br \/>  \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 My Models \u0438 \u043f\u0435\u0440\u0435\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440, \u043b\u0438\u0431\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c Upload Files \u0438\u0437 \u043c\u0435\u043d\u044e.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u043e\u043d\u0430 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u043d\u0438\u0436\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0438\u043a\u043d\u0435\u043c \u043d\u0430 \u0442\u0440\u043e\u0435\u0442\u043e\u0447\u0438\u0435 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>  <\/p>\n<p>\u0421 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043a\u043e\u043d\u0447\u0435\u043d\u043e, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443.<\/p>\n<p>  <\/p>\n<h3 id=\"algoritm\">\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/h3>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u043f\u0440\u043e\u0444\u0438\u043b\u044c \u043f\u043e \u043a\u043b\u0438\u043a\u0443 \u043d\u0430 Home \u0432 \u043c\u0435\u043d\u044e \u0441\u043b\u0435\u0432\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043a\u043b\u0438\u043a\u0430\u0435\u043c Create New -&gt; Algorithm \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u043c\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0446\u0438\u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u0430\u043a \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u043d\u0438\u0436\u0435.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043d\u0438\u0436\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/7u\/se\/aa\/7useaagraqj_hb0gzwkrrcmh3ua.png\"><\/p>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u041d\u0430\u0436\u0438\u043c\u0430\u0435\u043c Create New Algorithm \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c WebIDE \u0432 \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0435\u043c\u0441\u044f \u043e\u043a\u043e\u0448\u043a\u0435.<br \/>  <em>\u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u043b\u0438 \u043f\u043e\u043f\u0430\u043f, \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044c, \u043d\u0430\u0436\u0430\u0432 Source Code \u0432 \u043c\u0435\u043d\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<\/em><\/p>\n<p>  <\/p>\n<p>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448: <\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0415\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0431\u0435\u0437\u0434\u0443\u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import Algorithmia  import torch import torchvision import torchvision.transforms as transforms import cv2 from torch import * import uuid import gc  import requests import numpy as np  client = Algorithmia.client()  # \u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 file_path, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043d\u0430 \u043d\u0430\u0448 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 # \u043f\u043e\u0434 \u0438\u043c\u0435\u043d\u0435\u043c model_file \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0435\u0435. def load_model():     file_path = &quot;{ \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043d\u0430\u0448\u0443 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c }&quot;     model_file = client.file(file_path).getFile().name     model = torch.jit.load(model_file).half().cuda()     return model  model = load_model().eval() torch.cuda.empty_cache() torch.cuda.ipc_collect() torch.backends.cudnn.benchmark = True  # \u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435, \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0434\u043e \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430,  # \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0432 \u0442\u0435\u043d\u0437\u043e\u0440 \u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c,  # \u0442.\u043a. \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0430\u043b\u0430\u0441\u044c \u043d\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445  def preprocessing(image_path, max_size):      response = requests.get(image_path)     response = response.content     nparr = np.frombuffer(response, np.uint8)     img_res = cv2.imdecode(nparr, cv2.IMREAD_COLOR)     img_res = cv2.cvtColor(img_res, cv2.COLOR_BGR2RGB)      x = img_res.shape[0]     y = img_res.shape[1]      #if image is bigger than the target max_size, downscale it     if x&gt;max_size and x&lt;=y:         y = y*(max_size\/x)         x = max_size      if y&gt;max_size and y&lt;x:         x = x*(max_size\/y)         y = max_size      size = (int(y),int(x))     img_res = cv2.resize(img_res,size)      t = Tensor(img_res\/255.)[None,:]     t = t.permute(0,3,1,2).half().cuda()      # standartize     t = (t-0.5)\/0.5      return(t)  def predict(input):      gc.collect()     with torch.no_grad():         res = model(input).detach()      return res  # \u0414\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c # \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0432 \u043d\u0430\u0448\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435   def save_file(res, file_uri):     #de-standartize     res = (res*0.5)+0.5     tempfile = &quot;\/tmp\/&quot;+str(uuid.uuid4())+&quot;.jpg&quot;     torchvision.utils.save_image(res,tempfile)     client.file(file_uri).putFile(tempfile)  # API calls will begin at the apply() method, with the request body passed as 'input' # For more details, see algorithmia.com\/developers\/algorithm-development\/languages def apply(input):      processed_data= preprocessing(input[&quot;in&quot;], input[&quot;size&quot;])     res = predict(processed_data)     save_file(res, input[&quot;out&quot;])     input = None     res = None     processed_data = None      gc.collect()      return &quot;Success&quot;<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u0415\u0435 \u043c\u044b \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0445\u043e\u0434\u044f\u0441\u044c \u0432 WebIDE, \u0441\u043f\u0440\u0430\u0432\u0430 \u0432\u0432\u0435\u0440\u0445\u0443 \u043a\u043b\u0438\u043a\u0430\u0435\u043c \u043d\u0430 DEPENDENCIES \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430\u0448\u0438\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">algorithmia&gt;=1.0.0,&lt;2.0 opencv-python six torch==1.3.0 torchvision numpy <\/code><\/pre>\n<p>  <\/p>\n<p><em>\u0412\u0435\u0440\u0441\u0438\u044f torch \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0432\u043e\u0439, \u0447\u0435\u043c \u0442\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0435 jit \u043c\u043e\u0434\u0435\u043b\u0438. <\/em><\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0436\u0438\u043c\u0430\u0435\u043c SAVE, BUILD \u0438 \u0436\u0434\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0431\u0438\u043b\u0434\u0430. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0432\u043d\u0438\u0437\u0443 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0431\u0438\u043b\u0434\u0435, \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0432 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">{&quot;in&quot;:&quot;https:\/\/cdn3.sportngin.com\/attachments\/photo\/9226\/3971\/JABC-9u_medium.JPG&quot;, &quot;out&quot;:&quot;data:\/\/username\/photo2comics_out\/test.jpg&quot;, &quot;size&quot;:512} <\/code><\/pre>\n<p>  <\/p>\n<p>\u0413\u0434\u0435 {username} \u2014 \u0432\u0430\u0448 \u043b\u043e\u0433\u0438\u043d. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0448\u043b\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u201cSuccess\u201d, \u0430 \u0432 \u043f\u0430\u043f\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 photo2comics_out), \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. <\/p>\n<p>  <\/p>\n<h3 id=\"itogi\">\u0418\u0442\u043e\u0433\u0438<\/h3>\n<p>  <\/p>\n<p>\u041f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u044f\u044e, \u043c\u044b \u0434\u0435\u0448\u0435\u0432\u043e \u0438 \u0441\u0435\u0440\u0434\u0438\u0442\u043e \u0437\u0430\u0434\u0435\u043f\u043b\u043e\u0438\u043b\u0438 \u043d\u0430\u0448\u0443 \u0441\u043a\u0440\u043e\u043c\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c!<\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u044b\u043f\u0443\u0441\u043a\u0435 \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u043f\u043e\u0434\u0440\u0443\u0436\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u0431\u043e\u0442\u043e\u043c \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0437\u0430\u0440\u0435\u043b\u0438\u0437\u0438\u043c \u0443\u0436\u0435 \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u043e\u0431\u0440\u043e.<br \/>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u0442\u0435\u0440\u043f\u0438\u0442\u0441\u044f \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0434\u0435\u043b\u0435, \u0432\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439: <a href=\"https:\/\/algorithmia.com\/developers\/api\/\" rel=\"nofollow\">https:\/\/algorithmia.com\/developers\/api\/<\/a><\/p>\n<p>  <\/p>\n<p>\u041d\u0443 \u0430 \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u043e\u0440\u043e\u0442\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0442\u044b\u043a\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u043e\u0442\u043e\u0432, \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f \u0437\u0430\u0445\u043e\u0441\u0442\u0438\u043b \u043d\u0430 \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0438:<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/t.me\/selfie2animebot\" rel=\"nofollow\">@selfie2animebot<\/a> \u2014 \u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0435\u043b\u0444\u0438 \u0432 \u0430\u043d\u0438\u043c\u0435<br \/>  <a href=\"https:\/\/t.me\/pimpmyresbot\" rel=\"nofollow\">@pimpmyresbot<\/a> \u2014 \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u04452 (\u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0434\u043e 1400\u04451400)<br \/>  <a href=\"https:\/\/t.me\/photozoombot\" rel=\"nofollow\">@photozoombot <\/a> \u2014 \u0421\u043e\u0437\u0434\u0430\u0435\u0442 3\u0434-\u0437\u0443\u043c \u0432\u0438\u0434\u0435\u043e \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u043e\u0442\u043e<br \/>  <a href=\"https:\/\/t.me\/photo2comicsbot\" rel=\"nofollow\">@photo2comicsbot <\/a> \u2014 \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u0438\u043d\u043e\u0432\u043d\u0438\u043a \u0442\u043e\u0440\u0436\u0435\u0441\u0442\u0432\u0430<\/p>\n<p>  <\/p>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438, \u0438\u0434\u0435\u044f\u043c\u0438 \u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0448\u0438\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<br \/>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0441\u0435. \u0414\u043e \u043d\u043e\u0432\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447!<\/p>\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\/post\/485824\/\"> https:\/\/habr.com\/ru\/post\/485824\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/485824\/\">\n<p><a href=\"https:\/\/habr.com\/ru\/post\/479218\/\">-&gt; \u0427\u0430\u0441\u0442\u044c 1<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/483168\/\">-&gt; \u0427\u0430\u0441\u0442\u044c 2<\/a><\/p>\n<p>  <\/p>\n<p>\u041d\u0443, \u043e\u0442\u0434\u043e\u0445\u043d\u0443\u043b\u0438 \u0438 \u0445\u0432\u0430\u0442\u0438\u0442. \u0421 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c! <\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0435\u0440\u0438\u044f\u0445 \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0431\u0443\u0447\u0438\u043b\u0438 \u0441\u0432\u043e\u044e \u043f\u0435\u0440\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c.<br \/>  \u0417\u0430\u0442\u0435\u043c, \u0443\u0436\u0430\u0441\u043d\u0443\u0432\u0448\u0438\u0441\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c, \u043e\u0431\u0443\u0447\u0438\u043b\u0438 \u0435\u0449\u0435 \u0441 \u0434\u0435\u0441\u044f\u0442\u043e\u043a.<br \/>  \u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u0448\u0435 \u0442\u0432\u043e\u0440\u0435\u043d\u0438\u0435 \u043c\u0438\u0440\u0443!<\/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-297796","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297796","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=297796"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297796\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}