<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Bepro Team Blog - Medium]]></title>
        <description><![CDATA[A technical blog for Bepro, a sports performance analysis platform - Medium]]></description>
        <link>https://medium.com/bepro-team-blog?source=rss----e74c0f0d560f---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Bepro Team Blog - Medium</title>
            <link>https://medium.com/bepro-team-blog?source=rss----e74c0f0d560f---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 21:59:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/bepro-team-blog" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[비프로 택티컬 뷰 톺아보기]]></title>
            <link>https://medium.com/bepro-team-blog/%EB%B9%84%ED%94%84%EB%A1%9C-%ED%83%9D%ED%8B%B0%EC%BB%AC-%EB%B7%B0-%ED%86%BA%EC%95%84%EB%B3%B4%EA%B8%B0-2267f9a2a4e8?source=rss----e74c0f0d560f---4</link>
            <guid isPermaLink="false">https://medium.com/p/2267f9a2a4e8</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[football]]></category>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[sports-analytics]]></category>
            <dc:creator><![CDATA[Steffen True]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 06:56:44 GMT</pubDate>
            <atom:updated>2022-10-18T02:29:44.742Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dmssqxeMmtuYkz7j7KWQrA.png" /></figure><p>이 글에서는 비프로 택티컬 뷰의 개발 과정 그리고 비프로 에코시스템을 활용해 택티컬 뷰의 성능을 지속적으로 개선해나간 과정에 대해 다루고 있습니다.</p><h3>축구 경기 중계</h3><p>‘축구 경기 중계’라고 하면 어떤 장면이 떠오르시나요? 아마 다들 TV 중계 방송을 떠올리실 거예요. 이런 TV 중계 방송을 위한 카메라는 카메라맨에 의해 조작되고 따라서 시청자들이 보는 장면도 카메라맨에 의해 결정됩니다.</p><p>그러나 만약 전술적인 관점에서 경기를 시청하고 싶다면 문제를 맞닥뜨리게 됩니다. 바로 여러분이 보는 모든 장면이 카메라맨에 의해서 결정된다는 점이죠.</p><p>중계 비디오는 플레이 장면을 따라다니는데 대부분 공이 있는 장면을 촬영하게 됩니다. 하지만 마치 전술 분석관처럼 경기 장면 구석구석을 확인하고 싶다면 단지 공만을 쫓아서는 안되겠죠. 왜냐하면 공이 있는 곳에서 일어나는 상황은 전체 경기 장면의 일부일 뿐이니까요.</p><p>실제로 경기가 진행되는 순간순간마다 공을 직접 몰고 있는 선수는 소수에 불과합니다. 나머지 선수들은 무엇을 하고 있을까요? 그들의 위치는 어디이고 그 다음 움직임은 어디를 향하고 있을까요? 사실 실제로 공을 몰고 있는 선수보다 나머지 선수들의 움직임이 중요할 때가 훨씬 더 많습니다. 왜냐하면 이들이 팀 전술의 다음 액션을 취할 확률이 더 높으니까요.</p><h3>파노라마 비디오</h3><p>축구 경기 중계와 달리 비프로의 픽스캠은 경기가 진행되는 동안 경기장 전체 영역의 모든 순간을 촬영합니다. 그리고 유저들은 비프로의 3D 플레이어를 통해 카메라의 뷰를 직접 컨트롤하고 원하는 특정 각도에서 경기 장면을 확인할 수 있습니다. <br>— 더 자세한 내용은 <a href="https://medium.com/bepro-team-blog/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%A1%9C-360-%EB%B9%84%EB%94%94%EC%98%A4-%ED%94%8C%EB%A0%88%EC%9D%B4%EC%96%B4-%EA%B5%AC%ED%98%84%ED%95%98%EA%B8%B0-957a9f23366d">이 글</a>에서 확인해보세요.</p><h3>자동화된 택티컬 뷰</h3><p>카메라 뷰를 직접 컨트롤하며 경기장 구석구석 원하는 장면을 찾아보는 건 처음에는 흥미롭습니다. 하지만 만약 경기가 진행되는 내내 직접 화면을 움직여야 한다면 경기에 집중하기 어렵겠죠. 비프로의 AI 기술이 적용된 택티컬 뷰는 바로 여기서 빛을 발합니다.</p><blockquote>경기 흐름과 필드 플레이어의 움직임을 따라 자동으로 움직이는 택티컬 뷰는 유저로 하여금 필드에서 일어나고 있는 중요하지만 사소한 움직임 하나까지도 모두 관찰할 수 있게 해줍니다.</blockquote><p>비프로 택티컬 뷰를 한 마디로 정의하자면, ‘항상 가능한 한 많은 선수들이 경기 내내 카메라 뷰 안에 잡힐 수 있도록 하는 기술’이라고 할 수 있습니다. 하지만 전술적인 포메이션의 큰 틀을 놓치지 않는 선에서 최상의 뷰를 제공하려면 몇 명의 선수들은 택티컬 뷰 상에서 제외되는 예외적인 경우도 있습니다. 예를 들면, 골키퍼나 혹은 속공 전개 상황에서 저 멀리 뒤쳐져있는 선수 같은 경우가 이에 해당합니다.</p><h3>택티컬 뷰는 어떻게 만들어질까요?</h3><p>택티컬 뷰가 생성되는 과정을 간단하게 설명드리려 합니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUnD2i3RSfOsNMLNYaUlvQ.png" /></figure><ol><li>경기장에 설치되어 있는 각각의 카메라에서 스트리밍되는 이미지를 스티칭해서 하나의 파노라마 비디오를 만듭니다.</li><li>AI 모델을 통해 경기장 내 선수와 공에 대한 객체 탐지(Object Detection)를 실행합니다.</li><li>축적되어 있는 데이터를 기반으로 최적의 뷰를 결정합니다.</li><li>비프로 스페이스에 결과물을 송출하고 비디오 다운로드 기능을 제공합니다.</li></ol><p>택티컬 뷰를 만드는 것과 가장 연관이 깊은 2, 3번에 대해서 조금 더 자세히 알아보겠습니다.</p><h3>객체 탐지(Object Detection)</h3><p>전체 파노라마 영상에서 최적의 뷰를 찾아 보여주기 위해서는 필드 위에서 어떤 일이 일어나고 있는지 파악해야 합니다. 그리고 그걸 알아내기 위해서는 선수들과 공이 어디에 있는지 먼저 알아야겠죠. 이러한 정보를 얻기 위해 저희는 객체 탐지 기술을 사용합니다.</p><p>객체 탐지에 관한 위키피디아 문서는 아래와 같은 문장으로 시작합니다.</p><blockquote>„Object detection is a computer technology related to <a href="https://en.wikipedia.org/wiki/Computer_vision">computer vision</a> and <a href="https://en.wikipedia.org/wiki/Image_processing">image processing</a> that deals with detecting instances of semantic objects of a certain class (such as humans, buildings, or cars) in digital images and videos.“</blockquote><p>그렇다면 이게 도대체 어떻게 작동하는 걸까요? <br>아주 간단하게 답하자면, 정답은 바로 AI입니다!</p><p>오늘날 AI라는 단어는 현대 사회 문제에 대한 거의 모든 해결책처럼 여겨집니다. 때로는 사실이 아닐 때도 있지만 인공지능이 거의 모든 문제를 해결할 수 있다는 건 매력적으로 들리니까요. 하지만 객체 탐지는 정말로 AI, 더 엄밀히 말하자면 딥러닝의 영역이 맞습니다.</p><p>비프로에서는 컨볼루션 신경망(CNN, Convolutional Neural Network)이라는 커스텀 디자인된 모델을 사용합니다. 선수, 공 그리고 경기장 배경 각각의 개체를 식별하기 위한 모델 트레이닝에는 비프로에서 촬영한 엄청난 양의 경기 영상(현 시점 기준 총 60,000 시간 이상)에서 추출한 수백만 개 이상의 프레임이 사용되었습니다. 게다가, 단순히 데이터셋의 크기가 크다는 점 뿐만 아니라 경기장마다 픽스캠의 설치 환경이 달라 아주 다양한 화각의 영상 프레임이 있다는 점 또한 모델 트레이닝에 있어 큰 이점으로 작용했습니다.</p><h3>택티컬 뷰 화각 정하기</h3><p>첫 번째 단계로는 이미지 좌표계(Image Coordinate System, 비디오 이미지에서의 위치)에서 탐지된 객체의 위치를 세계 좌표계(World Coordinate System, 실제 경기장에서의 위치)로 변형해야 합니다. 이때 필요한 값들은 경기장으로부터 픽스캠까지의 거리를 가지고 도출할 수 있습니다. 경기장 위 객체들의 위치값이 결정되면, 디텍션 오류를 최소화하기 위해 각각의 인스턴스는 일련의 필터링 과정을 거칩니다.</p><blockquote>카메라의 뷰는 선수와 공의 위치에 대한 정보를 기반으로 한 규칙과 연산에 의해 정해지는데 우리는 이것을 택티컬 뷰 로직이라고 부릅니다.</blockquote><p>이렇게 생성된 택티컬 뷰 로직은 더 나은 뷰를 위해서 어떤 선수를 포함하고 배제할지에 대해 판단합니다. 이를 위해서는 개별 객체의 위치 뿐만 아니라 각 객체 간의 거리 등 다양한 정보가 활용됩니다.</p><p>그리고 현재 시점의 경기 흐름을 파악하고 이에 맞게 뷰를 조정하기 위해서는 다양한 지표들이 계산되어야 합니다. 택티컬 뷰 로직의 마지막 단계는 이렇게 생성된 모든 정보들을 모아 최적의 장면을 결정하고 이를 실제 영상 위에 입혀 아주 매끄럽게 동작하도록 하는 것입니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DuODNqkRMpe82XYcbaawxQ.png" /></figure><h3>택티컬 뷰 2.0의 도입</h3><p>택티컬 뷰 1.0은 꽤 오랜 시간 사용되었고 그동안 작은 개선 사항부터 버그 픽스까지 지속적으로 업데이트가 진행되었습니다. 하지만 때때로 극적인 퀄리티 향상을 위해서는 기존의 것에 무언가를 더하기보다 처음부터 다시 시작하는 것이 더 나을 때도 있습니다. 그리고 택티컬 뷰 2.0은 바로 그렇게 탄생했습니다.</p><blockquote>이번 리뉴얼에서 택티컬 뷰의 로직과 구조 리디자인은 백지에서 새롭게 출발했습니다.</blockquote><p>이런 리디자인 과정에서의 초기 목표는 기존 버전의 퀄리티를 따라잡는 것입니다. 하지만 이와 동시에 코드를 한줄 한줄 잘 다듬어서 전체 코드의 효율성, 가독성, 모듈성을 증대시키는 목표도 가지고 있죠. 초기 목표를 어느 정도 달성하면 다음 단계로 넘어갑니다. 단순히 이전 퀄리티를 따라잡는 것을 넘어 한층 더 깊이있게 나아가야겠죠.</p><p>기존 로직에 대해 끊임없이 질문을 던지는 것은 때때로 완전히 새로운 접근법을 떠올리게 해주기도 합니다. 그리고 개선된 코드 구조 덕분에 새로운 아이디어를 테스트하고 결과를 확인하는 건 훨씬 쉬워졌습니다. 아래는 기존 버전과 비교했을 때 이번 리뉴얼에서 두드러지게 개선되거나 새롭게 개발된 기능의 일부입니다.</p><ul><li>더 빨라진 카메라 응답 속도</li><li>최소화된 경기장 밖 검은 배경과 개선된 카메라 움직임</li><li>최상의 뷰를 보여주기 위해 특정 상황에서 일부 선수를 배제시키는 로직</li><li>잘못된 디텍션을 최소화하기 위해 더욱 강화된 필터링 메커니즘</li><li>선수들의 움직임을 바탕으로 경기 흐름을 예측하는 기능</li><li>코너킥을 인식하고 포착하는 기능</li><li>골 장면으로 이어질 가능성이 있는 중요 상황을 인식하는 새로운 기능</li></ul><h3>평가 — 비프로 에코시스템 십분 활용하기</h3><p>결론부에서는 택티컬 뷰 개발 과정에서의 가장 중요한 부분을 다루며 글을 마무리하려고 합니다. 바로 정말 택티컬 뷰의 퀄리티가 개선되었는지에 대한 평가 과정입니다. 조금 더 깊이 들어가기에 앞서 먼저 아래 두 가지를 전제를 말씀드리겠습니다.</p><ul><li>이상적인 택티컬 뷰에 대한 보편적으로 합의된 정의는 아직 존재하지 않는다.</li><li>택티컬 뷰의 퀄리티에 대한 평가는 대개 주관적이다.</li></ul><p>두 전제를 읽고 아마 이런 의문이 드셨을 거예요. 구체적으로 정의되지도 않았고, 아주 주관적인 영역에 대해 어떻게 평가하고 향상되었다고 판단할 수 있을까? <br>저희의 대답은 바로 ‘<strong>데이터</strong>를 통해서라면 가능하다!’입니다.</p><p>택티컬 뷰 개선 과정에서 객체 탐지 AI 모델을 트레이닝하기 위해 비프로의 영상에서 수백만 개의 프레임을 추출했다고 말씀드렸던 걸 기억하시나요? 비프로는 경기 영상 촬영부터 데이터 분석까지 축구 분석에 관한 모든 영역을 다루는 올인원 솔루션입니다. 그리고 저희는 택티컬 뷰의 퀄리티를 평가하기 위해 이렇게 저희 데이터베이스에 축적되어 있는 이벤트 분석 데이터, 즉 수치 데이터를 활용했습니다.</p><p>이 이벤트 데이터에서 얻을 수 있는 가장 중요한 정보는 바로 이벤트가 일어난 위치입니다. 각각의 이벤트가 일어난 경기장의 영역에 대한 정보를 불러와서, 택티컬 뷰에 이 장면이 제대로 잡혔는지 확인할 수 있습니다. 그러나 이건 개선을 확인하기 위한 아주 기초적이고 기본적인 출발점에 불과합니다. 중요한 이벤트를 제대로 보여주기 위해서는 단순히 전체 경기장 영역을 다 보여주는 것이 아니라, 필요한 부분만을 최대한으로 보여주는 것 또한 중요합니다. 이러한 목적에서 택티컬 뷰에서 작동하는 줌값과 위치에 대한 값 또한 평가될 수 있습니다. 그리고 택티컬 뷰의 방향 전환 횟수를 최소한으로 하는 것도 중요합니다. 카메라가 안정적이고 부드럽게 움직여야 유저에게 훨씬 더 나은 시청 경험을 제공할 수 있으니까요.</p><p>하지만 여전히 카메라 움직임과 포커스에 대한 유저의 평가는 주관적이고 편차가 있을 수 있습니다. 그리고 그게 바로 저희가 지속적으로 택티컬 뷰를 개선해나가고 있는 이유이기도 합니다.</p><h3>예시 영상</h3><p>아래 예시 비디오 클립에서 택티컬 뷰 개선 전후의 차이를 확인하실 수 있습니다. 영상 내 좌측이 택티컬 뷰 개선 전, 우측이 개선 후 장면입니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*F6ZYjz0IWLcSAvKmgIo64g.gif" /><figcaption>결정적인 수비 실책 이후 빠르게 골대 쪽 비추기</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*6kI4wcarht6uBxFDtSKhSw.gif" /><figcaption>위협적인 공격 전개 상황을 인식하고 골대 쪽을 비추었다가 성공적인 수비 장면 이후 줌인</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*BhYIbBTqTp82uqbAqSdAIQ.gif" /><figcaption>선수들의 움직임을 통해 위협적인 상황 인식</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Out36LbF39xItD3ux90OEQ.gif" /><figcaption>수비 셋업을 통해 골대 쪽으로 향하는 움직임 예측</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E8TqAt6LAtsTA-HA1cF0ug.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2267f9a2a4e8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bepro-team-blog/%EB%B9%84%ED%94%84%EB%A1%9C-%ED%83%9D%ED%8B%B0%EC%BB%AC-%EB%B7%B0-%ED%86%BA%EC%95%84%EB%B3%B4%EA%B8%B0-2267f9a2a4e8">비프로 택티컬 뷰 톺아보기</a> was originally published in <a href="https://medium.com/bepro-team-blog">Bepro Team Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bepro’s Tactical View — A General Look]]></title>
            <link>https://medium.com/bepro-team-blog/bepros-tactical-view-a-general-look-118e7eda72aa?source=rss----e74c0f0d560f---4</link>
            <guid isPermaLink="false">https://medium.com/p/118e7eda72aa</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[sports-analytics]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[football]]></category>
            <category><![CDATA[sports]]></category>
            <dc:creator><![CDATA[Steffen True]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 06:56:25 GMT</pubDate>
            <atom:updated>2022-10-18T02:26:35.985Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bepro’s Tactical View — A General Look</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5uL0m09sUoa8WnzuEUzlCA.png" /></figure><p>This article highlights the reasons for a tactical view, its creation, and its evolution where we use the Bepro ecosystem to our advantage.</p><h3>Football Broadcast</h3><p>When we think of a football match on a screen, we have a television broadcast in mind.</p><blockquote>The camera is operated by a cameraman, and the production decides on the images we ultimately see.</blockquote><p>However, if you want to view the game from a tactical point of view, you face a problem: <strong>The camera determines what you see</strong>.</p><p>The video follows the action — and who would have thought it — it mostly takes place where the ball is. But to observe the game like a tactical analyst, you can’t just follow the ball. Because what happens on the ball is only a small part of the whole picture.</p><p>In fact, most of the time there are over twenty players on the field who are not actively interacting with the ball. What are they doing? Where are they moving? What position or area do they occupy? In fact, the actions of these players are often more important than the situation directly on the ball, as they will most likely determine the next move.</p><h3>Panoramic Video</h3><p>Unlike football on TV, our camera(s) capture every moment of your game. Our panoramic video covers the entire playing area for the entire length of the game. The 3D video player allows the user to become the camera operator and determine the view of the game — Read more about it <a href="https://medium.com/bepro-team-blog/implement-a-360-video-player-in-javascript-41c1ddcd61bb">here</a>.</p><h3>Automatic Tactical View</h3><p>Operating the camera yourself is fun, but it doesn’t allow you to fully concentrate on the overall gameplay. This is where our <strong>AI-Generated Tactical View</strong> comes into play.</p><blockquote>The automatic camera movement allows our users to follow the exciting action of their team while assessing every tactical subtlety on the field.</blockquote><p>Bepro’s Tactical View is defined in such a way that as many field players as possible can be seen at all times in the camera’s angle of view. Certain exceptions to exclude players, e.g. the goalkeeper or players far behind, enable the best possible perspective without losing the overview of the tactical formation.</p><h3>From Pitch to View</h3><p>A quick summary of how the Tactical View is created as a final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8lPE80M-XxZuwZiGMYAKDQ.png" /></figure><ol><li>Create a panoramic video from the video streams of each camera</li><li>Perform object detection (player and ball) with an AI model</li><li>Determine the best view position based on the accumulated information</li><li>Presentation of the result on our platform and provision as a video for download</li></ol><p>Points 2 and 3 are the most relevant for creating the Tactical View, so let’s look at these in more detail.</p><h3>Object Detection</h3><p>In order for the camera to show the ideal section of the entire panorama (video), we need to assess what is happening on the field, and in order to do that we need to know where the players and the ball are. To obtain this information, we make use of object detection technology.</p><p>The first sentence on Wikipedia sums it up nicely:</p><blockquote><em>“</em>Object detection is a computer technology related to <a href="https://en.wikipedia.org/wiki/Computer_vision">computer vision</a> and <a href="https://en.wikipedia.org/wiki/Image_processing">image processing</a> that deals with detecting instances of semantic objects of a certain class (such as humans, buildings, or cars) in digital images and videos.“</blockquote><p>But now the question remains how does this work? — Well, the short (and frankly inaccurate) answer is: <strong>AI!</strong></p><p>The acronym AI is referred to as the solution for almost every problem that requires solving today, often unfairly, but let’s face it: it’s fascinating to imagine an artificial intelligence being able to solve something. However, object detection is truly an area dominated by AI, or more precisely Deep Learning.</p><p>We use a custom-designed model, more precisely a convolutional neural network (CNN). This model has been trained with millions of examples to identify objects (here player, ball and background). For the training data needed for this, we can fall back on our huge volume of recorded videos (At this point approx. 60,000 hours). In addition, we have the advantage that we not only have many data sets, but also a wide range of variety due to the completely different locations and users of our systems.</p><h3>Determine View Position</h3><p>The first step is to transform the position of the detected objects from the image coordinate system (position in the video image) to the world coordinate system (position on the playing field). The necessary calculations can be derived from the position of the camera in relation to the playing field. After the location of the objects on the playing field have been determined, each instance goes through a series of filtering steps to minimise detection errors.</p><blockquote>The actual view of the camera is defined by a set of rules and operations based on the player and ball position information.</blockquote><blockquote>We call these definitions the <strong>Tactical View Logic</strong>.</blockquote><p>The Logic then decides which players are relevant and which can be excluded in favour of a better camera perspective. For this purpose, various pieces of information are utilised, such as the distance between the identified players or the distance to the ball, as well as its general position.</p><p>In addition, various indicators are calculated to evaluate the current state of the game and adjust the view accordingly. The final step of the logic is to use the information gathered to determine the best possible image section and transfer it into a seamless camera motion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DuODNqkRMpe82XYcbaawxQ.png" /></figure><h3>Introducing Version 2.0</h3><p>The first version of Tactical View has been around for quite a while and has received constant updates. Over time, many minor improvements and bug fixes have been implemented, but to achieve a big leap in quality, sometimes it’s best to start with a blank sheet. And that’s exactly what we did.</p><blockquote>We have redesigned the structure and also the logic of Tactical View from the ground up.</blockquote><p>In such a redesign, the initial goal is to recreate the quality of the original version. However at the same time we also aim to increase the efficiency, comprehensibility and modularity of the code by scrutinising every single line. After a certain level of imitation has been reached, the next phase begins — the student becomes the master.</p><p>Questioning the existing logic frequently produces completely new approaches, which can now be quickly introduced and tested thanks to the improved structure of the code. Compared to the original version, these are a few highlights that have been improved or developed:</p><ul><li>Faster camera response time</li><li>Improved alignment of the camera to reduce blank backgrounds</li><li>New method to exclude players to allow the best possible perspective</li><li>Enhanced effectiveness of filtering mechanisms to avoid false detections</li><li>New feature to assess the gameplay based on the player’s movements</li><li>New feature to detect and capture corner kicks</li><li>Novel method to identify critical situations with goal potential</li></ul><h3>Evaluation — Taking Advantage of Bepro’s Ecosystem</h3><p>The concluding subject of this article deals with one of the most important points in the development of the Tactical View, which is the assessment of quality. To clarify this matter, two things must first be established:</p><ul><li>There is no universally valid definition of the ideal Tactical View</li><li>The quality of the Tactical View is largely subjective</li></ul><p>Faced with these facts, you’re probably wondering: how one can evaluate and improve something that is not strictly defined and highly subjective? Our solution is: <strong>data</strong>!</p><p>Remember the millions of examples we extract from our videos that we use to train our AI to identify objects? We also perform detailed analysis of the games for our all-in-one ecosystem.</p><blockquote>We use our analysed event data to convert the subjective quality of the Tactical View into numbers that can be compared.</blockquote><p>The most important information from this data is the position of the events. By referencing each action exactly on the playing field, we can determine if the event is visible in the tactical view. This is the basic requirement and the starting point of any improvement. However, in order not to miss any event, the virtual camera should not show the entire playing field, but just as much as necessary. For this purpose, the zoom level and the position of the Tactical View can be evaluated. In addition, the number of directional changes of the camera should be kept as low as possible to provide a pleasant viewing experience.</p><p>However, the actual experience of focus and camera movement is still subjective and perceived differently by each user. That’s why we are constantly striving to improve our Tactical View.</p><h3>Example Scenes</h3><p>The following videos show clips of improved situations detected by the automatic tactical view evaluation. The previous version is on the left and the new version is on the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*F6ZYjz0IWLcSAvKmgIo64g.gif" /><figcaption>Including the goal after a critical loss of the ball</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*6kI4wcarht6uBxFDtSKhSw.gif" /><figcaption>Recognising a goal-threatening situation and quickly zooming in after successful defence</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*BhYIbBTqTp82uqbAqSdAIQ.gif" /><figcaption>Anticipating a dangerous situation using player movement</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Out36LbF39xItD3ux90OEQ.gif" /><figcaption>Reading the setup of the defence to predict a movement toward the goal</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LDsl6c3teVidtgQY77XbdA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=118e7eda72aa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bepro-team-blog/bepros-tactical-view-a-general-look-118e7eda72aa">Bepro’s Tactical View — A General Look</a> was originally published in <a href="https://medium.com/bepro-team-blog">Bepro Team Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[비프로는 서버리스 아키텍처를 어떻게 운영하고 있을까?]]></title>
            <link>https://medium.com/bepro-team-blog/%EB%B9%84%ED%94%84%EB%A1%9C%EB%8A%94-%EC%84%9C%EB%B2%84%EB%A6%AC%EC%8A%A4-%EC%95%84%ED%82%A4%ED%85%8D%EC%B2%98%EB%A5%BC-%EC%96%B4%EB%96%BB%EA%B2%8C-%EC%9A%B4%EC%98%81%ED%95%98%EA%B3%A0-%EC%9E%88%EC%9D%84%EA%B9%8C-ba799f154c48?source=rss----e74c0f0d560f---4</link>
            <guid isPermaLink="false">https://medium.com/p/ba799f154c48</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[zappa]]></category>
            <category><![CDATA[서버리스]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[serverless-architecture]]></category>
            <dc:creator><![CDATA[Woojin]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 13:22:37 GMT</pubDate>
            <atom:updated>2022-09-20T13:22:37.452Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwNZCn5e8RTJt-1B59fVtg.png" /></figure><p>비프로의 대부분 백엔드 서비스는 파이썬으로 작성되고 있습니다. 그중 메인 API 서비스 역시 파이썬으로 구현이 되어 있는데요. 이 메인 API 서비스는 현재 서버리스로 운영하고 있습니다. 또한 서버리스 오픈소스 관리툴인 <a href="https://github.com/zappa/Zappa">Zappa</a>를 통해 배포를 진행하고 있습니다.</p><p>이번 글에서는 비프로의 파이썬 서버리스 아키텍처가 어떻게 운영되고 있는지 간단하게 소개해드리고자 합니다.</p><h3>서버리스는 무엇일까?</h3><p>비프로의 서버리스에 대해 이야기하기 전에 서버리스에 대해 간단히 살펴보고 가면 좋을 것 같은데요.</p><p>먼저 “Big Three” 클라우드 벤더들은 어떻게 이야기 하고 있을까요?</p><p><a href="https://aws.amazon.com/serverless/"><strong>Amazon AWS</strong></a></p><blockquote><em>서버에 대한 고민 없이 애플리케이션을 구축하고 실행</em></blockquote><p>AWS는 서버리스 아키텍처를 구성할 수 있는 여러 가지 서비스들을 제공하고 있습니다.(<a href="https://aws.amazon.com/lambda/">Lambda</a>, <a href="https://aws.amazon.com/api-gateway/">API Gateway</a>, <a href="https://aws.amazon.com/rds/aurora/serverless/">Aurora Serverless</a> 등..)</p><p><a href="https://cloud.google.com/serverless"><strong>Google Cloud</strong></a></p><blockquote><em>완전 관리형 서버리스 플랫폼에서 확장성이 우수한 애플리케이션 및 함수를 개발하고 배포합니다.</em></blockquote><p>역시 서버리스를 구성할 수 있는 여러 가지 서비스들을 제공합니다.(<a href="https://cloud.google.com/run/?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=japac-AU-all-en-dr-bkws-all-pkws-trial-e-dr-1009882&amp;utm_content=text-ad-none-none-DEV_c-CRE_602771386312-ADGP_Hybrid%20%7C%20BKWS%20-%20EXA%20%7C%20Txt%20~%20Compute%20~%20Cloud%20Run_cloud%20run-general%20-%20Products-44225-KWID_43700071610100400-aud-970366092687%3Akwd-678836618089&amp;userloc_9045957-network_g&amp;utm_term=KW_google%20cloud%20run&amp;gclsrc=aw.ds&amp;gclid=Cj0KCQjwhqaVBhCxARIsAHK1tiNjesfaaPfoaCIB5uKR8tuDlJQ7v1fQUv0c9ZZKNp8kHZ_Rt-Q-BnoaAsL6EALw_wcB">Cloud Run</a>, <a href="https://cloud.google.com/functions/?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=japac-KR-all-en-dr-bkws-all-all-trial-b-dr-1009882&amp;utm_content=text-ad-none-none-DEV_c-CRE_248280173489-ADGP_Hybrid%20%7C%20BKWS%20-%20PHR%20%7C%20Txt%20~%20Serverless%20Computing%20~%20Cloud%20Functions_cloud%20functions-KWID_43700065777621434-aud-970366092687%3Akwd-298528048746&amp;userloc_9045957-network_g&amp;utm_term=KW_google%20cloud%20functions&amp;gclsrc=aw.ds&amp;gclid=Cj0KCQjwhqaVBhCxARIsAHK1tiNm9AJbEMDt6gChC4zJdFu5TOQmfHObpvg2CNoO7eSxTuXV-tE7KIMaApP5EALw_wcB">Cloud Functions</a> 등..)</p><p><a href="https://azure.microsoft.com/en-us/overview/serverless-computing/"><strong>MS Azure</strong></a></p><blockquote><em>서버리스라는 이름은 인프라 프로비저닝 및 관리와 관련된 작업이 개발자에게 보이지 않는다는 사실에서 붙여진 것입니다.</em></blockquote><p>MS 역시 여러 서버리스 서비스들을 제공합니다.</p><p>마지막으로 제가 좋아하는 마틴 파울러의 블로그에서는 서버리스에 대해 이렇게 이야기합니다.</p><p><a href="https://martinfowler.com/articles/serverless.html"><strong>martinfowler.com</strong></a></p><blockquote><em>Serverless had become a dominant name for this area, giving way to the birth of the </em><a href="http://serverlessconf.io/"><em>Serverless Conference</em></a><em> series, and various Serverless vendors embracing the term in everything from product marketing to job descriptions.</em></blockquote><p>이 아티클에서는 클라우드 벤더사들이 BaaS(e.g., AWS API Gateway), FaaS(e.g., AWS Lambda) 와 같은 서비스들을 출시하면서 서버리스라는 용어를 마케팅적으로 활용하였고 대중화되었다고 말하고 있습니다.</p><p>결국 서버리스는 위에서 살펴보았던 “Big Three”와 같은 클라우드 벤더사들이 제공하는 서버리스 서비스들을 통해 “<strong>개발자가 인프라에 대한 고민을 할 필요가 없이 개발할 수 있는 환경</strong>” 이라는 개념으로 생각해보면 좋을 것 같습니다. 또한 위 <a href="http://martinflower.com/">martinfowler.com</a> 아티클에서는 서버리스에 대한 개념과 장단점에 대해 자세하게 설명하고 있으니 관심이 있으시다면 읽어보고 넘어가시는 것을 추천드립니다.</p><h3>비프로는 왜 서버리스를 채택하였을까?</h3><p>그렇다면 비프로는 왜 서버리스 환경을 채택했을까요?</p><h4>제한적인 개발 리소스</h4><p>서비스 런칭 초기 제한적인 리소스를 최대한 효율적으로 사용해야 했던 비프로의 상황이 서버리스 환경을 구성하게 된 중요한 이유 중 하나였을 것입니다. 향후 서비스 규모의 변화에 대한 불확실성 속에서 새로운 인프라 관리 인력을 채용하기보다는 기존의 개발자가 최대한 인프라에 신경을 쓰지 않고 서비스를 개발하고 운영할 수 있는 환경이 필요했습니다.</p><h4>API 호출 트래픽 패턴</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKvXfljNHhc4f4AwwYCgBg.png" /></figure><p>일반적인 주말 3시간 동안의 1초당 API 호출 패턴입니다. API 서버는 불규칙한 패턴(경기 일정의 영향)으로 아주 잠시 평소의 10배에서 20배에 달하는 부하가 발생하게 되는데요. 평상시에는 상대적으로 적은 인프라 리소스로도 충분히 트래픽 감당이 되지만 피크 때 동일한 서버 성능을 보장하기 위해서는 리소스를 아주 잠시 스케일 아웃 또는 업 해야 최적의 인프라 사용 효율성을 가져갈 수 있을 것입니다. 이러한 트래픽 패턴은 주말/평일, 시즌/비시즌 기간에 따라 상당히 불규칙하게 됩니다.</p><p>이런 상황에서는 피크 트래픽을 감당할 수 있는 인프라 리소스를 지속적으로 유지하던지, 또는 오토 스케일링이 지원되는 환경을 구성해 놓아야 합니다. 전자의 경우에는 비용의 낭비가 발생하고 후자의 경우에는 트래픽이 늘어나는 순간 스케일링 업 또는 아웃되겠지만 그 순간 바로 트래픽은 다시 줄어 들어 리소스 확장이 한발 늦게 됩니다. 위에서 언급한 대로 이러한 요인들을 고려하여 인프라를 관리하기에 리소스가 상당히 제한적이었습니다. 서버리스 환경에서는 이러한 트래픽 패턴에 대해 개발자가 고민할 필요가 없습니다. 서버리스 환경을 제공해주는 클라우드 벤더사가 알아서 인프라를 관리해주기 때문에 개발자는 오롯이 비즈니스 로직 개발에만 몰입할 수 있다는 판단이었습니다. 이는 스타트업에서 가장 중요한 요소 중 하나인 빠른 기능 출시에 큰 도움이 되었습니다.</p><h4>비용</h4><p>시스템 운영 관점 외에도 AWS 서버리스 환경과 일반적인 서버 환경을 구성했을 때의 예상 비용을 대략적으로 비교해보았습니다. (대략적인 추세만을 파악하기 위한 용도로 RDS, Load Balancer, S3 등의 구체적인 비용은 고려하지 않았습니다.)</p><p><em>가정 사항: 2,000,000 requests/Month</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wTD1TUZ_E6pl0MB26CGjPw.png" /></figure><p>AWS 기준으로 대략적으로 비용을 산출했을 때 서버리스 환경이 약 70% 정도 더 저렴합니다.</p><p>동시 최대 실행 개수 제한, 최대 실행시간 제한, 콜드 스타트 지연, 모니터링 등의 단점이 존재함에도 불구하고 위와 같은 이유로 비프로는 서버리스 환경을 채택했습니다. (<a href="https://martinfowler.com/articles/serverless.html#benefits">서버리스의 일반적인 장단점 참고</a>)</p><h3>비프로 서버리스 아키텍처</h3><p>비프로는 “Big Three” 서버리스 서비스 중 AWS의 서버리스 환경 사용하기로 결정했습니다. 대략적인 아키텍처는 아래와 같습니다. (서버리스의 구성만을 보여주기 위해 CDN 등의 세부적인 요소는 생략하였습니다.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Efc5Vab-duQFtptcRs6yAg.png" /></figure><p>글로벌 서비스를 제공하기 위해 유럽과 아시아 멀티 리전 구성을 통해 API 응답속도를 최적화했습니다. 또한 Docker 컨테이너와 함께 Lambda 환경을 구성했는데요. 이 모든 것은 오픈 소스 툴인 Zappa를 통해 관리됩니다.</p><h3>Zappa로 서버리스 파이썬 웹 서비스 배포하기</h3><p><a href="https://github.com/zappa/Zappa">Zappa</a>를 통해 서버리스 환경 배포를 어떻게 자동화했는지 살펴보겠습니다.</p><p>Zappa의 도움 없이 Python + Django 서비스를 AWS 서버리스 환경으로 배포한다면 IAM ROLE, 코드 패키징, API Gateway 세팅, Lambda 세팅 등 신경써야 할 것이 너무 많아 머리가 아플 것입니다. Zappa는 이 모든 걸 자동으로 처리해주는데요.</p><p>예제 프로젝트를 통해 Zappa로 도커 기반의 서버리스 파이썬 Django 웹서비스를 배포하는 방법을 알아보겠습니다.</p><h3>Django Project 예제 세팅</h3><p>우선 <a href="https://docs.python.org/ko/3/library/venv.html">파이썬 가상환경</a>을 만들고 <a href="https://www.djangoproject.com/">Django</a>를 설치합니다.</p><pre>(venv)&gt; pip install django</pre><p>django project 를 생성합니다.</p><pre>(venv)&gt; django-admin startproject zappa-example<br>(venv)&gt; cd zappa-example</pre><p>예제 test를 수월하게 진행하기 위해 Django settings 의 <a href="https://docs.djangoproject.com/en/4.0/ref/settings/#allowed-hosts">ALLOWED_HOSTS</a> 를 수정했습니다. 또한 <a href="https://docs.djangoproject.com/en/4.0/ref/settings/#databases">데이터베이스 관련된 설정</a>은 주석으로 처리합니다.</p><pre>... (생략) ...<br>ALLOWED_HOSTS = [&quot;*&quot;]<br>... (생략) ...<br># DATABASES = {<br>#     &#39;default&#39;: {<br>#         &#39;ENGINE&#39;: &#39;django.db.backends.sqlite3&#39;,<br>#         &#39;NAME&#39;: &#39;mydatabase&#39;,<br>#     }<br># }<br>... (생략) ...</pre><p>로컬환경에서 django 개발 서버를 실행합니다.</p><pre>(venv) python manage.py runserver</pre><pre>Watching for file changes with StatReloader<br>Performing system checks...</pre><pre>System check identified no issues (0 silenced).</pre><pre>You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.<br>Run &#39;python manage.py migrate&#39; to apply them.<br>June 14, 2022 - 15:09:23<br>Django version 4.0.5, using settings &#39;zappa_example.settings&#39;<br>Starting development server at &lt;http://127.0.0.1:8000/&gt;<br>Quit the server with CONTROL-C.</pre><p>브라우저에서 로컬 Django 서버로 접속이 잘되는 것을 확인합니다. (이 예제에서는 특별한 기능은 구현하지 않고 django admin 로그인 페이지 접속을 통해 간단하게 테스트하겠습니다.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I3mE9D60b69kPm0vIjOrEQ.png" /></figure><h3>Zappa 설정</h3><p>zappa를 세팅하기 전에 우선 <a href="https://aws.amazon.com/ko/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/">AWS credential</a> 세팅이 필요합니다.</p><p>우선 awscli 패키지를 설치합니다.</p><pre>&gt; pip install awscli</pre><p>aws configure 명령을 통해 AWS credential 세팅을 완료합니다.</p><pre>&gt; aws configure</pre><p>다음으로 위에서 만들어놓은 Django Project Python가상환경에 zappa 라이브러리를 설치합니다.</p><pre>(venv)&gt; pip install zappa</pre><p>zappa 초기화를 하기 전 requirements.txt 파일을 생성하여 의존성을 명시해줍니다.(추후 도커 배포에 이용하게 됩니다.)</p><pre>(venv)&gt; pip freeze &gt;&gt; requirments.txt</pre><p>zappa 세팅 초기화를 합니다.</p><pre>(venv)&gt; zappa init</pre><p>위 zappa 명령어를 실행하면 zappa 세팅을 위한 대화형 모드가 진행됩니다. 일단 디폴트 값으로 모두 진행했습니다. 대화 중간에 주목할 점은 zappa가 해당 디렉토리의 구조를 파악하고 자동으로 Django 프로젝트인 것을 감지하고 자동으로 세팅해준다는 점입니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*BH60YY8UdP-yIZQjd1TU6A.png" /></figure><p>ls 명령어로 현재 디렉토리 상태를 확인해봅니다.</p><pre>(venv)&gt; ls<br>db.sqlite3          manage.py           zappa_example       zappa_settings.json</pre><p>zappa_setting.json 이라는 파일이 생성되었습니다. 해당 파일 내용을 확인합니다.</p><pre>{<br>    &quot;dev&quot;: {<br>        &quot;aws_region&quot;: &quot;ap-northeast-2&quot;,<br>        &quot;django_settings&quot;: &quot;zappa_example.settings&quot;,<br>        &quot;profile_name&quot;: &quot;default&quot;,<br>        &quot;project_name&quot;: &quot;zappa-example&quot;,<br>        &quot;runtime&quot;: &quot;python3.8&quot;,<br>        &quot;s3_bucket&quot;: &quot;zappa-yyamukhwg&quot;<br>    }<br>}</pre><p>dev 라는 스테이지가 만들어졌습니다. 스테이지는 staging, production 등 여러 개를 만들 수 있고 배포도 각각 진행이 가능합니다. 여기서는 dev 만 만들어서 테스트해보겠습니다.</p><p>aws_region : 배포될 aws region 을 명시합니다.<br>django_settings : 해당 프로젝트가 Django 프로젝트일 경우 Django의 settings 파일 경로를 명시합니다.<br>profile_name : AWS CLI configuration profile을 명시합니다.<br>project_name : Lambda 함수를 위한 프로젝트 이름을 명시합니다.<br>runtime : Lambda에서 동작할 런타임 환경을 명시합니다.(Docker 이미지로 배포하는 경우 필요 없습니다.)<br>s3_bucket : deployment 패키지(zip 파일)를 업로드할 s3 버킷 입니다. → zappa 가 source code와 함께 배포 패키지를 압축하여 s3 bucket 에 업로드하며 lambda 함수가 구동될 때 사용하게 됩니다.</p><p>이 상태에서 바로 zappa 배포를 진행해 보겠습니다.</p><pre>(venv)&gt; zappa deploy dev</pre><pre>... (생략) ...<br>Deployment complete!: &lt;https://7qi7rn36uf.execute-api.ap-northeast-2.amazonaws.com/dev&gt;</pre><p>코드를 zip파일로 압축하여 S3 버킷에 업로드하고 람다 함수를 생성, API Gateway 를 세팅하는 등 여러 배포 프로세스를 명령어 하나로 진행합니다.</p><p>마지막에 출력된 url 로 접속하여 admin 페이지에 접속 가능한 것을 확인합니다.(static 파일을 배포하지 않은 상태이기 때문에 스타일이 적용되지 않은 상태입니다.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q84KSqhM1Gqf08NEQAUk6w.png" /></figure><p>배포를 취소합니다. 명령어 한줄로 생성된 AWS 리소스(Lambda, API Gateway 등)를 모두 회수합니다.</p><pre>(venv)&gt; zappa undeploy</pre><p>다음은 도커 이미지로 배포하는 과정을 살펴보겠습니다.</p><h3>도커 이미지 빌드 하기</h3><p>다음으로 도커 파일을 만들어 줍니다.</p><pre>FROM amazon/aws-lambda-python:3.8  # 1</pre><pre>ARG FUNCTION_DIR=&quot;/var/task/&quot;</pre><pre>WORKDIR ${FUNCTION_DIR}</pre><pre>COPY ./ ${FUNCTION_DIR}</pre><pre># Install packages<br>RUN pip install -r requirements.txt</pre><pre># Grab the zappa handler.py and put it in the working directory<br>RUN ZAPPA_HANDLER_PATH=$( \\<br>    python -c &quot;from zappa import handler; print (handler.__file__)&quot; \\<br>    ) \\<br>    &amp;&amp; echo $ZAPPA_HANDLER_PATH \\<br>    &amp;&amp; cp $ZAPPA_HANDLER_PATH ${FUNCTION_DIR}</pre><pre>CMD [ &quot;handler.lambda_handler&quot; ]  # 2</pre><p>#1 : AWS 에서 제공해주는 람다 베이스 이미지를 사용하였습니다.(<a href="https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-base">참고</a>)</p><p>#2 : zappa에서 제공해주는 lambda handler를 실행해주도록 합니다.(API Gateway의 요청을 알아서 Django 서버로 라우팅을 해주는 역할을 하게 됩니다.)</p><p>이미지를 빌드 하기전에 도커 배포에 필요한 세팅 파일을 만들어줍니다.</p><pre>(venv)&gt; zappa save-python-settings-file dev</pre><p>zappa save-python-settings-file &lt;stage_name&gt; 형식으로 실행합니다. 일반적인 zip 파일 기반의 zappa 배포에서는 파이썬 세팅 파일을 함께 패키지해서 배포하게 되는데, 이와 동일한 세팅 파일(zappa_settings.py)을 생성하여 도커 이미지에도 포함하도록 합니다.</p><p>이미지를 빌드합니다.</p><pre>&gt; docker build -t zappa-example:latest .</pre><h3>도커 이미지 푸시</h3><p>다음으로 AWS ECR Repository 를 생성합니다.</p><pre>&gt; aws ecr create-repository --repository-name zappa-example --image-scanning-configuration scanOnPush=true</pre><p>빌드해 놓은 도커 이미지에 태그를 수정합니다.</p><pre>&gt; docker tag zappa-example:latest XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><p>만들어 놓은 AWS ECR 에 도커 로그인 합니다.</p><pre>&gt; aws ecr get-login-password | docker login --username AWS --password-stdin XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example</pre><p>도커 이미지를 ECR에 푸시합니다.</p><pre>&gt; docker push XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><h3>도커 이미지로 배포하기</h3><p>마지막으로 AWS Serverless Docker 배포를 진행합니다.</p><pre>(venv)&gt; zappa deploy dev -d XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><pre>... (생략) ...<br>Deployment complete!: &lt;https://g9vu4sutk2.execute-api.ap-northeast-2.amazonaws.com/dev&gt;</pre><p>배포된 URL에 접속하여 배포가 잘되었는지 확인해봅니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_kuV24zFn3PXj7aNIXM2xQ.png" /></figure><p>배포가 잘된 것을 확인할 수 있습니다.</p><p>만약 배포가 된 상태에서 코드의 수정으로 변경 배포가 필요한 경우 다음과 같이 진행합니다.</p><pre>(venv)&gt; zappa save-python-settings-file dev<br>&gt; docker build -t XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest .<br>&gt; docker push XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest<br>(venv)&gt; zappa update dev -d XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><p>마지막에 zappa deploy 명령이 아닌 zappa update 를 사용합니다.</p><h3>커스텀 Domain 및 SSL 설정</h3><p>커스텀 Domain은 <a href="https://aws.amazon.com/route53/">AWS Route 53,</a> SSL 인증서는 <a href="https://aws.amazon.com/certificate-manager/">AWS Certificate Manager</a> 를 이용하겠습니다.</p><p>Domain 및 SSL Certificate 는 모두 발급이 완료되었다고 가정하겠습니다.</p><p>먼저 zappa_settings.json 파일을 수정합니다. domain명과 certificate_arn 값을 추가합니다.</p><pre>{<br>    &quot;dev&quot;: {<br>        &quot;aws_region&quot;: &quot;ap-northeast-2&quot;,<br>        &quot;django_settings&quot;: &quot;zappa_example.settings&quot;,<br>        &quot;profile_name&quot;: &quot;default&quot;,<br>        &quot;project_name&quot;: &quot;zappa-example&quot;,<br>        &quot;s3_bucket&quot;: &quot;zappa-yyamukhwg&quot;,<br>        **&quot;domain&quot;: &quot;zappa.cwoojin.com&quot;,**<br>        **&quot;certificate_arn&quot;: &quot;arn:aws:acm:us-east-1:XXXXXXXXXXXX:certificate/eba3fd6b-a1f4-4e6a-b5d6-fe7aa8c88649&quot;**<br>    }<br>}</pre><p>Zappa를 통해 API Gateway와 인증서, 도메인을 연동합니다.</p><pre>(venv)&gt; zappa certify<br>(venv)&gt; zappa update dev -d XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><pre>..(생략)...<br>Your updated Zappa deployment is live!: &lt;https://zappa.cwoojin.com&gt; (&lt;https://g9vu4sutk2.execute-api.ap-northeast-2.amazonaws.com/dev&gt;)</pre><p>등록한 도메인으로 접속이 잘되는지 확인합니다.(<a href="https://zappa.cwoojin.com/">https://zappa.cwoojin.com</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RlFvDQ_RQpjQ7YywXVEdbQ.png" /></figure><p>기본적인 배포 세팅이 끝났습니다.</p><p>(AWS에 배포된 예제를 undeploy 하는 것을 잊지 마세요!)</p><h3>비프로의 Zappa</h3><p>비프로에서는 dev, test, prod 환경 등으로 스테이지를 나누어 배포 환경을 운영하고 있습니다. 또한 Zappa에서 제공해주는 여러가지 <a href="https://github.com/zappa/Zappa#advanced-usage">부가적인 기능</a>들은 공식 문서에서 확인하실 수 있습니다.</p><p>비프로에서 운영중인 zappa_settings.json 파일을 일부 공유합니다.</p><pre>{<br>  &quot;dev&quot;: {<br>    &quot;aws_region&quot;: &quot;eu-central-1&quot;,<br>    &quot;django_settings&quot;: &quot;xxx&quot;,<br>    &quot;project_name&quot;: &quot;xxx&quot;,<br>    &quot;s3_bucket&quot;: &quot;xxx&quot;,<br>    &quot;environment_variables&quot;: {<br>      ...<br>    },<br>    &quot;certificate_arn&quot;: &quot;xxx&quot;,<br>    &quot;domain&quot;: &quot;xxx&quot;,<br>    &quot;route53_enabled&quot;: false,<br>    &quot;cors&quot;: {<br>      &quot;allowed_headers&quot;: [xxx]<br>    },<br>    &quot;exception_handler&quot;: &quot;xxx&quot;,<br>    &quot;keep_warm_expression&quot;: &quot;xxx&quot;,<br>    &quot;memory_size&quot;: xxx,<br>    &quot;payload_compression&quot;: xxx,<br>    &quot;payload_minimum_compression_size&quot;: xxx,<br>    &quot;lambda_description&quot;: &quot;xxx&quot;,<br>    &quot;vpc_config&quot;: {<br>      &quot;SubnetIds&quot;: [xxx],<br>      &quot;SecurityGroupIds&quot;: [xxx]<br>    }<br>  },<br>  &quot;prod_base&quot;: {<br>    ... (생략) ...<br>  },<br>  &quot;prod&quot;: {<br>    &quot;extends&quot;: &quot;prod_base&quot;,<br>    &quot;events&quot;: [{<br>      &quot;function&quot;: &quot;task_1&quot;,<br>      &quot;expression&quot;: &quot;cron(0/2 * * * ? *)&quot;<br>    }, {<br>      &quot;function&quot;: &quot;task_2&quot;,<br>      &quot;expression&quot;: &quot;cron(* * * * ? *)&quot;<br>	  },]<br>		... (생략) ...<br>  },<br>  &quot;prod_asia&quot;: {<br>    ... (생략) ...<br>  },<br>  &quot;test&quot;: {<br>    &quot;extends&quot;: &quot;dev&quot;,<br>    ... (생략) ...<br>  },<br>  ... (생략) ...<br>}</pre><h3>마치며</h3><p>이 글에서는 서버리스의 의미, 비프로가 서버리스 아키텍처를 채택한 이유 그리고 Zappa를 통한 AWS 서버리스 환경을 구성하는 방법을 간단하게 설명 드렸습니다.</p><p>Zappa는 이 글에서 살펴본 서버리스 배포 기능뿐만 아니라 Lambda를 활용할 수 있는 여러 가지 기능들을 지원하고 있습니다. 예를 들어 애플리케이션 로직에서 쉽게 Lambda 함수를 직접 호출하여 <a href="https://github.com/zappa/Zappa#asynchronous-task-execution">비동기 태스크</a>를 돌릴 수 있도록 하거나, <a href="https://github.com/zappa/Zappa#scheduling">스케쥴러</a>를 등록하여 정기적인 태스크를 Lambda 함수로 실행할 수 있도록 하는 등의 기능을 제공합니다.</p><p>비프로에서는 최종적으로 <a href="https://github.com/features/actions">Github Actions</a>과 Zappa 를 통해 서버리스 및 배포 환경을 구축하였고 이러한 환경을 통해 개발자들이 좀 더 비즈니스 로직에 집중할 수 있었습니다. 현재에도 비프로에서는 서버리스 환경 개선을 위해 해결해야 하는 문제들이 남아 있고, 이러한 문제들을 해결하기 위해 끊임없이 고민하고 있습니다.</p><p>그리고 만약 Python 서버리스 환경 구축을 고민하고 계셨다면 이 글이 도움이 되었기를 바라면서 마치겠습니다. 감사합니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TvPQJPCVZDidWmepmsay8g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba799f154c48" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bepro-team-blog/%EB%B9%84%ED%94%84%EB%A1%9C%EB%8A%94-%EC%84%9C%EB%B2%84%EB%A6%AC%EC%8A%A4-%EC%95%84%ED%82%A4%ED%85%8D%EC%B2%98%EB%A5%BC-%EC%96%B4%EB%96%BB%EA%B2%8C-%EC%9A%B4%EC%98%81%ED%95%98%EA%B3%A0-%EC%9E%88%EC%9D%84%EA%B9%8C-ba799f154c48">비프로는 서버리스 아키텍처를 어떻게 운영하고 있을까?</a> was originally published in <a href="https://medium.com/bepro-team-blog">Bepro Team Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Python Severless Services Operate at Bepro]]></title>
            <link>https://medium.com/bepro-team-blog/serverless-python-web-services-5b9c1e4382b?source=rss----e74c0f0d560f---4</link>
            <guid isPermaLink="false">https://medium.com/p/5b9c1e4382b</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[zappa]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[serverless-architecture]]></category>
            <dc:creator><![CDATA[Woojin]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 13:14:03 GMT</pubDate>
            <atom:updated>2022-09-20T13:20:32.237Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dl5NSVk0L73qJBwq73hCqw.png" /></figure><p>Most of Bepro’s backend services are written in Python. A Main API service is one of them. The service is currently operating in a serverless architecture and we are deploying it through <a href="https://github.com/zappa/Zappa">Zappa</a>, a serverless open source management tool.</p><p>In this article, I would like to briefly introduce how Python serverless services operate at Bepro.</p><h3>What is Serverless ?</h3><p>Before we talk about serverless at Bepro, I think it would be good to take a brief look at serverless itself. First, let us take a look at what the “Big Three” cloud vendors are saying about serverless.</p><p><a href="https://aws.amazon.com/serverless/"><strong>Amazon AWS</strong></a></p><blockquote><em>Build and run applications without thinking about servers</em></blockquote><p>AWS provide several serverless services. (<a href="https://aws.amazon.com/lambda/">Lambda</a>, <a href="https://aws.amazon.com/api-gateway/">API Gateway</a>, <a href="https://aws.amazon.com/rds/aurora/serverless/">Aurora Serverless</a> etc.)</p><p><a href="https://cloud.google.com/serverless"><strong>Google Cloud</strong></a></p><blockquote><em>Develop and deploy highly scalable applications and functions on a fully managed serverless platform.</em></blockquote><p>They also provide some serverless services.(<a href="https://cloud.google.com/run/?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=japac-AU-all-en-dr-bkws-all-pkws-trial-e-dr-1009882&amp;utm_content=text-ad-none-none-DEV_c-CRE_602771386312-ADGP_Hybrid%20%7C%20BKWS%20-%20EXA%20%7C%20Txt%20~%20Compute%20~%20Cloud%20Run_cloud%20run-general%20-%20Products-44225-KWID_43700071610100400-aud-970366092687%3Akwd-678836618089&amp;userloc_9045957-network_g&amp;utm_term=KW_google%20cloud%20run&amp;gclsrc=aw.ds&amp;gclid=Cj0KCQjwhqaVBhCxARIsAHK1tiNjesfaaPfoaCIB5uKR8tuDlJQ7v1fQUv0c9ZZKNp8kHZ_Rt-Q-BnoaAsL6EALw_wcB">Cloud Run</a>, <a href="https://cloud.google.com/functions/?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=japac-KR-all-en-dr-bkws-all-all-trial-b-dr-1009882&amp;utm_content=text-ad-none-none-DEV_c-CRE_248280173489-ADGP_Hybrid%20%7C%20BKWS%20-%20PHR%20%7C%20Txt%20~%20Serverless%20Computing%20~%20Cloud%20Functions_cloud%20functions-KWID_43700065777621434-aud-970366092687%3Akwd-298528048746&amp;userloc_9045957-network_g&amp;utm_term=KW_google%20cloud%20functions&amp;gclsrc=aw.ds&amp;gclid=Cj0KCQjwhqaVBhCxARIsAHK1tiNm9AJbEMDt6gChC4zJdFu5TOQmfHObpvg2CNoO7eSxTuXV-tE7KIMaApP5EALw_wcB">Cloud Functions</a> etc.)</p><p><a href="https://azure.microsoft.com/en-us/overview/serverless-computing/"><strong>MS Azure</strong></a></p><blockquote><em>The serverless name comes from the fact that the tasks associated with infrastructure provisioning and management are invisible to the developer.</em></blockquote><p>Finally, Martin Fowler’s blog (<a href="https://martinfowler.com/articles/serverless.html">martinfowler.com</a>), one of my favourite technical blogs, also talks about serverless.</p><blockquote><em>Serverless had become a dominant name for this area, giving way to the birth of the </em><a href="http://serverlessconf.io/"><em>Serverless Conference</em></a><em> series, and various Serverless vendors embracing the term in everything from product marketing to job descriptions.</em></blockquote><p>As a result, it would be good to think of serverless as an <strong>“environment where developers can develop without having to worry about infrastructure”</strong>, through serverless services provided by cloud vendors such as the “Big Three” discussed above. In addition, the above <a href="http://martinflower.com/">martinfowler.com</a> article explains in detail the concept, pros and cons of serverless, so if you are interested, I strongly recommend that you read it before moving on.</p><h3>Why did Bepro adopt Serverless?</h3><p>Why did Bepro adopt a serverless environment?</p><h4>Limited development resources</h4><p>One of the most important reasons is the situation at Bepro where we had to utilise limited resources as efficiently as possible at the beginning of the business. We needed an environment in which a few developers could develop and operate our products without considering infrastructures as much as possible, rather than hiring new DevOps developers, because we were not sure how quickly our service would grow at the time.</p><h4>API traffic patterns</h4><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*pKvXfljNHhc4f4AwwYCgBg.png" /></figure><p>This is a typical API call pattern (measured every second) for three hours on a weekend. The server handles 10 to 20 times the normal request for a very short time. This is very irregular(depending on match schedules). In normal situations, relatively few infrastructure resources are sufficient to handle this traffic, but resources must be scaled out or up for a short time in order to guarantee the same performance at peak times. These traffic patterns are very irregular depending on weekends/weekdays and seasonal/nonseasonal periods.</p><p>In this situation, we need to either maintain infrastructure resources which can handle peak traffic, or configure an auto-scaling environment. In the former case, cost is wasted, and in the latter case, it might be scaled up or out too late, because the traffic has already decreased as resources are scaled up or out. As mentioned above, our resources (especially developers) were quite limited when it came to manage infrastructure, considering these factors.</p><p>In a serverless environment, developers do not have to worry about these traffic patterns, since cloud vendors that provide serverless services manage their infrastructure on their own. By taking a serverless approach we thought our developers could concentrate on developing business logic and features. We could also launch our new features at speed thanks to serverless.</p><h4>Cost</h4><p>In addition to the system operation perspective, we roughly compared the estimated cost of an AWS serverless environment and a traditional server environment. (Specific costs such as RDS, Load Balancer, and S3 are not considered for approximate estimation purposes only.)</p><p><em>Assumptions: 2,000,000 requests / month</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*z5uew6ZUwWfDNwNDF9hhSA.png" /></figure><p>We can see that the AWS serverless environment is about 70% cheaper.</p><p>Bepro adopted a serverless environment, despite some disadvantages such as limited number of concurrent executions, limited execution time, cold start delay, etc. (<a href="https://martinfowler.com/articles/serverless.html#benefits">See general pros and cons of serverless</a>.)</p><h3>Serverless Architecture at Bepro</h3><p>We decided to use AWS serverless services. Bepro’s architecture is shown in brief below. (Details such as CDN, S3, etc. are omitted to show a serverless environment only.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Efc5Vab-duQFtptcRs6yAg.png" /></figure><p>We tried to optimise our API response latency by configuring Europe and Asia as multiple regions to provide global services. We also deployed a Lambda environment using Docker containers. All of this serverless management is done by Zappa, an open source tool.</p><h3>Deploying Python Web Services with Zappa</h3><p>Now, we are going to deploy Python web services with Zappa.</p><p>If you deploy web services to AWS serverless without Zappa, you will have a headache because there are so many things to consider, such as IAM Role, code packaging, API Gateway/Lambda settings, etc. — Zappa handles all of this automatically.</p><p>Let us see how to deploy a Docker based serverless Python Django web service with Zappa.</p><h3>Django Project Settings</h3><p>First, create a <a href="https://docs.python.org/3/library/venv.html">Python virtual environment</a> and install <a href="https://www.djangoproject.com/">Django</a>.</p><pre>(venv)&gt; pip install django</pre><p>Create a Django project.</p><pre>(venv)&gt; django-admin startproject zappa-example<br>(venv)&gt; cd zappa-example</pre><p><a href="https://docs.djangoproject.com/en/4.0/ref/settings/#allowed-hosts">ALLOWED_HOSTS</a> in Django settings has been modified. Also, we’ve commented out <a href="https://docs.djangoproject.com/en/4.0/ref/settings/#databases">database related settings</a> to run this example smoothly.</p><pre>... (skip) ...<br>ALLOWED_HOSTS = [&quot;*&quot;]<br>... (skip) ...<br># DATABASES = {<br>#     &#39;default&#39;: {<br>#         &#39;ENGINE&#39;: &#39;django.db.backends.sqlite3&#39;,<br>#         &#39;NAME&#39;: &#39;mydatabase&#39;,<br>#     }<br># }<br>... (skip) ...</pre><p>Run a Django server on your local environment.</p><pre>(venv) python manage.py runserver</pre><pre>Watching for file changes with StatReloader<br>Performing system checks...</pre><pre>System check identified no issues (0 silenced).</pre><pre>You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.<br>Run &#39;python manage.py migrate&#39; to apply them.<br>June 14, 2022 - 15:09:23<br>Django version 4.0.5, using settings &#39;zappa_example.settings&#39;<br>Starting development server at &lt;http://127.0.0.1:8000/&gt;<br>Quit the server with CONTROL-C.</pre><p>We can connect to the local Django server through your browser. (In this example, we will not implement any functions, but simply test by accessing the Django admin login page.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*I3mE9D60b69kPm0vIjOrEQ.png" /></figure><h3>Zappa Settings</h3><p>We need to set our <a href="https://aws.amazon.com/ko/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/">AWS credentials</a> prior to completing our Zappa settings</p><p>First, install awscli.</p><pre>&gt; pip install awscli</pre><p>Set AWS credentials using aws configure command.</p><pre>&gt; aws configure</pre><p>Install the Zappa library on your Python virtual environment that you created above.</p><pre>(venv)&gt; pip install zappa</pre><p>Before initialising Zappa, create a requirements.txt file to specify dependencies. (It will be used for deploying with Docker later.)</p><pre>(venv)&gt; pip freeze &gt;&gt; requirments.txt</pre><p>Initialise Zappa.</p><pre>(venv)&gt; zappa init</pre><p>We will go into the interactive mode for Zappa settings. I proceeded with the default values. A thing to note in the middle of the conversation is that Zappa recognised that our directory is a Django project and set it up automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*76zQLlqcn36E42PGoq6fMw.png" /></figure><p>Enter “ls” command.</p><pre>(venv)&gt; ls<br>db.sqlite3          manage.py           zappa_example       zappa_settings.json</pre><p>A file zappa_settings.json has been created. Let us see the contents of that file.</p><pre>{<br>    &quot;dev&quot;: {<br>        &quot;aws_region&quot;: &quot;ap-northeast-2&quot;,<br>        &quot;django_settings&quot;: &quot;zappa_example.settings&quot;,<br>        &quot;profile_name&quot;: &quot;default&quot;,<br>        &quot;project_name&quot;: &quot;zappa-example&quot;,<br>        &quot;runtime&quot;: &quot;python3.8&quot;,<br>        &quot;s3_bucket&quot;: &quot;zappa-yyamukhwg&quot;<br>    }<br>}</pre><p>A stage dev has been created. (Default.) You can create multiple stages (staging, production, etc.) and each can be deployed.</p><p>aws_region : AWS region to be deployed.<br>django_settings : If it is Django project, specify the Django settings file path.<br>profile_name : AWS CLI configuration profile.<br>project_name : project name for Lambda function.<br>runtime : Runtime environment for Lambda (not required for deploying with Docker image).<br>s3_bucket : The s3 bucket to upload the deployment package (zip file) to.</p><p>Zappa deployment is super easy.</p><pre>(venv)&gt; zappa deploy dev</pre><pre>... (skip) ...<br>Deployment complete!: &lt;https://7qi7rn36uf.execute-api.ap-northeast-2.amazonaws.com/dev&gt;</pre><p>Compress the code into a zip file, upload it to the S3 bucket, create Lambda function, set API Gateway, etc. — Zappa handles multiple deployment processes with only one command.</p><p>We can check the admin page can be accessed by using the last output url. (Style is not applied because static files are not deployed.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*q84KSqhM1Gqf08NEQAUk6w.png" /></figure><p>We can remove our deployed application completely.</p><pre>(venv)&gt; zappa undeploy</pre><p>Next, we are going to deploy with a Docker image.</p><h3>Building a Docker Image</h3><p>Create a Dockerfile.</p><pre>FROM amazon/aws-lambda-python:3.8  # 1</pre><pre>ARG FUNCTION_DIR=&quot;/var/task/&quot;</pre><pre>WORKDIR ${FUNCTION_DIR}</pre><pre>COPY ./ ${FUNCTION_DIR}</pre><pre># Install packages<br>RUN pip install -r requirements.txt</pre><pre># Grab the zappa handler.py and put it in the working directory<br>RUN ZAPPA_HANDLER_PATH=$( \\<br>    python -c &quot;from zappa import handler; print (handler.__file__)&quot; \\<br>    ) \\<br>    &amp;&amp; echo $ZAPPA_HANDLER_PATH \\<br>    &amp;&amp; cp $ZAPPA_HANDLER_PATH ${FUNCTION_DIR}</pre><pre>CMD [ &quot;handler.lambda_handler&quot; ]  # 2</pre><p>#1 : We used a Lambda based image provide by AWS(<a href="https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-base">See</a>)</p><p>#2 : Run a lambda handler provided by Zappa. (It will handle API Gateway requests and route them to the Django server.)</p><p>Create a settings file for Docker deployment before building an image.</p><pre>(venv)&gt; zappa save-python-settings-file dev</pre><p>zappa save-python-settings-file &lt;stage_name&gt; format</p><p>In general, with zip file based Zappa deployment, a python setting file is packaged into the zip file. The same file (zappa_settings.py) is created and will be included in the Docker image.</p><p>Now build an image.</p><pre>&gt; docker build -t zappa-example:latest .</pre><h3>Pushing a Docker Image</h3><p>Create an AWS ECR Repository.</p><pre>&gt; aws ecr create-repository --repository-name zappa-example --image-scanning-configuration scanOnPush=true</pre><p>Retag.</p><pre>&gt; docker tag zappa-example:latest XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><p>Log in to the AWS ECR you created above.</p><pre>&gt; aws ecr get-login-password | docker login --username AWS --password-stdin XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example</pre><p>Push the image to the ECR.</p><pre>&gt; docker push XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><h3>Deploying with a Docker Image</h3><p>Finally, deploying a Serverless Web Service with Docker image to AWS serverless.</p><pre>(venv)&gt; zappa deploy dev -d XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><pre>... (skip) ...<br>Deployment complete!: &lt;https://g9vu4sutk2.execute-api.ap-northeast-2.amazonaws.com/dev&gt;</pre><p>Check if the deployment is successful by accessing the output URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*_kuV24zFn3PXj7aNIXM2xQ.png" /></figure><p>If you have already deployed your application, then you are required to update your latest application code on AWS by using the following commands.</p><pre>(venv)&gt; zappa save-python-settings-file dev<br>&gt; docker build -t XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest .<br>&gt; docker push XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest<br>(venv)&gt; zappa update dev -d XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><p>Use zappa update rather than zappa deploy</p><h3>Custom Domain with SSL</h3><p>We will use <a href="https://aws.amazon.com/route53/">AWS Route 53</a> for domain and <a href="https://aws.amazon.com/certificate-manager/">AWS Certificate Manager</a> for SSl certificate.</p><p>I assume that Domain and Certificate have been issued completely.</p><p>First, modify zappa_settings.json, adding domain and certificate_arn value.</p><pre>{<br>    &quot;dev&quot;: {<br>        &quot;aws_region&quot;: &quot;ap-northeast-2&quot;,<br>        &quot;django_settings&quot;: &quot;zappa_example.settings&quot;,<br>        &quot;profile_name&quot;: &quot;default&quot;,<br>        &quot;project_name&quot;: &quot;zappa-example&quot;,<br>        &quot;s3_bucket&quot;: &quot;zappa-yyamukhwg&quot;,<br>        **&quot;domain&quot;: &quot;zappa.cwoojin.com&quot;,**<br>        **&quot;certificate_arn&quot;: &quot;arn:aws:acm:us-east-1:XXXXXXXXXXXX:certificate/eba3fd6b-a1f4-4e6a-b5d6-fe7aa8c88649&quot;**<br>    }<br>}</pre><p>Finally, just deploy!</p><pre>(venv)&gt; zappa certify<br>(venv)&gt; zappa update dev -d XXXXXXXXXXXX.dkr.ecr.ap-northeast-2.amazonaws.com/zappa-example:latest</pre><pre>..(skip)...<br>Your updated Zappa deployment is live!: &lt;https://zappa.cwoojin.com&gt; (&lt;https://g9vu4sutk2.execute-api.ap-northeast-2.amazonaws.com/dev&gt;)</pre><p>Check if the connection to the registered domain is successful. (<a href="https://zappa.cwoojin.com/">https://zappa.cwoojin.com</a>.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*RlFvDQ_RQpjQ7YywXVEdbQ.png" /></figure><p>The basic deployment setup is now complete.</p><p>(Do not forget to undeploy this example from your AWS.)</p><h3>Zappa Settings at Bepro</h3><p>I share some parts of the zappa_settings.json that we use at Bepro.</p><p>Bepro operates a deployment environment divided into multiple stages (dev, test, prod, etc.)</p><p>Please see a Zappa official document for <a href="https://github.com/zappa/Zappa#advanced-usage">advanced Zappa usage</a>.</p><pre>{<br>  &quot;dev&quot;: {<br>    &quot;aws_region&quot;: &quot;eu-central-1&quot;,<br>    &quot;django_settings&quot;: &quot;xxx&quot;,<br>    &quot;project_name&quot;: &quot;xxx&quot;,<br>    &quot;s3_bucket&quot;: &quot;xxx&quot;,<br>    &quot;environment_variables&quot;: {<br>      ...<br>    },<br>    &quot;certificate_arn&quot;: &quot;xxx&quot;,<br>    &quot;domain&quot;: &quot;xxx&quot;,<br>    &quot;route53_enabled&quot;: false,<br>    &quot;cors&quot;: {<br>      &quot;allowed_headers&quot;: [xxx]<br>    },<br>    &quot;exception_handler&quot;: &quot;xxx&quot;,<br>    &quot;keep_warm_expression&quot;: &quot;xxx&quot;,<br>    &quot;memory_size&quot;: xxx,<br>    &quot;payload_compression&quot;: xxx,<br>    &quot;payload_minimum_compression_size&quot;: xxx,<br>    &quot;lambda_description&quot;: &quot;xxx&quot;,<br>    &quot;vpc_config&quot;: {<br>      &quot;SubnetIds&quot;: [xxx],<br>      &quot;SecurityGroupIds&quot;: [xxx]<br>    }<br>  },<br>  &quot;prod_base&quot;: {<br>    ... (skip) ...<br>  },<br>  &quot;prod&quot;: {<br>    &quot;extends&quot;: &quot;prod_base&quot;,<br>    &quot;events&quot;: [{<br>      &quot;function&quot;: &quot;task_1&quot;,<br>      &quot;expression&quot;: &quot;cron(0/2 * * * ? *)&quot;<br>    }, {<br>      &quot;function&quot;: &quot;task_2&quot;,<br>      &quot;expression&quot;: &quot;cron(* * * * ? *)&quot;<br>	  },]<br>		... (skip) ...<br>  },<br>  &quot;prod_asia&quot;: {<br>    ... (skip) ...<br>  },<br>  &quot;test&quot;: {<br>    &quot;extends&quot;: &quot;dev&quot;,<br>    ... (skip) ...<br>  },<br>  ... (skip) ...<br>}</pre><h3>Conclusions</h3><p>In this article, I briefly explained what serverless means, why Bepro adopted serverless, and how to deploy python serverless web services with Zappa.</p><p>Zappa supports various features as well as the serverless deployment feature explained in this article. For example, it provides features like making it easy to invoke a Lambda function directly from application logic to run <a href="https://github.com/zappa/Zappa#asynchronous-task-execution">asynchronous tasks</a>, or registering <a href="https://github.com/zappa/Zappa#scheduling">schedulers</a> to run regular tasks as Lambda functions.</p><p>We finally built a serverless deployment environment using <a href="https://github.com/features/actions">Github Actions</a> and Zappa. The environment allowed our developers to focus more on business logic. Even now, there are still problems that need to be solved to improve the serverless environment and we are constantly thinking about solving these problems.</p><p>Finally, if you are thinking about building a Python Serverless Web Services, I hope this article was helpful.</p><p>Thank you!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mN01aqTJ5OeyNj8_HLkwcw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b9c1e4382b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bepro-team-blog/serverless-python-web-services-5b9c1e4382b">How Python Severless Services Operate at Bepro</a> was originally published in <a href="https://medium.com/bepro-team-blog">Bepro Team Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[비프로는 파이어베이스 동적 링크를 어떻게 활용하고 있을까]]></title>
            <link>https://medium.com/bepro-team-blog/%EB%B9%84%ED%94%84%EB%A1%9C%EB%8A%94-%ED%8C%8C%EC%9D%B4%EC%96%B4%EB%B2%A0%EC%9D%B4%EC%8A%A4-%EB%8F%99%EC%A0%81-%EB%A7%81%ED%81%AC%EB%A5%BC-%EC%96%B4%EB%96%BB%EA%B2%8C-%ED%99%9C%EC%9A%A9%ED%95%98%EA%B3%A0-%EC%9E%88%EC%9D%84%EA%B9%8C-490434753d4a?source=rss----e74c0f0d560f---4</link>
            <guid isPermaLink="false">https://medium.com/p/490434753d4a</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[앱개발]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[dynamic-link]]></category>
            <dc:creator><![CDATA[Bepro]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 17:36:21 GMT</pubDate>
            <atom:updated>2022-08-22T17:36:21.089Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cg1gpr9m1Q82uiqYThl7nw.png" /></figure><h3>파이어베이스 동적 링크란?</h3><p>파이어베이스 동적 링크(Firebase Dynamic Links)는 2016년에 발표된 이래로 수많은 서비스에서 사용되고 있는 기술로 사용자가 간단히 링크를 통해 특정 페이지에 도달할 수 있게 도와준다. 2022년 현재, 등장한지 6년이나 지난 전혀 새로울 것 없는 이 기술에 대해 테크 블로그 글을 작성하려고 하는지 의아한 분도 있을 것이다. 하지만 비프로 서비스에 왜 동적 링크가 필요한지, 이를 통해 어떤 문제를 해결하고 유저에게 어떤 경험을 주고 싶은지 이야기해 본다면 우리 서비스에 익숙하지 않은 사람들도 비프로 서비스가 추구하는 방향이 무엇인지 이해하는 데 도움이 될 것 같아 작성해 본다.</p><p>본격적으로 비프로에서 동적 링크를 어떻게 사용하고 있는지 알아보기에 앞서 동적 링크가 어떤 과정을 거쳐 진화했는지 알아보자.</p><ol><li><a href="https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml"><strong>URI Scheme</strong></a><strong><br></strong>딥링크의 초기 형태로 scheme://path (e.g. myapp://demo)와 같은 방식을 사용하는데 폴백(fallback) 처리를 할 수 있는 옵션이 없어서 앱이 설치되어 있지 않으면 에러 페이지를 보게 된다. 그리고 myapp이라는 scheme이 여러 앱에서 사용될 수 있어 같은 scheme이 다른 앱에도 사용되고 있으면 URI scheme을 클릭했을 때 바로 우리 앱을 띄우지 못할 수도 있고, 앱이 설치되어 있어야만 작동한다는 단점이 있다.</li><li><strong>딥링크(Deep Link)</strong>— 유니버설 링크(<a href="https://developer.apple.com/ios/universal-links/">Universal link</a>) for iOS, 앱링크(<a href="https://developer.android.com/training/app-links">App link</a>) for Android<br>URI scheme 방식을 따르며 브라우저를 열거나 url을 로딩하지 않고 앱을 바로 실행시키기 때문에 빠르다는 장점이 있다. 하지만 URI scheme 방식과 마찬가지로 앱이 설치되어 있어야만 작동한다.</li><li><strong>지연된 딥링크(Deferred Deep Link)<br></strong>딥링크의 단점을 보완한 방식으로 앱이 설치되어 있지 않아도 유저가 앱 설치 후 해당 페이지를 바로 볼 수 있지만 iOS와 Android 각각의 sdk를 사용해 구현해 줘야 하는 번거로움이 있다.</li><li><strong>동적 링크</strong>(<a href="https://firebase.google.com/docs/dynamic-links"><strong>Dynamic Link</strong></a><strong>)<br></strong>지연된 딥링크의 단점을 보완한 방식으로 하나의 링크로 iOS와 Android에서 모두 사용 가능하다.</li></ol><p>즉, 동적 링크란, 기존 링크 방식들의 단점을 해결한 버전으로 앱이 설치되어 있지 않아도 광고나 프로모션 페이지 혹은 랜딩 페이지를 통해 유저를 앱의 특정 페이지로 이동시켜 유저 스스로 별다른 액션을 하지 않아도 원하는 화면을 볼 수 있게 해주는 기술이다.</p><h3>비프로 서비스에 동적 링크가 필요한 이유</h3><p>비프로 서비스에 동적 링크가 왜 필요하고 실제로 이를 어떻게 활용하고 있는지 설명하기에 앞서 우선 비프로 서비스가 어떤 방식으로 유저에게 제공되는지 간략히 살펴보고 넘어가자.</p><p>비프로는 구단 혹은 협회와 계약을 맺고 각 팀에 소속된 코치와 선수들에 한해 서비스를 제공하는 B2B 서비스를 메인으로 운영하고 있다. 이렇게 B2B 계약을 바탕으로 서비스에 진입한 유저들은 비프로 스페이스 내에서 경기/훈련 영상 촬영, 시청 그리고 분석 데이터 조회, 더 나아가 영상 편집 및 분석까지 할 수 있다. 다시 말해, 비프로는 스포츠 경기 영상/분석과 관련된 모든 것을 하나의 프로덕트 안에서 해결할 수 있는 올인원 플랫폼인 셈이다.</p><p>하지만 보통의 B2C 서비스처럼 일반 유저가 가입해서 바로 서비스를 사용하는 것은 불가능하고, 클라이언트 구단에 소속된 선수와 코치도 회원가입 시 본인 인증 후 각 팀에 생성되어 있는 본인의 프로필에 연동하는 과정이 필요하다. 따라서 우연히 비프로를 접하고 서비스에 호기심을 갖게 된 잠재 유저가 바로 서비스를 직접 경험해보기는 쉽지 않다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*7BlqIfZS3DSJTxRMHPlg8g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*7K4R2QOWIZdqTRgEFP4AOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*Q3MhWSHzKmYrBVpWmsbsqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*XGVYacdeIkKSru7ERAzCHg.png" /></figure><ol><li>회원가입을 마치면 다음과 같은 온보딩 절차를 거치게 된다. 팀에서 선수와 스태프 중 어떤 역할을 맡고 있는지 선택하고 다음 단계로 넘어간다.</li><li>역할을 선택한 뒤, 자신이 소속된 팀을 국가&gt;리그 목록에서 찾거나 혹은 팀명으로 검색한다.</li><li>소속팀을 찾았다면 해당 팀에 소속된 선수 명단을 볼 수 있는데, 유저-선수 프로필 간 연동이 되어 있는 선수와 연동이 되어 있지 않은 선수로 나뉜다. 연동이 되어 있는 선수라 함은 유저가 ‘제가 선수 본인입니다. 이 프로필에 제 계정을 연동해 주세요’라는 요청을 보내서 수락된 상황을 의미한다. 연동이 되어 있지 않은 선수는 아직 유저가 가입을 하지 않았거나 유저가 선수 프로필 연동 요청을 하지 않은 상태라고 생각하면 된다. 그럼 연동 버튼을 눌러서 연동(Link) 요청을 해보자.</li><li>그럼 다음과 같은 화면을 볼 수 있는데, 선수 프로필 연동 신청은 선수 본인 계정으로만 가능하기 때문에 앞서 설명한 대로 비프로와 계약된 팀에 소속되지 않은 유저는 안타깝게도 아직은 비프로 서비스를 쓸 수 없다.</li></ol><p>비프로는 위와 같은 이유로 서비스 진입이 불가능한 유저도 비프로 서비스를 경험해 볼 수 있도록 데모 페이지를 제공한다. 데모 페이지에서는 데모 매치의 라인업, 패스 데이터, 팀/선수 스탯 등의 경기 분석 데이터와 하이라이트, 선수 볼터치, 경기 이벤트 등의 다양한 영상을 볼 수 있다. 따라서 아직 유효한 계약이 없는 유저들도 데모 페이지에 접속해서 비프로 서비스를 통해 어떤 기능을 제공받는지 체험해 볼 수 있다.</p><h3>동적 링크 동작 및 구현</h3><p>그럼 데모 페이지로 유저를 유도하기 위해서는 어떤 과정을 거치는지 <a href="https://www.bepro11.com/">비프로 랜딩 페이지</a>로 가서 살펴보자.</p><p>비프로 랜딩 페이지에서는 아래처럼 비프로에 대한 소개와 프로덕트 패키지 등의 정보를 볼 수 있다. 우측 상단의 메뉴 버튼을 눌러보자.</p><p>메뉴 페이지 하단에 See the Demo 버튼이 있는데, 웹에서 해당 버튼을 누르면 웹 데모 페이지로 연결되고 모바일에서 누르면 모바일 데모 페이지로 연결된다. 이때 비프로 앱이 설치되어 있지 않아도 바로 앱 설치 후 바로 데모 페이지로 연결되는데 이것이 바로 파이어베이스 동적 링크의 역할이다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XzUtzrqTPQzSFbkUhjQEPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzbu-YwBRv9xzci0aocx1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*9o2XsurEsU2BEZJi1H-9FQ.gif" /></figure><p>유저들이 이와 같은 동적 링크를 잘 사용할 수 있도록 하려면 사전 작업이 필요하다. 먼저 동적 링크를 생성한 후, iOS와 Android 앱에서 동적 링크를 수신할 수 있는 환경을 마련해야 한다.</p><p>파이어베이스에서 제공하는 <a href="https://firebase.google.com/docs/dynamic-links/create-links">가이드</a>를 따라 하면 어렵지 않게 마무리할 수 있다. 앱이 추가됐다는 전제하에 동적 링크 생성 방법을 간략히 알아보자.</p><p><a href="https://console.firebase.google.com/">파이어베이스 콘솔</a>에 로그인하고 좌측 메뉴에서 Engage &gt; Dynamic Links(한글 포스팅의 경우, 참여 &gt; Dynamic Links)를 클릭하면 다음과 같은 화면이 나온다.</p><p><strong>1. 단축 URL 링크 설정<br></strong>URL prefix 다음에 나오는 path를 정의하는데, 앱에서 동적 링크를 수신할 때 해당 path를 가지고 처리를 하게 된다. 여기서는 demo-test라고 작성을 해보았다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*b7ix4hbRHEI7Pe6Ngg6SEQ.png" /></figure><p><strong>2. 동적 링크 설정<br></strong>여기서의 딥링크 URL은 설명에 나와있는 것처럼 데스크톱에서 동적 링크를 누를 경우 어느 URL로 이동시켜줄지 작성하면 된다. 비프로에서는 웹 데모 페이지(https://space.bepro11.com/demo)를 입력했다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*AZrx1kK-8QS4SRJfoWIoaQ.png" /></figure><p><strong>3. iOS 링크 정의<br></strong>iOS 앱에서 동적 링크를 클릭했을 때 어떻게 처리할지 설정한다. 첫 번째 옵션의 경우, 브라우저를 띄워 2번 단계에서 작성한 웹 데모 페이지로 이동시키기 때문에 필요가 없고 두 번째 옵션을 선택했다. 이때, 프로덕션 앱을 실행시킬지 개발 버전의 앱을 실행시킬지 선택할 수 있는데, 개발 중인 앱에서 테스트할 동적 링크와 프로덕션 앱에서 사용할 동적 링크를 각각 만들어 두면 편리하다.<br>다음 옵션은 앱이 설치되어 있지 않을 때 유저를 어디로 보낼지 선택하는 옵션이다. 앱 설치를 위해 앱스토어로 보낼 수도 있지만 동적 링크를 클릭했을 때의 이후 과정을 설명해 주는 페이지를 만들어 Custom URL에 넣어주면 유저가 이후 상황을 인식하는 데 큰 도움이 될 것이다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*O05ftcSdrgJNC7Z_0okkGQ.png" /></figure><p><strong>4. Android 링크 정의<br></strong>안드로이드도 iOS와 마찬가지로 설정하면 된다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*RCU98afS0gFaxD4GZDZNXg.png" /></figure><p><strong>5. 캠페인 추적 설정 (옵션)<br></strong>동적 링크를 추적할 수 있는 기능으로 유저들의 유입률이나 어떤 경로를 통해서 들어왔는지 측정할 수 있어서 추후 마케팅에 유용하게 활용할 수 있다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*yGqd4WiLBTIOvdpznZz9sA.png" /></figure><p>6. 앱 구현 과정은 튜토리얼 수준이기 때문에 아래 링크를 보고 따라하면 된다.<br>- <a href="https://firebase.google.com/docs/dynamic-links/ios/receive">iOS 동적 링크 수신</a><br>- <a href="https://firebase.google.com/docs/dynamic-links/android/receive">안드로이드 동적 링크 수신</a></p><h3>비프로가 나아가고자 하는 방향</h3><p>현재는 데모 페이지에만 동적 링크가 적용되어 있는데, 향후에는 동적 링크를 통해 보다 다양한 방법으로 유저 유입(user retention)을 높일 수 있는 방안을 모색 중이다. 예를 들면, 오늘 경기에 있었던 나의 득점 장면 링크를 소셜 미디어나 메신저로 공유하여 친구들과 비프로 앱에서 함께 영상을 보며 소통할 수 있는 환경을 만들고자 한다.</p><p>그리고 더 나아가서는 축구를 넘어 더욱 다양한 종목과 비프로 서비스를 접목시키고 전 세계 스포츠인들이 비프로 스페이스에서 본인의 경기 영상과 데이터를 확인하며 이를 통해 선수들이 발전하고 성장하는 데 도움이 되는 환경을 구축하려는 비전을 그리고 있다.</p><p>스포츠인이라면 프로, 아마추어 레벨 상관없이 누구나 자신의 인생 골 장면을 소장하고 공유하는 것이 당연한 시대가 하루빨리 올 수 있도록 하는 게 앞으로의 비프로의 역할이 아닐까 생각한다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nWXbktOSPyWcDzikFOVZRw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=490434753d4a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bepro-team-blog/%EB%B9%84%ED%94%84%EB%A1%9C%EB%8A%94-%ED%8C%8C%EC%9D%B4%EC%96%B4%EB%B2%A0%EC%9D%B4%EC%8A%A4-%EB%8F%99%EC%A0%81-%EB%A7%81%ED%81%AC%EB%A5%BC-%EC%96%B4%EB%96%BB%EA%B2%8C-%ED%99%9C%EC%9A%A9%ED%95%98%EA%B3%A0-%EC%9E%88%EC%9D%84%EA%B9%8C-490434753d4a">비프로는 파이어베이스 동적 링크를 어떻게 활용하고 있을까</a> was originally published in <a href="https://medium.com/bepro-team-blog">Bepro Team Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Bepro Uses Firebase Dynamic Links]]></title>
            <link>https://medium.com/bepro-team-blog/how-bepro-uses-firebase-dynamic-links-961306bcb719?source=rss----e74c0f0d560f---4</link>
            <guid isPermaLink="false">https://medium.com/p/961306bcb719</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[dynamic-link]]></category>
            <dc:creator><![CDATA[Bepro]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 17:15:00 GMT</pubDate>
            <atom:updated>2022-09-05T15:58:22.949Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J7NIl1-WrUq5yV3dAO_Ijg.png" /></figure><h3>What is Firebase Dynamic Link?</h3><p>Released in 2016, Firebase Dynamic Link is a technology used by a number of services that allows users to easily reach specific pages through links. As of 2022, there may be questions as to why I would choose to write a tech blog post for a technology that has been around for six years. However, if we begin the conversation about why dynamic links are essential to Bepro’s services, what problems we want to solve, and what kind of experiences we want to provide our users, it will help people unfamiliar to our services better understand the direction Bepro is pursuing with our services.</p><p>Before looking into how Dynamic Link is used by Bepro, let’s first see how Dynamic Link has advanced.</p><ol><li><a href="https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml"><strong>URI Scheme</strong></a><strong><br></strong>As the initial form of Deep Link, it uses the same method as scheme://path (e.g. myapp://demo) but since there is no option to process fallback, users will land on the error page if the app is not installed. Moreover, since the myapp scheme can be used in numerous apps, if the same scheme is used on other apps, it may not immediately load our app when the URI scheme is clicked, and can only operate when the app is installed.</li><li><strong>Deep Link </strong>— <a href="https://developer.apple.com/ios/universal-links/">Universal link</a> for iOS, <a href="https://developer.android.com/training/app-links">App link</a> for Android<br>It follows the URI scheme method and therefore, has the advantage of speed as it immediately executes the app instead of opening a browser or loading a URL. However, just like the URI scheme method, it only works when the app is installed.</li><li><strong>Deferred Deep Link<br></strong>As the method supplementing the drawbacks of Deep Link, it allows users to view the relevant pages after installing the app even if it is not installed, but there is an inconvenience of having to use each iOS and Android’s SDKs.</li><li><a href="https://firebase.google.com/docs/dynamic-links"><strong>Dynamic Link</strong></a><strong><br></strong>As the method supplementing the drawbacks of the Deferred Deep Link, it can be used on iOS and Android with a single link.</li></ol><p>In other words, Dynamic Link is the solution that has solved the drawbacks of other existing link methods. This technology takes the user’s app to a specific page through ads, promotional pages, or landing pages, whether or not your app is already installed, to allow users to view their desired page without taking any particular actions.</p><h3>Why is Dynamic Link necessary for Bepro?</h3><p>Before explaining why Dynamic Link is necessary for Bepro and how it is being used, let’s briefly examine how the Bepro service is being provided to our users.</p><p>Bepro mainly operates a B2B service that provides services to the coaches and players belonging to the clubs and associations under contract. Users entering the service based on the B2B contract can record and watch match and training videos, inquire about analysis data, and edit and analyse video content, all within the Bepro space. In other words, Bepro is an all-in-one platform enabled to provide everything related to sports match videos and analysis within one product.</p><p>Nevertheless, just like general B2C services, it is impossible for general users to sign-up and immediately use the service. Even players and coaches belonging to a client club must verify their identity while signing up before linking their ID to their profile generated in their team. Hence, it is not easy for a potential user who has discovered Bepro themselves to experience the service right away.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*LG2do16fK3Q4J_ARJ5EZ0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*f8GI9cDKcOoNGVy0aoPu7A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*nXgkjWbKQZdxj9u8bpHTsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*H9_stFDth-4D5C6DzR1EfQ.png" /></figure><ol><li>Once the user has signed up, they will go through the onboarding process. The user selects their role between player and staff before moving on to the next step.</li><li>After selecting their role, the user must find their team under the Country → League list or search by team name.</li><li>Once the user has found their team, they will be able to view the roster. This roster is divided into players who have linked their user ID and player profile and players who have not. Being a linked player means that the user had sent a request to say, “I am this player. Please link my account to this profile,” and the request was accepted. Player profiles that are not linked can be considered as the user not having signed up yet or the user not having made the request to link their player profile. Now, let’s try to click on the button to make the link request.</li><li>The user will then land on the following screen. Since the player profile link request can only be made with the player’s actual account, users not belonging to a team contracted with Bepro cannot use the Bepro service, as mentioned above.</li></ol><p>Bepro provides a demo page to allow users who can’t access our service for reasons stated above to experience the Bepro service. On the demo page, users can view match analysis data, including the lineup, pass data, and team/player stats, and watch various video content, including highlights, player ball touch, and match events of the demo match. Therefore, users without valid contracts may experience what functions are provided through the Bepro service by accessing the demo page.</p><h3>Dynamic Link Operation &amp; Implementation</h3><p>Then, let’s visit and examine the Bepro landing page to see the steps taken to attract users to the demo page.</p><p>On the Bepro landing page, users can view Bepro’s introduction and product packages, as shown below. Let’s click on the menu button in the upper right corner.</p><p>At the bottom of the menu page, there is a “See the Demo” button. When users click on this button from the web, it connects to the web demo page, and when clicked on the mobile site, it connects to the mobile demo page. Even if the Bepro app is not installed, it will connect the user to the demo page immediately after installing the app. This is the role of Firebase Dynamic Link!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XzUtzrqTPQzSFbkUhjQEPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzbu-YwBRv9xzci0aocx1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*9o2XsurEsU2BEZJi1H-9FQ.gif" /></figure><p>To allow users to make good use of such dynamic links requires preliminary work. First, you must create a dynamic link before preparing the environment to receive the dynamic link from the iOS and Android apps.</p><p>This can be easily completed when following the guide provided by Firebase. Let’s briefly look at the dynamic link creation method under the premise that the app has been added.</p><p>If you log in to the Firebase console and click Engage &gt; Dynamic Links from the left side menu, you will land on the following screen.</p><p><strong>1. Set up short URL Link<br></strong>This defines the path following the URL prefix. When receiving a dynamic link from the app, it is processed with this path. Here, I used demo-test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*b7ix4hbRHEI7Pe6Ngg6SEQ.png" /></figure><p><strong>2. Set up Dynamic Link<br></strong>As written in the description, you must list which URL to send the user to when they click on the dynamic link from a desktop. I entered the web demo page (<a href="https://space.bepro11.com/demo">https://space.bepro11.com/demo</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*AZrx1kK-8QS4SRJfoWIoaQ.png" /></figure><p><strong>3. Define link behavior for iOS<br></strong>This sets up the process for what happens when the dynamic link is clicked from the iOS app. There is no need for the first option since it opens the browser to send the user to the web demo page set up in step 2, so option 2 was selected. Here, you can select whether to run the production app or the development version app and it is convenient if you made the dynamic link to test from the app in development, as well as the dynamic link to use from the production app. The following is an option to select where to send the user when the app is not installed. You can choose to send the user to the app store for installing the app, but it will be good help for the user to recognise the situation if you place a custom URL by creating a page explaining the process after clicking on the dynamic link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*O05ftcSdrgJNC7Z_0okkGQ.png" /></figure><p><strong>4. Define link behavior for Android<br></strong>The Android can be set up the same as the iOS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*RCU98afS0gFaxD4GZDZNXg.png" /></figure><p><strong>5. Campaign tracking (optional)<br></strong>By enabling the tracking function the number of users and their journeys can be measured, which is useful for marketing purposes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*yGqd4WiLBTIOvdpznZz9sA.png" /></figure><p>6. Since the app implementation process is available as a tutorial, you can just follow the directions on the following links.<br>- <a href="https://firebase.google.com/docs/dynamic-links/ios/receive">Receive Dynamic Links on iOS</a><br>- <a href="https://firebase.google.com/docs/dynamic-links/android/receive">Receive Dynamic Links on Android</a></p><h3>Bepro’s Vision</h3><p>At the present time, dynamic links are only applied to the demo page, but we are searching for measures to increase user retention with various methods using the dynamic links. For example, we are trying to create an environment where your goal video links can be shared via social media or Bepro Messenger to watch the video on the Bepro app with friends.</p><p>Furthermore, Bepro has a vision to move beyond football to integrate the Bepro service with various sport events, and construct an environment that helps the developments and advancements of the world’s athletes by enabling them to view their match videos and data within the Bepro space.</p><p>We believe that it is our role to create a world where owning and sharing your best goal and performance videos is natural, whether you are a professional or an amateur.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VmSlkHV0rhMMZubC2LJjYw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=961306bcb719" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bepro-team-blog/how-bepro-uses-firebase-dynamic-links-961306bcb719">How Bepro Uses Firebase Dynamic Links</a> was originally published in <a href="https://medium.com/bepro-team-blog">Bepro Team Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[자바스크립트로 360˚ 비디오 플레이어 구현하기]]></title>
            <link>https://medium.com/bepro-team-blog/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%A1%9C-360-%EB%B9%84%EB%94%94%EC%98%A4-%ED%94%8C%EB%A0%88%EC%9D%B4%EC%96%B4-%EA%B5%AC%ED%98%84%ED%95%98%EA%B8%B0-957a9f23366d?source=rss----e74c0f0d560f---4</link>
            <guid isPermaLink="false">https://medium.com/p/957a9f23366d</guid>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[3d-video]]></category>
            <category><![CDATA[360-video]]></category>
            <dc:creator><![CDATA[Jiho Hong]]></dc:creator>
            <pubDate>Mon, 09 May 2022 21:41:48 GMT</pubDate>
            <atom:updated>2022-05-09T21:41:48.213Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sTSU1Yef6Okxy0bpuRDDsA.png" /></figure><h3>TL;DR</h3><p>이 글에서는 THREE.js를 사용해서 360˚ 비디오 플레이어를 구현하는 방법을 다룬다. 아래 링크에 전체 코드가 있으니 시간이 없다면 바로 아래 링크를 확인해보자.</p><p><a href="https://gist.github.com/bepro-dev/a640f0c2048d4d02a063476ee8a2a3a3">https://gist.github.com/bepro-dev/a640f0c2048d4d02a063476ee8a2a3a3</a></p><p>결과물은 <a href="https://s.bepro11.com/vr-player/index.html">여기</a>에서 확인할 수 있다.</p><h3>비프로 비디오 플레이어</h3><p>비프로는 경기장에 다수의 카메라를 설치하여 사용자에게 제공할 경기 영상을 촬영한다. 각 경기장에 설치되는 카메라의 수는 두 대에서 네 대 사이인데, 이는 카메라가 설치된 지점과 경기장 사이의 거리, 카메라의 높이, 그리고 카메라가 경기장을 내려다보는 각도 등에 의해서 결정된다. 이렇게 여러 대의 카메라에서 촬영된 영상은 각각의 이미지에서 겹치는 영역에 있는 특징점들을 기준으로 합쳐져서 경기장 전체를 한 화면에 담을 수 있는 파노라믹 영상으로 가공된다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k_0TiUV38S-vB8kp3wwRuw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVqUkPW2sv6AnxIyqyEDtQ.png" /><figcaption>참고: 비프로 유튜브, <a href="https://www.youtube.com/watch?v=8Nuc6CeU32M">최첨단 영상 처리 기술</a></figcaption></figure><p>이렇게 가공된 파노라믹 영상은 일반적인 영상에 비해 화각이 굉장히 넓어서 왜곡 또한 심하기 때문에 이러한 영상을 바로 사용자에게 전달하기에는 무리가 있다. 그래서 비프로에서는 이 영상을 그대로 사용하지 않고 왜곡을 없앨 수 있는 특수한 비디오 플레이어를 사용한다. 비프로의 사용자거나 비프로에 관심이 있어서 <a href="https://www.bepro11.com/demo/">비프로 서비스 데모 페이지</a>를 이용해본 적이 있다면 비프로 3D 비디오 플레이어를 경험해봤을 것이다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2z2ay8kqbc_0QYQYflr9Q.png" /><figcaption>비프로 서비스 데모 페이지(<a href="https://www.bepro11.com/demo/">https://www.bepro11.com/demo/</a>) 내의 3D 비디오 플레이어</figcaption></figure><p>비프로 3D 비디오 플레이어로 재생되는 영상은 원본 파노라믹 영상과는 다르게 왜곡이 없고, 영상의 확대/축소도 가능하며 화면을 자유자재로 돌려서 경기장 내의 원하는 지점을 볼 수도 있다.</p><p>비프로에서는 각 플랫폼 별로 다양한 언어로 이 비디오 플레이어를 구현해놓았는데, 이 글에서는 웹 브라우저에서 사용할 수 있는 자바스크립트 버전의 360˚ 비디오 플레이어를 구현하는 방법에 대해서 소개하겠다.</p><h3>원리</h3><p>비프로 3D 비디오 플레이어의 작동 방식은 기본적으로 360˚ 비디오 플레이어와 동일하다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jgtbdd-eLWYEfPIq7aurdw.png" /></figure><p>다만 앞서 말했다시피 비프로의 픽스캠 영상은 카메라가 설치되는 위치와 조건에 따라 화면 안에 담기는 경기장의 형태가 다르다. 이 때문에 일반적인 360˚ 비디오 플레이어의 화각이 가로 360도, 세로 180도로 되어있는 것과 달리 비프로의 파노라믹 영상은 경기장에 따라 다양한 화각을 가지며 이에 따라 구 전체가 아니라 영상에 맞게 구의 일부분만 사용하는 등의 특수한 처리가 필요하다. 따라서 이 글에서는 더 보편적으로 사용되는 360˚ 비디오 플레이어를 예시로 설명하려 한다.</p><p><strong>3D Engine</strong></p><p>360˚ 비디오 플레이어는 3D 엔진을 사용하면 간단하게 구현할 수 있다. 3D 엔진에 대한 이해가 없어도 본 튜토리얼을 따라하는 데에는 무리가 없지만, 간략하게나마 이해하고 싶다면 아래 개념들을 한번 훑어보고 넘어가자.</p><p><strong>3D 엔진에서 사용되는 기본적인 개념들</strong></p><blockquote>Scene, Renderer, Camera</blockquote><p>3D 엔진으로 무언가를 시각적으로 표현하기 위해서는 Scene, Renderer, 그리고 Camera가 필요하다. Scene은 가상의 3차원 공간이라고 생각할 수 있다. Scene 내에 여러 3D Object와 가상의 Camera를 배치하고, 가상의 Camera로 촬영된 장면을 Renderer를 통해서 화면에 표시한다.</p><blockquote>Perspective Camera, Orthographic Camera</blockquote><p>카메라의 종류로는 Perspective camera와 Orthographic camera 두 가지가 있다. Perspective camera를 사용하면 원근감이 느껴지는 3D 이미지를 얻을 수 있고, Orthographic camera를 사용하면 3D Scene을 2D처럼 화면에 표시할 수 있다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgqLnE1z4oG193GcDW223w.png" /><figcaption>Perspective Camera</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OuZmCy2imXu130sByDgdhQ.png" /><figcaption>Orthographic Camera</figcaption></figure><blockquote>Geometry, Material, Mesh</blockquote><p>Scene에 추가할 3D Object를 생성하기 위해서는 Geometry, Material, Mesh가 필요하다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vWBPLgyu3_ErwoBdhvNBSQ.png" /><figcaption>이미지: <a href="https://threejs.org/docs/index.html#api/en/geometries/SphereGeometry">https://threejs.org/docs/index.html#api/en/geometries/SphereGeometry</a></figcaption></figure><p>3D 엔진에서 각각의 Object는 작은 삼각형 여러 개로 이루어져있는데, Geometry는 이 삼각형들의 꼭지점에 해당하는 점들(vertices)과 각 삼각형의 면(faces)에 관한 정보를 가지고 있다.</p><p>Material은 Object의 표면이 어떻게 보여질지를 결정한다. 단순하게 하나의 색상으로 칠할 수도 있고, Shader를 사용해서 좀 더 복잡한 패턴이나 다양한 색상을 표현할 수도 있으며, 이미지를 Texture로 물체 표면에 입힐 수도 있다.</p><p>Mesh는 삼각형들로 이루어진 3D object인데, Scene에 실제로 추가되는 물체의 단위가 된다. 이 글에서 사용할 THREE.js에서는 Material이 geometry의 표면을 결정하고, Mesh를 통해서 물체의 위치, 크기, 방향 등을 설정한다.</p><p>3D 엔진을 통한 360˚ 비디오 플레이어 구현은 다음과 같은 단계로 이루어진다.</p><ol><li>Scene 생성</li><li>구(Sphere) 생성</li><li>구 가운데에 Perspective camera 배치</li><li>구의 안쪽 면에 영상 입히기</li></ol><p>이를 실제로 어떻게 구현할 수 있는지 단계 별로 코드와 함께 보자.</p><h3>360˚ 비디오 플레이어 구현하기</h3><p>비프로에서는 널리 쓰이는 자바스크립트 3D 엔진인 THREE.js(<a href="https://threejs.org/">https://threejs.org/</a>)를 사용해서 3D 비디오 플레이어를 구현했다.</p><p>1. THREE.js 설치 (<a href="https://threejs.org/docs/#manual/en/introduction/Installation">https://threejs.org/docs/#manual/en/introduction/Installation</a>)</p><p>npm 등의 패키지 매니저를 통해서 설치할 수도 있고, CDN으로 제공되는 버전을 사용할 수도 있다. 이 튜토리얼에서는 현재(22년 3월 18일) 기준 <a href="https://cdnjs.com/libraries/three.js">cdnjs</a> 에서 제공하는 최신 버전인 r128 버전을 사용한다.</p><ul><li>npm (<a href="https://www.npmjs.com/package/three">https://www.npmjs.com/package/three</a>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S4vYFfQ31TrN9EdxoF2aXg.png" /></figure><ul><li>CDN</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cJQ5l4DEFrzCRA94Vy3jyQ.png" /></figure><p><strong>2. Scene 생성</strong></p><p>3D 엔진을 통해서 화면에 무언가를 표시하기 위해서는 먼저 Scene을 생성해야한다. 이후에 이 Scene에 여러 물체와 카메라를 추가하게 된다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KvzYruwGl3Al9UEItnRDSQ.png" /></figure><p><strong>3. 카메라 배치 및 화면에 Renderer 추가</strong></p><p>카메라를 만드는 순서가 중요하지는 않지만, 진행하면서 중간 결과를 확인할 수 있도록 카메라를 먼저 만들고 화면에 Renderer를 추가하자.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1jM4HR1eXVwSrdCtdEOdw.png" /></figure><p>PerspectiveCamera의 near, far 파라미터는 각각 카메라로부터의 거리인데, 이 범위 안에 있는 물체만 화면에 보이게 된다. 아래 이미지에서 Near Clip과 Far Clip 사이의 사각뿔대 형태의 도형 내부가 실제 화면에 보이는 영역이다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*9gihTsD_Xu2P69tgROHe4w.png" /></figure><p>여기서는 WebGLRenderer의 생성자에 아무 옵션도 넣지 않았지만, WebGLRenderer는 이미지 품질과 성능에 영향을 줄 수 있는 다양한 옵션을 제공한다. 자세한 내용은 <a href="https://threejs.org/docs/#api/en/renderers/WebGLRenderer">THREE.js 문서</a>를 참고하자.</p><p>여기까지 잘 따라했다면 화면에 640x480 크기의 검은 사각형이 보일 것이다.</p><p><strong>4. 구 생성</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zKCQO5lBIQYMEuvsj53G1Q.png" /></figure><p>SphereGeometry 생성자에 넘겨준 세 값은 각각 radius, widthSegments, heightSegments이다. 우리는 PerspectiveCamera를 구의 중앙에 배치할 예정이기 때문에 radius가 보이는 모양에 영향을 주지는 않지만, PerspectiveCamera의 near와 far 값 사이에 있어야 실제로 화면에 그려지게 된다.</p><p>widthSegments와 heightSegments는 각각 구를 가로/세로로 몇 개의 삼각형으로 나눌지 결정하는 값으로, 많은 수로 나눌수록 이미지 품질은 좋아지지만 당연하게도 성능은 저하된다.</p><blockquote>widthSegments, heightSegments에 따른 품질 비교</blockquote><ul><li>widthSegments=8, heightSegments=4</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*kp7AQLZYrvkXfuTDKx1Grg.png" /></figure><ul><li>widthSegments=32, heightSegments=16</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*GQHjWaQMepSe8I3jyKcFEg.png" /></figure><ul><li>widthSegments=32, heightSegments=16</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AF1kD-jdvUuKhqWmkUzKyg.png" /></figure><ul><li>widthSegments=128, heightSegments=64</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhtP-J_PW1bfWyq7PC2ZXQ.png" /></figure><p><strong>5. 구의 안쪽 면에 영상 입히기</strong></p><p>영상을 입히기 전에 구가 잘 만들어졌는지 확인해보자.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0gSJGILu9RB5zaN9urfWwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*dKnO9-wIHxXWFemiO8ECDQ.png" /></figure><p>파란 구 한가운데에 카메라가 위치해 있기 때문에 화면 전체가 파랗게 보인다. 카메라 위치를 조금 조정해보자. 카메라의 위치와 방향을 따로 설정해주지 않았다면 카메라는(0, 0, 0) 점에서 -z 방향을 보고 있게 된다. 구의 반지름을 15로 설정했으니, 카메라를 15보다 멀리 +z 방향으로 이동시키자.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3eJ0izUr73EzCij3hFBDZg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*pzOqua_IHcT6-GjJhGmpIg.png" /></figure><p>구면에 영상을 입히기 위해서는 THREE.js의 VideoTexture를 사용한다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hf96ItEu6eZOuGs_BGHyUg.png" /></figure><p>material.side 를 THREE.BackSide 로 설정해주었는데, 3D 오브젝트 표면을 구성하고 있는 삼각형들은 방향이 있고 방향에 맞게 텍스쳐가 입혀진다. THREE.js의 SphereGeometry의 기본 방향은 구의 바깥쪽을 향하고 있다. 하지만 우리는 카메라를 구의 내부에 배치했기 때문에 텍스쳐를 보기 위해서는 삼각형의 뒷면(구의 안쪽 면)을 사용해야 한다.</p><p><strong>6. Animation Loop 시작</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3wbLszTyHIoBpWHxemKEBg.png" /></figure><p>renderer.render() 함수를 호출하면 한 번만 화면을 업데이트 하기 때문에, 재생되는 영상을 보여주기 위해서는 renderer.setAnimationLoop 함수를 사용해서 매 프레임마다 화면을 업데이트 해주어야 한다.</p><p>검은 사각형 대신 왜곡이 펴진 영상이 재생되는 것을 확인할 수 있을 것이다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*wF5EVvdFf3D-cU8cobvheg.png" /></figure><p><strong>7. 확대, 축소, 회전</strong></p><p>이제 360˚ 비디오 플레이어에 꼭 필요한 확대/축소 기능과 화면 회전을 구현해보자. 이 기능들은 카메라를 조작해서 구현할 수 있다.</p><blockquote>확대, 축소</blockquote><p>줌 인/아웃을 구현하기 위해서는 카메라의 FOV를 변경하면 된다. FOV를 줄이면 renderer의 크기에는 변화가 없지만 보이는 영역이 좁아져서 좁은 영역이 확대가 되고, 반대로 FOV를 늘리면 더 넓은 영역이 한 화면에 들어오기 때문에 축소가 된다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iqesqx169M5gFhLy3NFNUw.png" /></figure><blockquote>회전</blockquote><p>카메라를 포함한 3D object들은 position과 rotation값을 가지고 있는데, 기본값은 모두 {x: 0, y: 0, z: 0} 으로 설정되어있다. 물체를 회전시키기 위해서는 <a href="https://threejs.org/docs/#api/en/core/Object3D">Object3D</a>의 .rotateX(), .rotateY(), .rotateZ() 함수를 사용하면 된다. 각각 x축, y축, z축을 기준으로 물체를 회전시키는 함수이다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fH1t94quvifkB6zx5ice5A.png" /></figure><p>이제 마우스 휠을 돌려서 영상을 확대/축소 할 수 있고, 화면을 드래그해서 영상의 다른 부분을 볼 수 있다.</p><h3>결과물</h3><p>이 글에서 작성한 코드의 결과물은 <a href="https://s.bepro11.com/vr-player/index.html">여기</a>에서 확인할 수 있다. 전체 코드는 아래 링크에서 볼 수 있으니 작성한 코드가 정상적으로 작동하지 않는다면 아래 코드와 비교해보자.</p><p><a href="https://gist.github.com/bepro-dev/a640f0c2048d4d02a063476ee8a2a3a3">https://gist.github.com/bepro-dev/a640f0c2048d4d02a063476ee8a2a3a3</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBUkqBeYLzZpr6GsEbIdoA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=957a9f23366d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bepro-team-blog/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%A1%9C-360-%EB%B9%84%EB%94%94%EC%98%A4-%ED%94%8C%EB%A0%88%EC%9D%B4%EC%96%B4-%EA%B5%AC%ED%98%84%ED%95%98%EA%B8%B0-957a9f23366d">자바스크립트로 360˚ 비디오 플레이어 구현하기</a> was originally published in <a href="https://medium.com/bepro-team-blog">Bepro Team Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement a 360˚ Video Player in JavaScript]]></title>
            <link>https://medium.com/bepro-team-blog/implement-a-360-video-player-in-javascript-41c1ddcd61bb?source=rss----e74c0f0d560f---4</link>
            <guid isPermaLink="false">https://medium.com/p/41c1ddcd61bb</guid>
            <category><![CDATA[360-video]]></category>
            <category><![CDATA[3d-video]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Jiho Hong]]></dc:creator>
            <pubDate>Mon, 09 May 2022 21:09:03 GMT</pubDate>
            <atom:updated>2022-05-09T21:37:18.224Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u0n-lZLMfWujoMexF9HwzA.png" /></figure><h3>TL;DR</h3><p>This article covers how to implement a 360˚ video player in JavaScript. You can find the complete code on the following link:</p><p><a href="https://gist.github.com/bepro-dev/a640f0c2048d4d02a063476ee8a2a3a3">https://gist.github.com/bepro-dev/a640f0c2048d4d02a063476ee8a2a3a3</a></p><p>And <a href="https://s.bepro11.com/vr-player/index.html">here</a> is the final result.</p><h3>Bepro Video Player</h3><p>We (Bepro) install multiple cameras next to a pitch to film matches or trainings for our clients. The number of cameras installed at each pitch is between two and four, which is determined by the distance between the cameras and the ground, the height of the cameras and the angle at which the cameras look down to the ground.</p><p>Images taken by each camera are stitched based on the feature points in the overlapping area in each image and processed into a panoramic image that can capture the entire pitch on a screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k_0TiUV38S-vB8kp3wwRuw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVqUkPW2sv6AnxIyqyEDtQ.png" /><figcaption>Reference: Bepro YouTube channel, <a href="https://www.youtube.com/watch?v=8Nuc6CeU32M">State-of-the-Art Video Technology</a></figcaption></figure><p>However, these panoramic images have a very wide field of view (FOV) which makes videos look distorted. To give a better viewing experience to our users, we developed a special video player to display videos without distortion. You may have had a chance to take a look at our 3D video player if you have already tried our service or have visited the <a href="https://www.bepro11.com/demo/">Bepro demo website</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2z2ay8kqbc_0QYQYflr9Q.png" /><figcaption>3D Video Player in the Bepro demo page (<a href="https://www.bepro11.com/demo/">https://www.bepro11.com/demo/</a>)</figcaption></figure><p>Unlike the original panoramic video, the videos played with Bepro’s 3D Video Player have no distortion and the video can be zoomed in/out and users can freely rotate their view to see wherever inside the pitch.</p><p>Bepro has implemented this video player in multiple languages for each platform. We’re going to take you through the steps you need to take to implement a 3D video player in JavaScript, which can then be used in a web browser.</p><h3>Fundamentals</h3><p>Bepro’s 3D Video Player basically works the same as a general 360˚ video player.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jgtbdd-eLWYEfPIq7aurdw.png" /></figure><p>However, as mentioned earlier, the shape of the ground captured by each camera differs depending on the location and conditions where the cameras are installed. Accordingly, Bepro’s panoramic video has various FOVs depending on the pitch, which makes it hard to apply the mechanism of general 360˚ video player which have FOV of 360 degrees horizontally and 180 degrees vertically. Therefore, in Bepro’s 3D Video Player additional processing is required to use only a certain part of the sphere, not the entirety of it.</p><p>In this article, we’re going to practise with the example of the general 360˚ video player which is more commonly used.</p><p><strong>3D Engine</strong></p><p>You can easily implement a 360˚ video player if you use a 3D Engine. It’s not necessary to have experienced a 3D engine to follow this tutorial, but please read the brief introduction of a 3D Engine below if you want to understand the basics of it.</p><p><strong>Basic concepts in a 3D Engine</strong></p><blockquote>Scene, Renderer, Camera</blockquote><p>A scene, a renderer and a camera are needed to display something with a 3D Engine. A scene is like a virtual 3D space. After placing 3D objects and a virtual camera in a scene, you can render the image captured by the virtual camera on the screen through a renderer.</p><blockquote>Perspective Camera, Orthographic Camera</blockquote><p>There are two types of cameras — perspective and orthographic. A perspective camera is used to display 3D graphics while an orthographic camera is used to display 2D images although the scene itself is 3D.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgqLnE1z4oG193GcDW223w.png" /><figcaption>Perspective Camera</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OuZmCy2imXu130sByDgdhQ.png" /><figcaption>Orthographic Camera</figcaption></figure><blockquote>Geometry, Material, Mesh</blockquote><p>To create a 3D object which will be shown in the scene, a geometry, a material and a mesh are needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vWBPLgyu3_ErwoBdhvNBSQ.png" /><figcaption>Image: <a href="https://threejs.org/docs/index.html#api/en/geometries/SphereGeometry">https://threejs.org/docs/index.html#api/en/geometries/SphereGeometry</a></figcaption></figure><p>In a 3D Engine, each object consists of multiple triangles and a geometry contains information of vertices and faces of these triangles.</p><p>A material decides how the surface of an object will be rendered. The object can be painted with a solid colour, a complex pattern or multiple colours by using a Shader, or covered with an image as a texture.</p><p>A mesh is a 3D object made up of triangles, which is the unit of an object that is actually displayed in the Scene. In THREE.js, the material defines the surface of the geometry, and the position, size and direction of the object are set through the mesh.</p><p>Implementing 360˚ video player through a 3D Engine can be carried out in the following steps:</p><ol><li>Create a scene</li><li>Create a sphere</li><li>Place a perspective camera in the centre of the sphere</li><li>Put a video as a texture on the inner surface of the sphere</li></ol><p>Now, let’s look at each step in more detail with working code.</p><h3>Implementing a 360˚ Video Player</h3><p>To implement a 360˚ video player, we are using THREE.js (<a href="https://threejs.org/">https://threejs.org/</a>) which is a popular JavaScript 3D Engine.</p><p><strong>1. Create an HTML file and install THREE.js</strong><br>(<a href="https://threejs.org/docs/#manual/en/introduction/Installation">https://threejs.org/docs/#manual/en/introduction/Installation</a>)<br>THREE.js can be installed via a package manager like npm or from CDN. We are going to use r128 version which is the most recent version at the moment(18/03/2022) served by <a href="https://cdnjs.com/libraries/three.js">cdnjs</a>.</p><ul><li>npm (<a href="https://www.npmjs.com/package/three">https://www.npmjs.com/package/three</a>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S4vYFfQ31TrN9EdxoF2aXg.png" /></figure><ul><li>CDN</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cJQ5l4DEFrzCRA94Vy3jyQ.png" /></figure><p><strong>2. Create a Scene</strong></p><p>First of all, we need to create a scene to display something with a 3D Engine. A camera and other objects will be added to this scene.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KvzYruwGl3Al9UEItnRDSQ.png" /></figure><p><strong>3. Place a Camera and add a Renderer to the screen</strong></p><p>We can create a camera anytime before rendering, but let’s create it first and then add a renderer to the screen so that interim results can be checked during the tutorial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1jM4HR1eXVwSrdCtdEOdw.png" /></figure><p>The value of near and far parameters of PerspectiveCamera are distances from the camera respectively and objects only between near and far are captured by the camera and displayed on the screen. The frustum between Near Clip and Far Clip in the image below is the area which will be shown on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*9gihTsD_Xu2P69tgROHe4w.png" /></figure><p>Although we didn’t pass any arguments to the constructor of WebGLRenderer, it provides some options by default to optimise image quality and performance. You can check the details in <a href="https://threejs.org/docs/#api/en/renderers/WebGLRenderer">THREE.js documentation</a>.</p><p>Now we can see a black rectangle on the screen.</p><p><strong>4. Create a sphere</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zKCQO5lBIQYMEuvsj53G1Q.png" /></figure><p>The three values we passed to the SphereGeometry constructor are radius, widthSegments and heightSegments. The radius doesn’t affect the visible shape since we are going to place a PerspectiveCamera in the centre of the sphere, but it has to be bigger than near and smaller than far of PerspectiveCamera to actually be displayed on the screen.</p><p>widthSegments and heightSegments define how many triangles the sphere should be divided into horizontally/vertically, and the larger the number, the better the image quality but of course the performance decreases.</p><blockquote>Compare the quality depending on different widthSegments and heightSegments values</blockquote><ul><li>widthSegments=8, heightSegments=4</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*kp7AQLZYrvkXfuTDKx1Grg.png" /></figure><ul><li>widthSegments=32, heightSegments=16</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*GQHjWaQMepSe8I3jyKcFEg.png" /></figure><ul><li>widthSegments=32, heightSegments=16</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AF1kD-jdvUuKhqWmkUzKyg.png" /></figure><ul><li>widthSegments=128, heightSegments=64</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhtP-J_PW1bfWyq7PC2ZXQ.png" /></figure><p><strong>5. Put a video on the inner surface of the sphere</strong></p><p>Let’s check the sphere before putting a video.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0gSJGILu9RB5zaN9urfWwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*dKnO9-wIHxXWFemiO8ECDQ.png" /></figure><p>The whole screen looks blue since the camera is inside of the blue sphere. Let’s move the camera a bit so that we can see the sphere from outside. If the position or rotation values are not given separately, the camera is located on (0, 0, 0) and looking at -z direction by default. As we’ve set radius of the sphere to 15, let’s move the camera farther than 15 to +z direction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3eJ0izUr73EzCij3hFBDZg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*pzOqua_IHcT6-GjJhGmpIg.png" /></figure><p>To cover the sphere with a video, we can use a VideoTexture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hf96ItEu6eZOuGs_BGHyUg.png" /></figure><p>You can see the material.side is set to THREE.BackSide. Triangles consisting the surface of a sphere are facing outside by default and if we put a texture on them, it can only be seen from the outside of the sphere. But as we put the camera inside of the sphere, the material should be set to BackSide - to make the triangles face inward towards the centre of the sphere.</p><p><strong>6. Start Animation Loop</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3wbLszTyHIoBpWHxemKEBg.png" /></figure><p>As the screen is updated only once when the function renderer.render() is called, it must be updated for every frame using the function renderer.setAnimationLoop() to show the video being played.</p><p>Now you can see the undistorted video being played instead of a black rectangle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*wF5EVvdFf3D-cU8cobvheg.png" /></figure><p><strong>7. Zoom in/out and rotation</strong></p><p>It’s time to implement the essential features of a 360˚ video player, zoom in, zoom out and rotation. These can be implemented by controlling the virtual camera.</p><blockquote>Zoom in/out</blockquote><p>Zoom in/out can be implemented by changing the FOV value of the camera. Reducing the FOV does not change the size of the renderer but it narrows the visible area which enlarges the screen, while increasing the FOV reduces the screen by enlarging the visible area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iqesqx169M5gFhLy3NFNUw.png" /></figure><blockquote>Rotation</blockquote><p>Every 3D object including the camera have position and rotation values and all their default values are {x: 0, y: 0, z: 0}. To rotate an object, use the function .rotateX(), .rotateY() and .rotateZ() in <a href="https://threejs.org/docs/#api/en/core/Object3D">Object3D</a>. These functions rotate the object based on the x, y and z axis respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fH1t94quvifkB6zx5ice5A.png" /></figure><p>Now you can zoom in/out by rolling your mouse wheel and drag the screen to see other parts of the image.</p><h3>Result</h3><p>You can find the final result <a href="https://s.bepro11.com/vr-player/index.html">here</a> and check the complete code in the following link. Compare it with your code in case yours doesn’t work properly.</p><p><a href="https://gist.github.com/bepro-dev/a640f0c2048d4d02a063476ee8a2a3a3">https://gist.github.com/bepro-dev/a640f0c2048d4d02a063476ee8a2a3a3</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MoYlCuXOf4jRhcPJ4DSpBA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41c1ddcd61bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bepro-team-blog/implement-a-360-video-player-in-javascript-41c1ddcd61bb">Implement a 360˚ Video Player in JavaScript</a> was originally published in <a href="https://medium.com/bepro-team-blog">Bepro Team Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we are adopting MLOps at Bepro]]></title>
            <link>https://medium.com/bepro-team-blog/mlops-pipeline-a3c38b36980?source=rss----e74c0f0d560f---4</link>
            <guid isPermaLink="false">https://medium.com/p/a3c38b36980</guid>
            <category><![CDATA[mlops-solution]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Alexey Rozhkov]]></dc:creator>
            <pubDate>Tue, 05 Apr 2022 13:29:14 GMT</pubDate>
            <atom:updated>2022-04-08T11:51:52.950Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m9mOiYsNtQ2UuiqIp3ww5A.png" /></figure><p>Are you tired of manually managing datasets and trying to keep track of which one you used for a particular experiment?</p><p>Or maybe you trained your production model several years ago and are afraid of touching it now, even though the data it is dealing with now might be different?</p><p>Perhaps you don’t care about any of that, and just want to improve your model’s metrics, but after trying all the architecture and hyperparameter combinations still ended up short?</p><p>Quite surprisingly, in all of these scenarios, you might benefit from “adopting MLOps”.</p><p>Here we’ll describe some steps which we took in this direction, hoping that these might be useful or at least interesting.</p><h3>What’s MLOps?</h3><p>Before we proceed, we must first agree on what exactly MLOps is. Let’s consult some big companies first.</p><p><a href="https://cloud.google.com/architecture/mlops-continuous-delivery-and-automation-pipelines-in-machine-learning">Google Cloud documentation</a>:</p><blockquote>MLOps<em> is an ML engineering culture and practice that aims at unifying ML system development (Dev) and ML system operation (Ops).</em></blockquote><p>Hmm, this was not particularly enlightening.</p><p><a href="https://blogs.nvidia.com/blog/2020/09/03/what-is-mlops/">NVIDIA blog</a>:</p><blockquote><em>A shorthand for machine learning operations, MLOps is a set of best practices for businesses to run AI successfully.</em></blockquote><p>Now that’s more interesting, but still fairly vague.</p><p><a href="https://azure.microsoft.com/en-gb/services/machine-learning/mlops/">Azure (Microsoft) documentation</a>:</p><blockquote><em>MLOps — machine learning operations, or DevOps for machine learning — enables data science and IT teams to collaborate and increase the pace of model development and deployment via monitoring, validation, and governance of machine learning models.</em></blockquote><p>I guess that’s as detailed as it gets.</p><p>If we try to summarise these definitions, MLOps is a set of practices that help in AI model development.</p><p>But it we <a href="https://www.youtube.com/watch?v=06-AZXmwHjo&amp;t=368s">ask Andrew Ng</a> — the answer is going to be somewhat different. It can be roughly rephrased as — if we seek to improve the performance of the system, perhaps we should focus less on the models, and more on the data, and in the linked video he provides some examples of the motivation for this.</p><p>These two perspectives do not directly contradict, yet the difference in what is being emphasised tells us an important thing — MLOps is interesting for different reasons, and it depends on whom are you “selling it” to, a business owner or an engineer, an enterprise company or a startup.</p><p>Perhaps another way to put it would be analysing the main potential for improvement in an ML service — better metrics? less manual work for each model update iteration? more stable deployments? less regressions? and then systematically addressing it with some concrete measures.</p><p>This would mean that “adopting MLOps” is somewhat of an umbrella term, which might mean different things for different companies at different stages, so to be more specific we’ll focus on particular aspects that were important to us at Bepro.</p><h3>MLOps at Bepro</h3><p>For us, it seemed that the best starting point for employing MLOps practices would be for automating dataset collection procedures and to make it happen at regular intervals.</p><p>Previously, a dataset would be collected manually according to certain criteria (pitch, teams, weather conditions, etc), and would be handed over to a third-party company to do the annotation. But during the lifecycle of the product, a lot of annotated data is already being generated, and not using it would be wasteful.</p><p>Besides, immediately incorporating the acquired data would mean less potential for the models to become outdated (once we start operating in new pitches, with new teams, more diverse weather conditions, etc) and opportunities for collecting more data in a targeted manner (samples where the current models are not accurate enough).</p><p>Finally, if the data collection / preparation process is not performed frequently, it often becomes “sacred knowledge”, that is either lost, or known only to select few engineers, making it harder to check new hypothesis (sometimes to the point where such tasks are completely avoided).</p><p>Not only would “adopting MLOps” make the data collection process more transparent and systematic, it would also allow us to increase the dataset size very significantly (orders of magnitude) with regards to the number of samples and the number of matches, which is expected to noticeably improve the model’s metrics.</p><h3>Initial research</h3><p>In order to avoid reinventing the wheel, we used off-the-shelf open-source tools that help with dataset management and automation.</p><h3>Dataset management</h3><p>We work with (versioned) datasets where each version contains millions of files that come to hundreds of gigabytes, so speed and storage efficiency are crucial. To manage these we decided to use <a href="https://dvc.org/">DVC</a>, since it doesn’t get in your way and has a git-like interface that makes it easier to get a hang of (although initially it still might take some effort to get comfortable with).</p><p>We mostly care about the following points:</p><ul><li>Easily uploading / downloading the dataset to our cloud storage of choice using any machine (helps to scale training / hyperparameter search)</li><li>Avoiding using extra storage / transfer bandwidth if different datasets or dataset versions overlap in terms of samples</li><li>Making sure that the version of the data would be exactly equivalent between machines without any manual steps (less room for human error)</li></ul><p>Point one should probably be taken for granted for a dataset management system, so we’ll focus on point two here (and doing it properly involves the third point).</p><p>Assume you have two datasets (or versions of the same dataset) A and B, which contain samples {1, 2, 3, 4, 5} and {2, 3, 4, 5, 6}, respectively.</p><p>Naive solutions would store them separately, requiring storage for 10 samples, but with DVC you’ll store only six samples and some extra data to define which dataset has which samples (which would typically be negligible as long as you are working with relatively large binary samples).</p><p>If we already have dataset A locally and want to download dataset B — you’ll need to download only a single sample instead of five.</p><p>This example might look trivial, but having a system that can handle it efficiently makes a very significant impact on the storage and bandwidth requirements as well as speed of operations, <strong>which become critical as soon as you start regularly creating new versions of datasets in an automated manner</strong>, uploading them to a cloud and downloading to agent machines for training or other purposes.</p><p>Also, in our case it might be possible to have datasets for different tasks (object detection, player shirt number recognition, camera position estimation, etc) that share the images, but have separate labels without increasing cloud storage usage. Of course it is also possible to achieve manually, but this would require coordination between people that maintain different datasets, whereas in this case they might push/pull to storage their data independently, and it will be reused as much as possible under the hood.</p><p>Even with this you still have to take special care when collecting data to make sure that the cache would be reused as much as possible without sacrificing the model performance — more on this later.</p><h3>Automation and integration</h3><p>Since we use GitHub as a repository storage, it was a natural choice to use <a href="https://github.com/features/actions">GitHub Actions</a> to automate some jobs.</p><p>Many of the jobs would be relatively long-running and require a GPU, so we needed to use some custom agents instead of the ones provided by GitHub.</p><p>To do that, we used <a href="https://cml.dev/">CML</a>, which also allows to send reports as comments to commits and PRs.</p><p>Apart from the typical software development usages (run lint and tests for each commit / PR), we used several manually triggered jobs:</p><ul><li>Make a report about samples, which are available for inclusion into the dataset (a nice markdown table that allows us to compare the dataset to be exported with a previous one to determine if it is worth retraining the model)</li><li>Actual dataset export, with the possibility to select the branch of the repo with the code and configuration to use and also to override some of the export settings (size of the dataset, etc)</li></ul><p>It is possible to run the export automatically according to the schedule, but it didn’t make sense to perform it more often than once a month, so there was not much to gain in terms of saved time. The same goes for training the model with the updated dataset — it is easy to do in principle, but automating it would reduce the amount of control that we have over the process and wouldn’t free up much time.</p><p>A convenient aspect of the current integration is that once the dataset export is complete, the data is automatically uploaded to the cloud storage via DVC, and the identifiers for the uploaded data are posted as comments under the commit that was used to perform the export, along with the configuration file content that determines export settings. This ensures that it is easy to find a particular version of the dataset and it wouldn’t be lost, unlike in a scenario where datasets are managed manually.</p><p>This way the developers that don’t work with this system directly might use the exported datasets in their projects, without having to run any data collection / cleanup themselves (allowing us to have separate specialists that focus on data cleanup and on training the models).</p><h3>Pilot project</h3><p>Here, we’ll be using multiple object tracking task as an example. In this case, an image is an input to the model, and expected output is a set of bounding boxes, each accompanied with an object class (player, ball, etc) and an embedding vector, which will be used during the re-identification stage.</p><h3>Obtaining the labels</h3><p>During the lifecycle of our product predictions from the models are being reviewed by human experts, and the corrected results (bounding boxes, class and player identity labels) are saved in a database, providing a source of data that we can consider to be ground truth.</p><p>Here’s an example of the bounding boxes with corresponding player IDs overlaid on top of the image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KmaVgDCvTcXLMJi_sEPMPg.png" /></figure><p>In an ideal world we would’ve used it as is, but in our case we have to go through some cleaning first.</p><p>An example of a case that needs extra attention:</p><ul><li>When a human expert corrects missing boxes, the boxes are placed only in frames where the velocity vector of the player changes, and their positions in the remaining frames are expected to be interpolated</li><li>When a player crosses the sideline to leave the pitch — they are not included in the annotation until they have returned to the pitch</li><li>When the two conditions above are combined, “ghost” trajectory chunks will be generated (a slow moving box from the point of exit to the point of entry onto the pitch), and unless some data cleaning is performed — such artifacts will negatively impact the trained model</li></ul><p>Another potential problem is synchronisation between video frames and labels, which might be slightly inaccurate sometimes. It’s not a problem for the users of the product, but during the model training even a single-frame offset has a negative impact, so ideally it should be compensated.</p><p>We tackle both problems by comparing the labels with outputs from the best available model, and then estimate:</p><ul><li>Optimal offset for label and frame synchronisation</li><li>Alignment between corrected labels and predictions (loss, IoU or any other meaningful measure could be used)</li></ul><p>Then, using this information, we can filter the samples to include only ones with reasonable agreement between labels and model output.</p><h3>Sample selection</h3><p>After quick back-of-the-envelope calculations it became obvious that it wouldn’t be possible to include all the samples that we have in our dataset due to the projected size. Since we’re working with video-based data, consecutive samples are strongly correlated, which makes including all of them even less meaningful. Finally, due to the nature of the process that we use to obtain the ground-truth labels, some of these are less accurate than the others, making their inclusion undesirable.</p><p>Keeping this in mind, we have ended up with the following strategy:</p><ul><li>For a given frame step parameter and the range of relevant frames, prepare a list of frame indices for export candidates</li><li>Drop frame indices for samples where the number of players in the label doesn’t match expectations (mostly to exclude non-game situations)</li><li>Measure the agreement between labels for each of these with output of the current best model, drop indices for frames with extreme disagreement</li></ul><p>These points were mostly related to the selection of samples from a video, but selection can also be applied to the set of the videos as well. Different strategies might be employed, and while it is not clear which one is the best, we have decided to go for the data diversity maximisation within a fixed sample budget. It can be roughly expressed as: “when facing a choice to include either sample A or sample B into the dataset, include the one which is more ‘novel’ (has less similar samples in the dataset already), repeat N times”.</p><p>How can one determine if the videos are “similar” or not? In our case, each video is assigned a set of categorical properties (pitch, home team, away team, etc), and a combination of these properties defines a “group”. For each group we include up to a limited number of videos, one of which goes to the validation set, and the rest — to the training one. Such a procedure ensures that there’s no extreme imbalance between sizes of groups and avoids too much storage being used for well-represented groups.</p><h3>Caching</h3><p>Even with such measures, downloading (and pre-processing) samples from scratch each time the export is performed would take an unacceptable amount of time, forcing us to employ caching for each of the steps (and strategies for cache invalidation). Having a caching mechanism alone is not enough though, since one must also make sure to select and store samples in a cache-friendly way.</p><p>This means that, for instance, if at time t1 we select matches M1, at time t2 (when more data is available), M2 should be a superset of M1 (include all matches that we had previously + some new ones), the selection criteria from (pick N matches from G) shouldn’t change.</p><p>As an example, let’s compare two policies for choosing a subset of samples from a group — using the N newest ones or N oldest ones available. If we were to use the newest ones — such a subset might change after each re-export, making some samples in the cache unused and requiring the downloading of new samples. But if we use the oldest samples such issues would not arise, making caching more effective.</p><p>After implementing all of this, regular exporting would only download and pre-process the samples incrementally, avoiding most of the time expense. Besides, instead of needing sum(each dataset version size) we’ll need only max(dataset size) (assuming that datasets are not disjointed in samples).</p><h3>Downloading the samples</h3><p>The naive approach would be to download the video file and then extract the frames from it using OpenCV or another tool, but depending on the number of frames that would be extracted from the video this might be inefficient (assuming you need only one frame from a three hour video as an extreme example).</p><p>ffmpeg to the rescue! With it, we can extract a specific frame from a remote video without downloading the whole thing. Initially we had concerns about the accuracy of frame selection, since “fast seeking” with ffmpeg is possible only via specifying the time offset, and not the frame index. Of course, by knowing the frame rate of the video you should be able to infer the time offset for a particular frame, but by doing this you have to assume that the time interval between frames is very consistent throughout the whole video, and that the seeking functionality is precise enough. Fortunately, such an approach was accurate enough for our use case, so we stuck with this approach.</p><p>The only issue with that was working with m3u8 playlists instead of mp4 files — ffmpeg was not able to perform an accurate fast seek to the exact timestamp, which resulted in a lot of frames with a severe mismatch between image and labels. We’ve resolved it in a relatively straightforward manner, by first performing a fast seek to a timecode a few seconds before the frame of interest, and then doing an “accurate” or “slow” seek to the exact timecode of the frame we need — it worked well enough for our use case.</p><p>Finally, in order to speed up the overall process, frames are acquired using this process in parallel, using a pre-determined number of processes, which depends on network, CPU and input data.</p><h3>Benchmarking</h3><p>So far we’ve mostly been referring to a scenario where the acquired data is used for training the model. But obviously this is not the only potential application, and it could also be used for end-to-end benchmarking of the system.</p><p>In our case it meant working with the videos instead of images and measuring the metrics which are important for the product (and might be harder to measure when one or all of the models are trained in isolation). Using the sample groups that were established during the data collection, we could automatically generate (or update) a set of inputs and expected outputs for the benchmarks (quality and performance related).</p><p>One obvious issue with such a “dynamic” benchmark is comparing the results of models which were evaluated on different “versions” of the benchmark. We address it in following fashion:</p><ul><li>Once the sample (video) is included into the benchmark — it could not be excluded, only new samples could be added (unless we want to invalidate it completely)</li><li>Metrics are measured and stored on a per-sample basis (allowing to “update” previous results incrementally, rather than recalculating completely)</li><li>Once new samples are included — old models are simply evaluated on these new samples, and the aggregate benchmark results are updated</li></ul><p>Such an approach allows us to avoid expensive reruns and is relatively easy to accomplish.</p><h3>Results</h3><p>One might wonder if going through all these steps was worth it. In our case it was definitely the case:</p><ul><li>Using the data, which was collected using the steps described above, we have been able to achieve &gt; 40% error reduction in multiple object tracking task (different types of errors are weighted differently, which is a topic for another article🙂)</li><li>As a result of that, the amount of human expert work was decreased &gt; 25%, which reduces the net cost of providing the service significantly</li><li>Regularly rerunning the dataset collection pipeline doesn’t take more than few minutes of developers’ time, likewise with using a new version of the dataset to retrain the model (even though these processes might take significant time, developers can still focus on other tasks in the meantime)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sMKmf4IUwY42sN0oCEiZ7g.png" /></figure><h3>Next steps</h3><p>We are still in the process of “adopting MLOps” at Bepro, so there are several obvious next steps, some of which are:</p><ul><li>Expanding to other tasks</li><li>Evaluating different sample weighting schemes</li><li>Pseudo-labelling the samples for which we don’t have human expert annotations (a lot more samples with different conditions become available with such approach)</li></ul><p>It is also interesting to evaluate the long term return of continuous dataset collection and model retraining. So far we have been able to get improvements by incorporating more data over time, but these are expected to be diminishing, and over time most likely would be limited by the model capacity/architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rW3yKcBwarJpdHfFPQyiuA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3c38b36980" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bepro-team-blog/mlops-pipeline-a3c38b36980">How we are adopting MLOps at Bepro</a> was originally published in <a href="https://medium.com/bepro-team-blog">Bepro Team Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>