<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Meticulous Hyunni</title>
    <description>changhyun&apos;s study blog</description>
    <link>https://Changhyun-song.github.io/</link>
    <atom:link href="https://Changhyun-song.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Thu, 28 Nov 2024 18:21:46 +0900</pubDate>
    <lastBuildDate>Thu, 28 Nov 2024 18:21:46 +0900</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>[Paper Review] Improving Calibration for Long-Tailed Recognition (ICLR 2021) 논문 리뷰</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;✍🏻 이번 포스팅에서는 적은 이미지로 학습가능한 &lt;strong&gt;Improving Calibration for Long-Tailed Recognition&lt;/strong&gt; 논문 리뷰를 꼼꼼하게 !!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Paper : &lt;a href=&quot;https://arxiv.org/abs/2104.00466&quot;&gt;Improving Calibration for Long-Tailed Recognition&lt;/a&gt; (arxiv 2021 /Zhisheng Zhong, Jiequan Cui, Shu Liu, Jiaya Jia)&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;1-abstract&quot;&gt;1. Abstract&lt;/h2&gt;

&lt;p&gt;본 논문에서는 &lt;strong&gt;&lt;em&gt;Deep Neural Networks&lt;/em&gt;&lt;/strong&gt;가 &lt;strong&gt;&lt;em&gt;Training Datasets&lt;/em&gt;이 심한 &lt;em&gt;Class-Imbalance&lt;/em&gt;가 있을 경우 성능이 저하될 수 있다&lt;/strong&gt;고 말하고 있다.&lt;br /&gt;&lt;br /&gt; &lt;em&gt;Two-stage Method&lt;/em&gt;를 통해 &lt;em&gt;Representation Learning&lt;/em&gt;과 &lt;em&gt;Classifier learning&lt;/em&gt; 성능을 향상시키긴 했지만 여전히 &lt;strong&gt;&lt;em&gt;Miscalibration&lt;/em&gt;이 발생&lt;/strong&gt;한다.&lt;br /&gt;&lt;br /&gt; 이를 해결하기 위해 본 논문에서는 2가지 방법을 제안한다.
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;“Motivated by the fact that predicted probability distributions of classes are highly related to the numbers of class instances, we propose label-aware smoothing to deal with different degrees of over-confidence for classes and improve classifier learning.&lt;br /&gt;For dataset bias between these two stages due to different samplers, we further propose shifted batch normalization in the decoupling framework.”&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;2-introduction&quot;&gt;2. Introduction&lt;/h2&gt;
&lt;p&gt;많이 쓰이는 Open Dataset 같은 경우에는 일반적으로 각각의 Object, Class의 Instance 수와 관련해서 인위적으로 균형을 이루고 있다. &lt;br /&gt;&lt;br /&gt;하지만 실제 사용되는 일반적인 데이터셋은 각각의 Class의 Instance 수가 심각하게 불균형한 &lt;strong&gt;&lt;em&gt;Long-tailed Distribution&lt;/em&gt;&lt;/strong&gt;을 보여주고 있다. Long-tailed Distribution애 대해 CNN을 학습시킬 때 성능이 크게 떨어진다.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;여기서 &lt;strong&gt;&lt;em&gt;Long-tailed Distribution&lt;/em&gt;&lt;/strong&gt; 이란?
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-1.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;쉽게 말하면 &lt;strong&gt;클래스가 가지고 있는 데이터 양의 차이가 큰 것&lt;/strong&gt;을 말한다. &lt;br /&gt;&lt;br /&gt;예를 들면 병원에서 질병이 있는 사람과 질병이 없는 사람의 데이터를 모아야 한다고 했을 때 일반적으로 질병이 있는 사람의 데이터가 질병이 없는 사람의 데이터 수에 비해 현저하게 적다. &lt;br /&gt;&lt;br /&gt;물론 병원 데이터 뿐 아니라 현실 데이터에서는 대부분 클래스 불균형 문제를 가지고 있다. &lt;br /&gt;&lt;br /&gt;이러한 클래스 불균형으로 인해 특정 클래스의 Instance가 너무 높고 반대로 다른 클래스의 경우는 매우 낮기 때문에 마치 긴 꼬리 모양과 같이 생긴 것을 &lt;strong&gt;&lt;em&gt;Long-tailed Distribution&lt;/em&gt;&lt;/strong&gt;이라고 말한다.
&lt;br /&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;다시 논문으로 돌아오면 최근에는 &lt;em&gt;Two-Stage Approach&lt;/em&gt;를 통해서 성능이 &lt;em&gt;One-stage Method&lt;/em&gt;와 비교했을 때 상당히 개선되었다.&lt;br /&gt;&lt;br /&gt; &lt;em&gt;Two-Stage Approach&lt;/em&gt;에서&lt;br /&gt; &lt;strong&gt;&lt;em&gt;Deffered Re-sampling(DRS)&lt;/em&gt;&lt;/strong&gt;과 &lt;strong&gt;&lt;em&gt;Deffered Re-weighting(DRW)&lt;/em&gt;&lt;/strong&gt;방법이 있다.
&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;일반적인 방법으로 불균형되어 있는 Dataset을 CNN Model로 학습시킨다.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;DRS로 클래스 균형 리샘플링을 사용하여 데이터 세트에서 CNN을 조정한다.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;DRW로 클래스에 다른 weight를 할당함으로써 CNN을 조정한다.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;본 논문에서 참고한 2가지 논문과 링크는 아래에 첨부하겠습니다.
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;bbn: bilateral-branch network with cumulative learning for long-tailed visual recognition, CVPR 2020&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://arxiv.org/abs/1912.02413&quot; title=&quot;논문 링크&quot;&gt;Link&lt;/a&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Decoupling Representation and Classifier for Long-Tailed Recognition, ICLR 2020&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://arxiv.org/abs/1910.09217&quot; title=&quot;논문 링크&quot;&gt;Link&lt;/a&gt;
&lt;br /&gt;&lt;br /&gt;
첫 번째 논문에서는 &lt;strong&gt;&lt;em&gt;Bilateral-Branch Network(BBN-Model)&lt;/em&gt;&lt;/strong&gt;을 제안한다.&lt;br /&gt; 이 모델은 Representation learning과 classifier learning을 따로 수행하는 형태의 학습 방법을 의미한다. 
&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-2.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;
위 모델은 2가지의 branch로 이루어져 있다.&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;1-coventional-learning-branch&quot;&gt;1. Coventional learning branch&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Representation learning&lt;/li&gt;
  &lt;li&gt;원래 &lt;strong&gt;&lt;em&gt;Long-tail distribution pattern&lt;/em&gt;을 그대로 학습하는 용도로 사용&lt;/strong&gt;된다.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;em&gt;Typical uniform sampler&lt;/em&gt;&lt;/strong&gt; 사용&lt;br /&gt;&lt;br /&gt;
이 때 &lt;strong&gt;&lt;em&gt;Typical uniform sampler&lt;/em&gt;&lt;/strong&gt;는 클래스 불균형이 있는 Dataset을 그대로 sampling 하는 것을 의미한다. 따라서 이 때 학습할 때 data가 많은 class, 즉 Head 쪽 Data가 학습이 더 많이 진행되게 되고 결과적으로 feature의 학습인 representation learning이 더 잘 되게 만든다.
&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-re-balancing-branch&quot;&gt;2. Re-balancing branch&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Classifier learning&lt;/li&gt;
  &lt;li&gt;Coventional learning branch와 달리 Tail 쪽 Data를 조금 더 많이 sampling한다.&lt;/li&gt;
  &lt;li&gt;Tail class에 대한 classification accuracy를 상승시키기 위한 것이다.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;
이 논문으로부터 얻을 수 있는 정보는 &lt;em&gt;Original Data&lt;/em&gt;로 부터 &lt;em&gt;Feature learning&lt;/em&gt;의 장점을 얻기 위해&lt;br /&gt;&lt;br /&gt; &lt;strong&gt;Conventional branch를 통해서 Original distribution에 대해 학습&lt;/strong&gt;을 진행한다.&lt;br /&gt;&lt;br /&gt;
이전 실험에서 &lt;em&gt;Representation learning&lt;/em&gt;을 한 이후에 &lt;em&gt;Classifier learning&lt;/em&gt;을 &lt;em&gt;RW, RS&lt;/em&gt; 형태로 진행한 것처럼 &lt;em&gt;Alpha&lt;/em&gt; 값을 조정하여 처음에는 &lt;em&gt;uniform sampler&lt;/em&gt;로부터 학습을 시작하고,&lt;br /&gt; &lt;strong&gt;이것으로부터 feature가 잘 학습된 Backbone 네트워크로부터 RS/RW 효과를 내는 Re-balancing branch로 부터 학습을 늘린다.&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;
최종적으로&lt;br /&gt; &lt;strong&gt;&lt;em&gt;Conventional learning branch&lt;/em&gt;&lt;/strong&gt;는 &lt;strong&gt;&lt;em&gt;Majority Class&lt;/em&gt;&lt;/strong&gt;에 preference를 더 가지도록, &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Re-balancing branch&lt;/em&gt;&lt;/strong&gt;는 &lt;strong&gt;&lt;em&gt;Minority Class&lt;/em&gt;&lt;/strong&gt;에 preference를 더 가지도록 학습이 된다.&lt;/p&gt;

&lt;p&gt;따라서 Mix-up을 했을 때, 즉 두 가지 결과를 합쳤을 때 이런 Weight가 Balance한 형태로 가장 잘 맞춰지게 된다.&lt;br /&gt;&lt;br /&gt;
두 번째 논문에서는 &lt;strong&gt;&lt;em&gt;Two-stage decoupling Model&lt;/em&gt;&lt;/strong&gt;을 제안한다.&lt;br /&gt; 이 모델은 &lt;strong&gt;&lt;em&gt;classifier re-training(cRT)&lt;/em&gt;&lt;/strong&gt;와 &lt;strong&gt;&lt;em&gt;Learnable weight scaling(LWS)&lt;/em&gt;&lt;/strong&gt;가 있다.&lt;/p&gt;

&lt;h4 id=&quot;1-classifier-re-trainingcrt&quot;&gt;1. classifier re-training(cRT)&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Representation learning 부분을 고정&lt;/strong&gt;시키고 &lt;em&gt;Classifier&lt;/em&gt;만 &lt;em&gt;Class Balanced&lt;/em&gt; 형식으로 다시 학습시키는 방법을 이야기 한다.&lt;/p&gt;

&lt;h4 id=&quot;2-learnable-weight-scalinglws&quot;&gt;2. Learnable weight scaling(LWS)&lt;/h4&gt;
&lt;p&gt;&lt;em&gt;Scaling&lt;/em&gt; 하는 정도는 학습을 통해서 얻는 방법을 의미한다.
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Confidence Calibration&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;em&gt;Calibration&lt;/em&gt;이란 모형의 출력값이 실제 &lt;em&gt;Calibrated Confidence&lt;/em&gt;를 반영하도록 만드는 것을 말한다. &lt;br /&gt;&lt;br /&gt;
예를 들어 X의 Y1에 대한 모형의 출력이 0.8이 나왔을 때, 80% 확률로 Y1일 것이라는 의미를 갖도록 만드는 것이다. &lt;br /&gt;일반적으로 현대 딥러닝같은 경우에는 &lt;strong&gt;&lt;em&gt;Overconfident&lt;/em&gt;&lt;/strong&gt; 성격을 띄고 있다. &lt;br /&gt;&lt;br /&gt;예시로 아래 그림을 보면 1998년에 제시된 &lt;em&gt;LeNet&lt;/em&gt;의 경우 모형의 출력이 0~1 사이에 균일하게 분포되어 있지만, &lt;em&gt;ResNet&lt;/em&gt;의 경우 1근처에 집중되어 있는 것을 확인할 수 있다. &lt;br /&gt;&lt;br /&gt;그 결과로 아래 그림을 보게 되면 &lt;em&gt;ResNet&lt;/em&gt;의 경우 &lt;em&gt;Confidence&lt;/em&gt;와 &lt;em&gt;Accuracy&lt;/em&gt;가 많이 어긋나는 것을 확인할 수 있다. &lt;br /&gt;
&lt;strong&gt;모형의 출력이 실제 &lt;em&gt;Calibrated Confidence&lt;/em&gt;를 반영한다면 &lt;em&gt;Confidence&lt;/em&gt;와 &lt;em&gt;Accuracy&lt;/em&gt;는 일치해야 한다.&lt;/strong&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-3.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;모형의 예측값이 실제 확률을 반영한다는 의미를 가진 &lt;em&gt;Calibration&lt;/em&gt;이 중요한 이유&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;
실제 딥러닝이 응용될 때, 의사결정 프로세스중 하나의 구성요소가 될 경우가 많다. &lt;br /&gt;&lt;br /&gt;의학적 진단을 예로 들자면, 딥러닝을 전적으로 신뢰해서 모든 판단을 딥러닝에게 맡기는 의사결정이 이루어지는 경우는 적고, 딥러닝 모델의 &lt;em&gt;Confidence&lt;/em&gt;가 낮은 경우에만 사람이 보는 방식으로 사람이 할 일의 일부를 딥러닝이 하게 되는 구조가 대부분입니다. &lt;br /&gt;&lt;br /&gt;이 경우 &lt;em&gt;Confidence&lt;/em&gt;가 낮은 것만 사람이 재확인하는 방식이 가능한데 이러한 의사결정이 가능하기 위해서는 모형의 &lt;em&gt;Confidence&lt;/em&gt;를 보는 것이 필요하고 &lt;strong&gt;이 &lt;em&gt;Confidence&lt;/em&gt;가 &lt;em&gt;Calibrated Confidence&lt;/em&gt;이여야 신뢰할 수 있는 값&lt;/strong&gt;이라고 할 수 있다.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;네트워크의 &lt;em&gt;Calibration&lt;/em&gt;을 측정하는 방법으로 &lt;strong&gt;&lt;em&gt;Expected Calibration Error(ECE)&lt;/em&gt;&lt;/strong&gt;를 사용한다. &lt;br /&gt;&lt;br /&gt; &lt;strong&gt;&lt;em&gt;ECE&lt;/em&gt;&lt;/strong&gt;는 &lt;strong&gt;&lt;em&gt;Confidence&lt;/em&gt;와 실제 &lt;em&gt;Accuracy&lt;/em&gt;의 &lt;em&gt;Distribution&lt;/em&gt;의 차이를 측정하는 방법&lt;/strong&gt;이다. 예측값을 균등하게 M묶음으로 나눈 뒤에 &lt;em&gt;Accuracy&lt;/em&gt;와 &lt;em&gt;Confidence&lt;/em&gt;차이의 평균을 계산하는 방법이다. 여기서 n은 샘플의 개수다.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-4.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;아래 그림을 통해 클래스의 불균형 구성 비율 때문에 &lt;em&gt;Long-tailed Datasets&lt;/em&gt;에서 훈련된 네트워크가 &lt;strong&gt;&lt;em&gt;Miscalibrated&lt;/em&gt;&lt;/strong&gt;하고 &lt;strong&gt;&lt;em&gt;Over-Confident&lt;/em&gt;&lt;/strong&gt;하다는 것을 보여준다. &lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-5.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;원본 CIFAR-100 Dataset + CE(Cross Entropy)&lt;/li&gt;
  &lt;li&gt;Long-tailed Datasets&lt;/li&gt;
  &lt;li&gt;Long-tailed Datasets + cRT&lt;/li&gt;
  &lt;li&gt;Long-tailed Datasets + LWS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;위 결과값을 통해 &lt;em&gt;Long-tailed Datasets&lt;/em&gt;를 훈련한 &lt;em&gt;Network&lt;/em&gt;가 일반적으로 ECE가 높다는 것을 확인할 수 있다. 또한 &lt;em&gt;cRT, LWS&lt;/em&gt; 에서도 마찬가지로 &lt;em&gt;Over-Confidence&lt;/em&gt;를 확인할 수 있다. &lt;br /&gt;위 현상은 다른 &lt;em&gt;Long-tailed Datasets&lt;/em&gt;에서도 존재한다.
&lt;br /&gt;&lt;br /&gt;
또 다른 문제는  &lt;em&gt;Two-stage Decoupling&lt;/em&gt;이 &lt;em&gt;Dataset bias&lt;/em&gt; 또는 &lt;em&gt;Domain shift&lt;/em&gt;를 무시한다는 것이다.&lt;br /&gt;&lt;br /&gt;
이 문제는 1단계에서 &lt;em&gt;Instanced balanced Dataset&lt;/em&gt;에 대해 먼저 훈련하고 2단계에서 모델이 &lt;em&gt;Class-balanced dataset&lt;/em&gt;에서 훈련했을 때 &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Distribution of the dataset by different sampling ways&lt;/em&gt;가 일치하지 않는다는 것이다.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;
따라서 &lt;em&gt;Dataset bias&lt;/em&gt; 문제를 해결하기 위해서 Batch normalization에 초점을 둔다. &lt;br /&gt;&lt;br /&gt;위 문제들을 모두 해결하기 위해서 논문에서는 &lt;strong&gt;&lt;em&gt;Mixup Shifted Label-Aware Smoothing model(MiSLAS)&lt;/em&gt;&lt;/strong&gt;를 제안한다.&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;Long-tailed Dataset&lt;/em&gt;에 대해 훈련된 &lt;em&gt;Model&lt;/em&gt;이 &lt;em&gt;Balanced Dataset&lt;/em&gt;에 대해 훈련된 &lt;em&gt;Model&lt;/em&gt; 보다 훨씬 &lt;strong&gt;&lt;em&gt;Miscalibrated and Over-confident&lt;/em&gt;&lt;/strong&gt; 
&lt;br /&gt;(이는 2단계 모델 역시 같은 문제점 발생)&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;mixup&lt;/em&gt;은 &lt;em&gt;representation learning&lt;/em&gt;에는 긍정적인 영향을 주고 &lt;em&gt;Over-confidence&lt;/em&gt;를 줄일 수 있지만 &lt;em&gt;Classifier learning&lt;/em&gt;에서는 부정적 영향을 줄 수 있다.&lt;br /&gt;&lt;strong&gt;따라서 &lt;em&gt;Classifier learning&lt;/em&gt;과 &lt;em&gt;Calibration&lt;/em&gt;을 향상시키기 위해 &lt;em&gt;Label-aware smoothing&lt;/em&gt;을 제안한다.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Label-aware smoothing&lt;/em&gt;&lt;/strong&gt;이란? &lt;br /&gt;&lt;strong&gt;&lt;em&gt;–&amp;gt;handle different degrees of over- confidence for classes&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Dataset bias or Domain shift&lt;/em&gt;를 &lt;em&gt;Decoupling Framework&lt;/em&gt;에서 해결하기 위해 성능을 개선할 수 있는 &lt;strong&gt;&lt;em&gt;Shift learning on the batch normalization layer&lt;/em&gt;&lt;/strong&gt;를 제안한다.&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Long-tailed Dataset&lt;/em&gt; 여러 개에서 MiSLAS를 검증하고 실험 결과를 보여준다.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;3-related-work&quot;&gt;3. Related Work&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Re-sampling and Re-weighting&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;em&gt;Re-samling&lt;/em&gt;
&lt;br /&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;&lt;em&gt;Over-sampling the Tail-class images&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;em&gt;Over-sampling&lt;/em&gt;은 대규모 데이터셋에 정기적으로 유용&lt;/li&gt;
          &lt;li&gt;소규모 데이터셋에서 &lt;strong&gt;&lt;em&gt;Tail Class&lt;/em&gt;에 대한 &lt;em&gt;Over-fitting&lt;/em&gt; 발생&lt;/strong&gt;&lt;br /&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;&lt;em&gt;Under-sampling the Head-class images&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
        &lt;ul&gt;
          &lt;li&gt;데이터의 많은 부분을 폐기하므로 &lt;strong&gt;&lt;em&gt;Deep model&lt;/em&gt;의 일반화 능력이 저하&lt;/strong&gt;&lt;br /&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Re-weighting&lt;/em&gt;
&lt;br /&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Class &amp;amp; Instance&lt;/em&gt;에 서로 다른 &lt;em&gt;weight&lt;/em&gt;를 할당&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Vanilla Re-weighting Method&lt;/em&gt;
        &lt;ul&gt;
          &lt;li&gt;클래스 샘플 수에 &lt;strong&gt;역비례&lt;/strong&gt;하여 &lt;strong&gt;&lt;em&gt;Class weight&lt;/em&gt;를 제공&lt;/strong&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;대규모 데이터의 경우 학습시키는 동안 &lt;em&gt;Deep Model&lt;/em&gt;을 최적화하기 어려움
        &lt;ul&gt;
          &lt;li&gt;유효 숫자를 사용하여 &lt;em&gt;Class weight&lt;/em&gt;를 사용하여 위 문제 해결&lt;/li&gt;
          &lt;li&gt;각 인스턴스의 &lt;em&gt;weight&lt;/em&gt;를 적응적으로 다시 매김 &lt;br /&gt;(ex.&lt;strong&gt;&lt;em&gt;Focal loss&lt;/em&gt;&lt;/strong&gt; -&amp;gt; 잘 분류된 예제에는 작은 &lt;em&gt;weight&lt;/em&gt;, 분류하기 어려운 일부 예제에는 큰 &lt;em&gt;weight&lt;/em&gt;를 부여하여 학습을 어려운 예제에 집중시킴)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Confidence calibration and regularization&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;Calibrated confidence&lt;/em&gt;는 &lt;em&gt;Classification model&lt;/em&gt;에서 중요&lt;br /&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Model capacity, Normalization, Regularization -&amp;gt; Network Calibration&lt;/em&gt;에 큰 영향을 미치는 것을 확인&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Mixup&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Interpolation of input and labels&lt;/em&gt;으로 훈련하는 &lt;em&gt;Regularization&lt;/em&gt; 기법
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;manifold mixup, Cut- Mix, Remix&lt;/em&gt;&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Mixup&lt;/em&gt;으로 학습된 &lt;em&gt;CNN&lt;/em&gt; -&amp;gt; &lt;strong&gt;&lt;em&gt;Better calibrated&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Label smoothing&lt;/em&gt;&lt;br /&gt;&lt;em&gt;another Regularization&lt;/em&gt; 기법 &lt;br /&gt;–&amp;gt;&lt;strong&gt;Over-confident&lt;/strong&gt;를 줄이도록 &lt;em&gt;Model&lt;/em&gt;을 만든다.
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;compute loss upon a soft version of labels&lt;/em&gt;&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;relieve Over-fitting and increase Calibration and Reliability&lt;/em&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Mixup&lt;/em&gt;&lt;/strong&gt;은 학습을 진행할 때 랜덤하게 두 개의 샘플 (x(i),y(i)), (x(j),y(j))를 뽑아서 (x_dot,y_dot)을 만들어 학습에 사용하는 것을 말한다.&lt;br /&gt;
아래 그림은 &lt;strong&gt;&lt;em&gt;Mixup&lt;/em&gt;&lt;/strong&gt;에 대한 예시를 보여준다. &lt;em&gt;lambda&lt;/em&gt;는 보통 0.5가 아닌 한 쪽 데이터에 치우치도록 0.1 혹은 0.2정도를 준다.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-8.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Label smoothing&lt;/em&gt;&lt;/strong&gt;은 일반화 성능을 높이기 위해 사용하는 기법이다.&lt;br /&gt; &lt;em&gt;one-hot encoding&lt;/em&gt;처럼 정답 레이블에 1 아닌 레이블에 0을 부여하는 것이 아니라 &lt;br /&gt;정답 레이블이 아닌 레이블에도 약간의 레이블 값을 넣어주는 것을 의미한다.&lt;br /&gt;
아래 그림은 &lt;em&gt;Label smoothing&lt;/em&gt;에 대한 예시이다.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-9.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Two-stage methods&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;&lt;em&gt;Deffered Re-weighting(DRW) &amp;amp; Deffered Re-sampling(DRS)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;em&gt;better than conventional one-stage methods&lt;/em&gt;
    &lt;ul&gt;
      &lt;li&gt;더 나은 Feature에서 시작해서 &lt;strong&gt;&lt;em&gt;adjust the decision boundary and locally tunes features&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;em&gt;Decomposing representation and classifier learning&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;먼저 &lt;em&gt;Instance-balanced sampling&lt;/em&gt;으로 &lt;em&gt;Deep Model&lt;/em&gt;을 학습&lt;/strong&gt;
        &lt;ul&gt;
          &lt;li&gt;그 후 &lt;em&gt;Parameters of Representation learning&lt;/em&gt;이 고정된 &lt;em&gt;Class-balanced sampling&lt;/em&gt;으로 &lt;em&gt;classifier&lt;/em&gt;를 미세 조정&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;&lt;em&gt;The cumulative learning strategy&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;em&gt;bridge the representation learning and classifier re-balancing&lt;/em&gt;&lt;/li&gt;
          &lt;li&gt;&lt;em&gt;requires dual samplers of instance-balanced and reversed instance- balanced sampler&lt;/em&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;31-study-of-mixup-strategy&quot;&gt;3.1 Study of mixup Strategy&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Instance-balanced sampling &amp;amp; mixup&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;em&gt;Instance-balanced sampling : &lt;strong&gt;The most general representation among all for long-tailed recognition&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;mixup : &lt;strong&gt;The Network trained with mixup are better calibrated&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;&lt;em&gt;Mixup in the Two-stage Decoupling framework&lt;/em&gt;&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Higher representation generalization&lt;/em&gt;&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;reduce Over-confidence&lt;/em&gt;
&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Stage 1&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
180epochs 동안 &lt;em&gt;ImageNet-LT&lt;/em&gt;에서 &lt;em&gt;Original Cross-entropy Model, Two stage Models of cRT and LWS&lt;/em&gt; 학습시킨다 &lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Stage 2&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
각각 10epochs에 대해 미세 조정한다.
&lt;br /&gt;&lt;br /&gt;
두 단계에 대한 &lt;em&gt;Training setup(with/without mixup alpha = 0.2)&lt;/em&gt;을 변경한다. &lt;br /&gt;&lt;br /&gt;&lt;em&gt;체크표시는 mixup이 적용했을 때 x표시는 mixup을 적용하지 않을 때이다.&lt;/em&gt;&lt;br /&gt;(Top-1 Accuracy / ECE에 대한 표)&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-6.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;Mixup&lt;/em&gt;을 적용했을 때&lt;br /&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Improvement of Cross Entropy&lt;/em&gt;는 &lt;strong&gt;&lt;em&gt;can be ignored&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Stage 1&lt;/em&gt;에서 &lt;em&gt;cRT, LWS&lt;/em&gt; 모두 &lt;strong&gt;성능이 크게 향상&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Stage 2&lt;/em&gt;에서 추가로 &lt;em&gt;mixup&lt;/em&gt;을 진행시 &lt;strong&gt;개선 효과가 없거나 오히려 성능을 손상시킴&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;위 결과에 대한 이유를 설명하는 mixup의 역할&lt;/strong&gt; 
&lt;br /&gt;1. &lt;em&gt;encourages representation learning&lt;/em&gt;
&lt;br /&gt;2. &lt;em&gt;but, adverse or negligible effect on classifier learning&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;정리&lt;/strong&gt;&lt;br /&gt;
즉, 1단계에서 &lt;em&gt;mixup&lt;/em&gt;은 representation learning에는 좋은 효과를 보여주지만 &lt;br /&gt;&lt;strong&gt;2단계에서는 &lt;em&gt;classifier learning&lt;/em&gt;에서는 효과를 보여주지 못하거나 오히려 악영향을 미친다.&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-7.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;위 그림은 &lt;strong&gt;&lt;em&gt;Final classifier weight norms&lt;/em&gt;&lt;/strong&gt;을 확인한 것이다. 위 그림을 봤을 때 &lt;em&gt;mixup&lt;/em&gt;이 &lt;em&gt;tail classes&lt;/em&gt;에 더 우호적일 수 있다는 것을 보여준다.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;그래서 2단계에서 &lt;em&gt;mixup&lt;/em&gt;을 추가했을 때 생기는 불안정한 결과를 개선하기 위한 방법으로 다음과 같은 방법을 추가로 제안한다.&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;-&amp;gt; Label-aware smoothing&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;32-label-aware-smoothing&quot;&gt;3.2. Label-aware smoothing&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Cross-entropy&lt;/em&gt;의 최적의 솔루션과 비교하여,&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Label-aware smoothing&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;&lt;em&gt;encourage a finite output, more general and remedying overfit&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br /&gt;&lt;br /&gt;
또한 인스턴스 수가 더 많은 클래스인 Head class가 
&lt;br /&gt;더 다양한 예를 많이 포함하고 있기 때문에 예측 확률이 &lt;em&gt;Tail class&lt;/em&gt;보다 더 좋다.&lt;br /&gt;
따라서 더 큰 &lt;strong&gt;&lt;em&gt;Label smoothing factor&lt;/em&gt;&lt;/strong&gt;를 부여해야 한다고 논문에서는 말하고 있다.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;그리고 &lt;em&gt;Label-aware smoothing&lt;/em&gt;은 &lt;em&gt;Cross-entropy&lt;/em&gt;보다 더 복잡하기 때문에
&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Generalized classifier learning framework&lt;/em&gt;&lt;/strong&gt;에 적용해야 한다고 말하고 있고&lt;br /&gt;
예시로는 위에서 배운 &lt;strong&gt;&lt;em&gt;cRT&lt;/em&gt;&lt;/strong&gt; 혹은 &lt;strong&gt;&lt;em&gt;LWS&lt;/em&gt;&lt;/strong&gt;를 말한다.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;cRT&lt;/em&gt;와 &lt;em&gt;LWS&lt;/em&gt;중에서 대규모 데이터셋에서 &lt;em&gt;LWS&lt;/em&gt;가 더 좋은 결과를 주기 때문에&lt;br /&gt;
실험에서는 &lt;strong&gt;&lt;em&gt;LWS + Label-aware smoothing&lt;/em&gt;&lt;/strong&gt;으로 결과를 확인한다. &lt;br /&gt;
결과는 아래 그림과 같다.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-10.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;왼쪽부터 &lt;em&gt;Head, Medium,Tail&lt;/em&gt; 순으로 결과를 보여준 것이다.&lt;br /&gt;
(연한 파랑 : &lt;em&gt;LWS + Cross-Entropy&lt;/em&gt; , 짙은 파랑 : &lt;em&gt;LWS + Label-Aware Smoothing&lt;/em&gt;)
&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;LWS + Cross-Entropy&lt;/em&gt;&lt;/strong&gt;의 경우엔 &lt;br /&gt;&lt;em&gt;Head&lt;/em&gt;와 &lt;em&gt;Medium&lt;/em&gt;에서 실제로 1.0에 가까울 정도로 높은 &lt;em&gt;Over-confident&lt;/em&gt;를 보이는 반면에,&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;LWS + Label-Aware Smoothing&lt;/em&gt;&lt;/strong&gt;의 경우엔 &lt;br /&gt; &lt;em&gt;Over-confident&lt;/em&gt;가 많이 감소한 것을 확인할 수 있다.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h3 id=&quot;33-shift-learning-on-batch-normalization&quot;&gt;3.3. Shift Learning on Batch Normalization&lt;/h3&gt;

&lt;p&gt;인스턴스 균형 샘플링으로 1단계에서 학습한 후 클래스 균형 샘플링으로 2단계에서 학습한다.&lt;br /&gt;&lt;br /&gt;
위 &lt;em&gt;Two-stage training framework&lt;/em&gt;는 &lt;strong&gt;&lt;em&gt;Transfer learning&lt;/em&gt;의 변형&lt;/strong&gt;으로 볼 수 있는데&lt;br /&gt;&lt;br /&gt;
Transfer learning 관점에서 Two-stage training framework를 보면&lt;br /&gt;&lt;br /&gt; backbone부분을 고정하고 Classifier를 튜닝하는 것은 unreasonable 하다. &lt;br /&gt;&lt;br /&gt;
다른 샘플링 방법이기 때문에 &lt;em&gt;Head, Medium, Tail&lt;/em&gt; 구성 비율이 다르고, 따라서 &lt;em&gt;Bias&lt;/em&gt;가 존재한다.&lt;br /&gt;&lt;br /&gt;
2가지 방법을 참고해서 사용&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;&lt;em&gt;AdaBN &amp;amp; TransNorm&lt;/em&gt;&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;update the running mean μ and variance σ&lt;/li&gt;
      &lt;li&gt;fix the learnable linear transformation parameters α and β for better normalization in Stage-2&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;4-experiments&quot;&gt;4. Experiments&lt;/h2&gt;

&lt;h3 id=&quot;411-datasets-and-setup&quot;&gt;4.1.1 Datasets and Setup&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;1. CIFAR-10 and CIFAR-100&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
50000장 Training &amp;amp; 10000장 Validation + 10개 카테고리 혹은 100개 카테고리&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Long-tailed Dataset 사용&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;2. ImageNet-LT and Places-LT&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;ImageNet-LT&lt;br /&gt;
115800 이미지 + 100 카테고리 (class cardinality:5~1280)&lt;/li&gt;
  &lt;li&gt;Places-LT&lt;br /&gt;
184500 이미지 + 365 카테고리 (class cardinality:5~4980)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;3. iNaturalist 2018&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
437500 이미지 + 8142 카테고리&lt;/p&gt;

&lt;h3 id=&quot;412-implementation-details&quot;&gt;4.1.2 Implementation Details&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;SGD optimizer with momentum = 0.9 to optimize network&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;MiSLAS model with ResNet-32 + 160~180 epochs에서 0.1로 learning rate 감소&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;Use cosine learning rate -&amp;gt; MiSLAS model + ResNet- 10, 50, 101, 152&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;42-ablation-study&quot;&gt;4.2 Ablation Study&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Calibration performance&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-11.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;CIFAR-100-LT with IF 100 데이터셋으로 했을 때 &lt;br /&gt;Calibration performance에 대한 결과이다.&lt;br /&gt;
&lt;strong&gt;본 논문에서 제시하는 MiSLAS 모델일 때가 가장 Confidence gap이 적은 것을 보여준다.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Comparing re-weighting with label-aware smoothing&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-12.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;class balanced cross-entropy와 Label-aware smoothing을 비교했을 때 결과이다.&lt;br /&gt;
위 결과에서 알 수 있듯이 Label-aware smoothing을 했을 때 &lt;br /&gt;&lt;strong&gt;&lt;em&gt;Over-confidence&lt;/em&gt;도 크게 감소&lt;/strong&gt;하고 &lt;strong&gt;&lt;em&gt;Accuracy&lt;/em&gt;도 상승&lt;/strong&gt;하는 것을 확인할 수 있다.&lt;/p&gt;

&lt;h3 id=&quot;421-result&quot;&gt;4.2.1 Result&lt;/h3&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-13.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;위 결과 표를 통해 알 수 있는 점&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;1단계에서 mixup을 했을 때 Accuracy증가 + ECE 감소&lt;/li&gt;
  &lt;li&gt;Shift learning on BN + Label-aware smoothing까지 했을 때 Accuracy 약간 증가 + ECE 크게 감소&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Comparison with State-of-the-arts&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/paper_review/paper_review1/paper_review1-14.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;
전체적으로 본 논문 이전에 사용되었던 방법들이랑 비교했을 때 &lt;br /&gt;&lt;strong&gt;&lt;em&gt;MiSLAS가 압도적으로 높은 Accuracy + 좋은 Calibration임을 보여준다.&lt;/em&gt;&lt;/strong&gt;
&lt;br /&gt;
대규모 데이터 셋인 a,b,c에서도 MiSLAS가 높은 성능을 가지고 있는 것을 확인할 수 있다.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;5-conclusion&quot;&gt;5 Conclusion&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;&lt;em&gt;Long-tailed Dataset을 학습한 모델은&lt;/em&gt;&lt;/strong&gt; &lt;br /&gt;balanced dataset을 학습한 모델보다 &lt;strong&gt;&lt;em&gt;miscalibrated and overconfident&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;첫 번째 솔루션 - &lt;strong&gt;&lt;em&gt;Mixup&lt;/em&gt;&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;1단계에서 mixup 사용 -&amp;gt; &lt;strong&gt;&lt;em&gt;representation learning에서 좋은 효과&lt;/em&gt;&lt;/strong&gt;(classifier learning에서는 오히려 역효과)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;두 번째 솔루션 - &lt;strong&gt;&lt;em&gt;Label-aware smoothing&lt;/em&gt;&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;LWS를 사용하여 Over-confidence를 크게 감소시킨다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;세 번째 솔루션 - &lt;strong&gt;&lt;em&gt;Shift learning on the batch normaization&lt;/em&gt;&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Two-stage method framework에서 &lt;strong&gt;&lt;em&gt;Dataset bias를 줄이기 위해서&lt;/em&gt;&lt;/strong&gt; 사용 -&amp;gt; 성능 향상&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;논문에서 제시하는 &lt;strong&gt;&lt;em&gt;MiSLAS 모델이 가장 좋은 Accuracy + Calibration&lt;/em&gt;&lt;/strong&gt; 을 보여줌
    &lt;ul&gt;
      &lt;li&gt;대규모 데이터 셋에서도 마찬가지 좋은 성능을 보여줌&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Mon, 26 Apr 2021 00:00:00 +0900</pubDate>
        <link>https://Changhyun-song.github.io/paper_review/PaperReview-1/</link>
        <guid isPermaLink="true">https://Changhyun-song.github.io/paper_review/PaperReview-1/</guid>
        
        <category>paper_review</category>
        
        <category>calibration</category>
        
        <category>vision</category>
        
        <category>deeplearning</category>
        
        
        <category>Paper_Review</category>
        
      </item>
    
      <item>
        <title>[Medical_AI] Finding and Measuring Lungs in CT Data (CT 데이터에서 폐 부분만 뽑아내기)</title>
        <description>&lt;h2 id=&quot;1-데이터-전처리&quot;&gt;1. 데이터 전처리&lt;/h2&gt;

&lt;p&gt;이번에는 CT Data에서 필요한 이미지인 폐 영역만 골라내는 segmentation을 해보도록 하겠습니다.
먼저 데이터 셋은 kaggle에서 가져오시면 됩니다.
&lt;a href=&quot;https://www.kaggle.com/kmader/finding-lungs-in-ct-data?select=2d_masks.zip&quot; title=&quot;데이터 셋 받는 주소&quot;&gt;Dataset&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;여기서 2d_images.zip 파일과 2d_masks.zip 파일을 받아오시면 됩니다!
다운로드 받은 파일은 다음과 같이 원래 CT 이미지들이 모여있는 image 폴더와 폐 부분만 표시되어 있는 mask된 사진만 모여있는 폴더입니다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-1.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2d_images Dataset&lt;/strong&gt;&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-2.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2d_masks Dataset&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;보시면 이미지파일이 tif 형식으로 되어 있습니다. Data 분야를 공부하면 할수록 느끼는 것이지만 처음 Data를 전처리하는 과정이 전체 과정의 절반이상을 차지한다고 말하는 것처럼 전처리 과정은 정확한 결과 값을 알기위해선 매우중요합니다!
따라서 우리는 이 tif 이미지들을 먼저 학습하기 쉬운 .npy 형식의 파일로 만들것입니다.&lt;/p&gt;

&lt;h3 id=&quot;1-1필요한-패키지와-함수-변수-import-하기&quot;&gt;1-1.필요한 패키지와 함수 변수 import 하기&lt;/h3&gt;
&lt;p&gt;Jupyter notebook을 키기 전에 필요한 패기지들을 다운로드 받아줍니다. 그 후 아래코드를 넣어주시면 됩니다.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from skimage.io import imread
from skimage.transform import pyramid_reduce, resize

import os, glob
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;1-2list-형식으로-img_list와-mask_list-생성&quot;&gt;1-2.list 형식으로 img_list와 mask_list 생성&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;glob&lt;/strong&gt;
glob.glob 를 사용하여 우선 폴더에 있는 모든 파일명을 /*를 사용하여 모두 리스트 형식으로 불러옵니다.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;img_list = sorted(glob.glob(&apos;2d_images/*.tif&apos;))
mask_list = sorted(glob.glob(&apos;2d_masks/*.tif&apos;))

print(len(img_list), len(mask_list))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-3.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;이렇게 img_list와 mask_list에 list 형식으로 폴더에 있는 모든 파일명들을 불러온 뒤 저장합니다.&lt;/p&gt;

&lt;h3 id=&quot;1-3-array-형태로-만들고-array-형태의-이미지-확인하기&quot;&gt;1-3. Array 형태로 만들고 array 형태의 이미지 확인하기&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;IMG_SIZE = 256

x_data, y_data = np.empty((2, len(img_list), IMG_SIZE, IMG_SIZE, 1), dtype=np.float32)

for i, img_path in enumerate(img_list):
    img = imread(img_path)
    img = resize(img, output_shape=(IMG_SIZE, IMG_SIZE, 1), preserve_range=True)
    x_data[i] = img
    
for i, img_path in enumerate(mask_list):
    img = imread(img_path)
    img = resize(img, output_shape=(IMG_SIZE, IMG_SIZE, 1), preserve_range=True)
    y_data[i] = img
    
y_data /= 255.

fig, ax = plt.subplots(1, 2)
ax[0].imshow(x_data[12].squeeze(), cmap=&apos;gray&apos;)
ax[1].imshow(y_data[12].squeeze(), cmap=&apos;gray&apos;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;우선 imread 함수를 통해서 img_list에 있는 파일을 하나씩 불러오고 Array형태로 불러오고 img에 하나씩 저장합니다. 그 후 resize를 통해 (256,256,1) 형태로 만들어 줍니다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-4.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;x_data와 y_data를 중간에 확인해보면 총 267개의 이미지 형태인 (256,256,1)이 되는 것을 확인할 수 있다. 그리고 마지막에 squeeze 함수를 통해 1차원 배열로 바꿔 imshow 함수로 이미지를 확인한다.
이미지 형태로 잘 나오는 것을 확인할 수 있다.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-5.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;마지막으로 sklearn 패키지에서 train_test_split 함수를 통해 데이터셋에서 x_train, x_val, y_train, y_val 셋을 만들어준뒤에 저장한다.
shape를 통해 마지막으로 확인해보면 train 셋 240개, val 셋 27개씩 만들어진것을 확인할 수 있다.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-6.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;2-lung-data-추출하기&quot;&gt;2. lung data 추출하기&lt;/h2&gt;

&lt;p&gt;우선 필요한 패키지와 함수들을 import 합니다.&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#필요한 패키지,함수,변수 import
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;keras.layers&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Activation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Conv2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Flatten&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Dense&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MaxPooling2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Dropout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LeakyReLU&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UpSampling2D&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;keras.models&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;load_model&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;keras.callbacks&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ReduceLROnPlateau&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;그 뒤에 numpy를 이용해 npy파일로 만들어 놓은 x_train, x_val, y_train, y_val 파일들을 load 합니다.&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;x_train&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;dataset/x_train.npy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y_train&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;dataset/y_train.npy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x_val&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;dataset/x_val.npy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y_val&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;dataset/y_val.npy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;각각을 살펴보면 다음과 같이 나온다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-7.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;train data 240개 val data는 27개씩 있다.&lt;/p&gt;

&lt;p&gt;인공지능 모델로 사용하는 것은 &lt;strong&gt;Convolutional Encoder-Decoder&lt;/strong&gt; 이다.
간단하게 말하면 CNN으로 이루어진 인코더-디코더 형태이다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-8.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Encoder는 차원을 축소해서 핵심 요소만 뽑는 것을 말하고 Decoder는 반대로 압축된 정보로부터 차원을 확장을 하면서 원하는 정보로 복원하는 것을 말한다.
여기서 위 그림과 같이 Input에는 CT이미지를 넣고 Output에는 폐의 영역만 흰색인 마스크 이미지로 뽑을 것입니다.&lt;/p&gt;

&lt;p&gt;Encoder부분에서는 Downsampling을 하는데 CNN에서 주로 사용하는 MaxPooling2D를 사용할 것이다.
MaxPooling2D를 통해 차원을 축소한다.&lt;/p&gt;

&lt;p&gt;Decoder부분에서는 Upsampling을 하는데 여기서 Upsampling2D는 반대로 차원을 확장하는 것이다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-9.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;위와 같이 행렬이 늘어나면서 0으로 채워주는 Upsampling, 반대로 행렬이 줄어드는 Downsampling을 보여주고 있다. 물론 0으로 채우는 것 외에 다양한 Upsampling 방법이 존재한다.&lt;/p&gt;

&lt;h3 id=&quot;2-1-model-구현&quot;&gt;2-1. Model 구현&lt;/h3&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#DownSampling
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Conv2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kernel_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;relu&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;same&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MaxPooling2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pool_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;same&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Conv2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kernel_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;relu&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;same&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MaxPooling2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pool_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;same&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Conv2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kernel_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;relu&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;same&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MaxPooling2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pool_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;same&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Dense&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;relu&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#UpSampling
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UpSampling2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Conv2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kernel_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;sigmoid&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;same&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UpSampling2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Conv2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kernel_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;sigmoid&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;same&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UpSampling2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;outputs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Conv2D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kernel_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;sigmoid&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;same&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;compile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;optimizer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;adam&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loss&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;binary_crossentropy&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;metrics&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;acc&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;mse&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Model은 위와 같이 만들어준다. Model을 확인해보면&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-10.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Model을 확인해보면 MaxPooling2D를 통해 256,256에서 128,128으로 줄고 계속 줄어 32,32까지 줄어든다.
그 후 Upsamping2D를 통해 256,256 까지 차원을 다시 확장한다.
이제 Training을 해주면 된다.&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;history&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_train&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;validation_data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;epochs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;batch_size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;callbacks&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ReduceLROnPlateau&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;monitor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;val_loss&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;factor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;patience&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;verbose&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;auto&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;min_lr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-05&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;epochs를 100으로 설정한 뒤에 학습이 끝나고 loss, acc, val_loss, val_acc를 확인해본다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-11.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;loss는 이상적으로 내려가는 것을 확인할 수 있고 반대로 정확도는 올라가므로 학습이 잘 된것을 확인할 수 있다.&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;preds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;predict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ax&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subplots&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;figsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;preds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;squeeze&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;gray&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;       
    &lt;span class=&quot;n&quot;&gt;ax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;squeeze&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;gray&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;squeeze&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;gray&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;이제 predict를 통해 학습된 모델로 lung data를 잘 추출하는지 확인해본다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/medical_ai/medical_ai1/medicalai1-12.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;결과값을 확인해보면 맨 왼쪽은 input으로 CT 이미지이고 가운데 있는 이미지는 실제 mask된 이미지이고 맨 오른쪽에 있는 이미지는 학습된 모델이 예측한 lung data 입니다.
두번째와 세번쨰를 비교했을 때 굉장히 비슷하게 잘 나오기 때문에 예측이 잘 된것을 확인할 수 있었다.&lt;/p&gt;

</description>
        <pubDate>Wed, 02 Sep 2020 00:00:00 +0900</pubDate>
        <link>https://Changhyun-song.github.io/medical_ai/Medical_AI-1/</link>
        <guid isPermaLink="true">https://Changhyun-song.github.io/medical_ai/Medical_AI-1/</guid>
        
        <category>medical_ai</category>
        
        <category>opencv</category>
        
        <category>segmentation</category>
        
        <category>deeplearning</category>
        
        <category>vision</category>
        
        
        <category>Medical_AI</category>
        
      </item>
    
      <item>
        <title>[OPencv] opencv를 이용한 python project(이미지 슬라이드쇼 만들기)</title>
        <description>&lt;h2 id=&quot;1-이미지-슬라이드-쇼-개요&quot;&gt;1. 이미지 슬라이드 쇼 개요&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;특정 폴더에 있는 모든 이미지 파일을 슬라이드 쇼로 만들기&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;구현 기능&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;특정 폴더에 있는 이미지 파일 목록 읽기&lt;/li&gt;
  &lt;li&gt;이미지를 전체 화면으로 출력하기&lt;/li&gt;
  &lt;li&gt;일정 시간동안 이미지를 화면에 출력 후 다음 이미지로 교체하기 -&amp;gt; 무한루프 형식으로&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-관련-함수-패키지-및-함수에-대해-알아보기&quot;&gt;2. 관련 함수 패키지 및 함수에 대해 알아보기&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;os.listdir()&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# 예시 - os
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;file_list&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;listdir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;.&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;images&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;file_list&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;.jpg&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;모든 파일 목록을 불러올 수 있고 그 중에서 jpg로 되어 있는 파일만 찾아서 불러올 수 있다.
&lt;strong&gt;glob.glob()&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# 예시 - glob
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;glob&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;.&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;images&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;*.jpg&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;glob 패키지는 특정 패턴의 문자열 이름을 다 불러올 수 있다. 위와 같이 images 폴더에 있는 파일들을 불러와도 되지만 현재 파일이 있는 곳에 images라는 폴더를 냅두지 않고
저처럼 assets이라는 폴더안에 모든 그림파일들을 넣어두었다면 glob.glob(‘assets/images/*.jpg’) 이렇게 바꿔주면 된다.&lt;/p&gt;

&lt;h2 id=&quot;3코드-구현하기&quot;&gt;3.코드 구현하기&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;3-1.images 폴더안에 있는 파일명들 확인하기&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;glob&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 현재 python 파일이 있는 위치에 images 폴더를 옮겨놓은 경우 위 예시처럼 바꿔주어야 함
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;assets/images/*.jpg&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;그럼 다음과 같이 images 안에 있는 파일명들이 나열된 것을 확인할 수 있다.&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv4/opencv4-1.png?raw=1&quot; width=&quot;800&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3-2.전체 화면 영상 출력 창 만들기&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nameWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;image&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WINDOW_NORMAL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setWindowProperty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;image&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WND_PROP_FULLSCREEN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WINDOW_FULLSCREEN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;image&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;#ESC
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cnt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;destroyALLWindows&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
  &lt;li&gt;먼저 cv2.WINDOW_NORMAL 속성의 창을 만들고 cv2.setWindowProperty() 함수를 사용하여 전체 화면 속성으로 바꿔준다.&lt;/li&gt;
  &lt;li&gt;그 뒤에 img 를 while 문에서 불러와서 ESC 키(27)를 누르기 전까지 반복적으로 사진을 imread 하면 끝!&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Thu, 05 Mar 2020 00:00:00 +0900</pubDate>
        <link>https://Changhyun-song.github.io/opencv/cv-5/</link>
        <guid isPermaLink="true">https://Changhyun-song.github.io/opencv/cv-5/</guid>
        
        <category>matplotlib</category>
        
        <category>opencv</category>
        
        <category>vision</category>
        
        
        <category>opencv</category>
        
      </item>
    
      <item>
        <title>[OpenCV] OpenCV를 이용한 Python Project (이미지 슬라이드쇼 만들기)</title>
        <description>&lt;h1 id=&quot;opencv를-이용한-python-project-이미지-슬라이드쇼-만들기&quot;&gt;OpenCV를 이용한 Python Project (이미지 슬라이드쇼 만들기)&lt;/h1&gt;

&lt;h2 id=&quot;개요&quot;&gt;개요&lt;/h2&gt;

&lt;p&gt;이번 프로젝트에서는 특정 폴더에 있는 모든 이미지 파일을 활용하여 간단한 &lt;strong&gt;이미지 슬라이드쇼&lt;/strong&gt;를 구현합니다.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;1-프로젝트-개요&quot;&gt;1. 프로젝트 개요&lt;/h2&gt;

&lt;h3 id=&quot;구현-기능&quot;&gt;구현 기능&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;특정 폴더에 있는 이미지 파일 목록 읽기.&lt;/li&gt;
  &lt;li&gt;이미지를 &lt;strong&gt;전체 화면&lt;/strong&gt;으로 출력하기.&lt;/li&gt;
  &lt;li&gt;일정 시간 동안 이미지를 화면에 출력 후 다음 이미지로 교체하기 (무한 루프 형식).&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;2-관련-패키지-및-함수&quot;&gt;2. 관련 패키지 및 함수&lt;/h2&gt;

&lt;h3 id=&quot;21-oslistdir&quot;&gt;2.1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;os.listdir()&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;폴더 내 모든 파일 목록 불러오기&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;특정 확장자(.jpg 등)를 가진 파일만 필터링 가능.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;file_list&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;listdir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;./images&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;file_list&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endswith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;.jpg&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;22-globglob&quot;&gt;2.2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glob.glob()&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;특정 패턴의 파일 이름 불러오기&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;원하는 경로와 파일 형식을 지정하여 간단하게 파일 목록 생성 가능.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;glob&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;./images/*.jpg&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;예시&quot;&gt;예시&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;현재 파일 경로와 다른 디렉토리에 이미지 파일이 있는 경우:
    &lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;assets/images/*.jpg&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;3-코드-구현&quot;&gt;3. 코드 구현&lt;/h2&gt;

&lt;h3 id=&quot;31-이미지-파일명-확인&quot;&gt;3.1 이미지 파일명 확인&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;glob&lt;/code&gt;를 사용하여 이미지 파일 경로를 읽어온 후, 파일명을 출력합니다.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;glob&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# assets 폴더 내 images 디렉토리에서 모든 JPG 파일 읽기
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;assets/images/*.jpg&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;실행-결과&quot;&gt;실행 결과&lt;/h4&gt;
&lt;p&gt;아래와 같이 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;images&lt;/code&gt; 폴더 내 파일명이 출력됩니다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv4/opencv4-1.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;32-전체-화면-출력-창-만들기&quot;&gt;3.2 전체 화면 출력 창 만들기&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.namedWindow&lt;/code&gt;와 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.setWindowProperty&lt;/code&gt;를 사용하여 &lt;strong&gt;전체 화면&lt;/strong&gt;을 구현합니다.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cv2&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;glob&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 이미지 파일 읽기
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;glob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;assets/images/*.jpg&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;namedWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;image&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WINDOW_NORMAL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setWindowProperty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;image&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WND_PROP_FULLSCREEN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WINDOW_FULLSCREEN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 이미지 파일 개수
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;img_files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 이미지 읽기
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;image&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# ESC 키를 누르면 종료
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;  
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cnt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;idx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;destroyAllWindows&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;코드-설명&quot;&gt;코드 설명&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;창 속성 설정&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.WINDOW_NORMAL&lt;/code&gt;: 창 크기를 조정 가능하도록 설정.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.WINDOW_FULLSCREEN&lt;/code&gt;: 창을 전체 화면으로 변경.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;이미지 출력&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.imshow()&lt;/code&gt;로 이미지를 출력.&lt;/li&gt;
      &lt;li&gt;이미지 파일 리스트를 반복적으로 순회하며 슬라이드쇼 구현.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;키 입력 처리&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.waitKey(1000)&lt;/code&gt;: 1초(1000ms) 동안 키 입력 대기.&lt;/li&gt;
      &lt;li&gt;ESC 키(27)를 누르면 반복문 종료.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;4-결과&quot;&gt;4. 결과&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;슬라이드쇼가 실행되며, 설정한 시간 간격으로 이미지를 전환합니다.&lt;/li&gt;
  &lt;li&gt;ESC 키를 누르면 프로그램이 종료됩니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;결론&quot;&gt;결론&lt;/h2&gt;

&lt;p&gt;이번 포스팅에서는 OpenCV와 Python을 사용해 간단한 &lt;strong&gt;이미지 슬라이드쇼&lt;/strong&gt;를 구현했습니다.&lt;br /&gt;
이미지 파일을 동적으로 읽고 전체 화면으로 출력하는 이 방법을 응용해 더욱 다양한 프로젝트를 시도해보세요!&lt;/p&gt;
</description>
        <pubDate>Thu, 05 Mar 2020 00:00:00 +0900</pubDate>
        <link>https://Changhyun-song.github.io/opencv/cv-4/</link>
        <guid isPermaLink="true">https://Changhyun-song.github.io/opencv/cv-4/</guid>
        
        <category>matplotlib</category>
        
        <category>opencv</category>
        
        <category>vision</category>
        
        
        <category>opencv</category>
        
      </item>
    
      <item>
        <title>[OpenCV] OpenCV를 이용한 실습 (Matplotlib을 사용하여 불러오기)</title>
        <description>&lt;h1 id=&quot;opencv를-이용한-실습-matplotlib을-사용하여-불러오기&quot;&gt;OpenCV를 이용한 실습 (Matplotlib을 사용하여 불러오기)&lt;/h1&gt;

&lt;h2 id=&quot;개요&quot;&gt;개요&lt;/h2&gt;

&lt;p&gt;이번 포스팅에서는 Python의 Matplotlib 라이브러리를 활용해 컬러 사진과 흑백 사진을 출력하는 방법을 알아봅니다.&lt;br /&gt;
또한, 두 가지 이미지를 동시에 출력하는 방법도 소개합니다.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;1-matplotlib-설치&quot;&gt;1. Matplotlib 설치&lt;/h2&gt;

&lt;p&gt;OpenCV와 함께 Matplotlib을 사용하려면 Matplotlib 패키지를 설치해야 합니다.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;matplotlib
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;2-컬러-영상-출력하기&quot;&gt;2. 컬러 영상 출력하기&lt;/h2&gt;

&lt;p&gt;컬러 영상을 출력하려면 영상 데이터가 &lt;strong&gt;RGB 순서&lt;/strong&gt;여야 합니다.&lt;br /&gt;
하지만 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.imread()&lt;/code&gt;로 이미지를 불러오면 &lt;strong&gt;BGR 순서&lt;/strong&gt;로 불러오기 때문에, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.cvtColor()&lt;/code&gt;를 사용하여 BGR을 RGB로 변환합니다.&lt;/p&gt;

&lt;h3 id=&quot;2-1-컬러-영상-출력-코드&quot;&gt;2-1. 컬러 영상 출력 코드&lt;/h3&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cv2&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 컬러 영상 읽기 및 BGR -&amp;gt; RGB 변환
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgBGR&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;cat.bmp&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;imgRGB&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cvtColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgBGR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;COLOR_BGR2RGB&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;off&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 눈금 제거
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgRGB&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;3-그레이스케일-영상-출력하기&quot;&gt;3. 그레이스케일 영상 출력하기&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;plt.imshow()&lt;/code&gt; 함수에서 컬러맵을 설정하여 그레이스케일 영상을 출력합니다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;컬러맵 설정&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cmap=&apos;gray&apos;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-1-그레이스케일-영상-출력-코드&quot;&gt;3-1. 그레이스케일 영상 출력 코드&lt;/h3&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cv2&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 그레이스케일 영상 읽기
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgGray&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;assets/cat.bmp&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IMREAD_GRAYSCALE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;off&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgGray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;gray&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;4-컬러와-그레이스케일-영상을-함께-출력하기&quot;&gt;4. 컬러와 그레이스케일 영상을 함께 출력하기&lt;/h2&gt;

&lt;p&gt;Matplotlib의 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;plt.subplot()&lt;/code&gt;을 사용하여 두 개의 영상을 동시에 출력할 수 있습니다.&lt;/p&gt;

&lt;h3 id=&quot;4-1-컬러와-그레이스케일-영상-동시-출력-코드&quot;&gt;4-1. 컬러와 그레이스케일 영상 동시 출력 코드&lt;/h3&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cv2&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 컬러 및 그레이스케일 영상 읽기
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgBGR&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;cat.bmp&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;imgRGB&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cvtColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgBGR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;COLOR_BGR2RGB&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;imgGray&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;assets/cat.bmp&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IMREAD_GRAYSCALE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subplot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;121&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;off&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgRGB&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subplot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;122&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;off&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgGray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;gray&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;5-전체-코드&quot;&gt;5. 전체 코드&lt;/h2&gt;

&lt;p&gt;아래는 위의 모든 과정을 포함한 전체 코드입니다.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cv2&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 컬러 영상 출력
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgBGR&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;assets/cat.bmp&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;imgRGB&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cvtColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgBGR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;COLOR_BGR2RGB&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;off&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgRGB&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 그레이스케일 영상 출력
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgGray&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;assets/cat.bmp&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IMREAD_GRAYSCALE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;off&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgGray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;gray&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 두 개의 영상을 함께 출력
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subplot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;121&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;off&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgRGB&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subplot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;122&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;axis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;off&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imgGray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;gray&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;6-결과&quot;&gt;6. 결과&lt;/h2&gt;

&lt;h3 id=&quot;컬러-영상-출력-결과&quot;&gt;컬러 영상 출력 결과&lt;/h3&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv3/opencv3-1.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;그레이스케일-영상-출력-결과&quot;&gt;그레이스케일 영상 출력 결과&lt;/h3&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv3/opencv3-2.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;컬러와-그레이스케일-영상을-함께-출력한-결과&quot;&gt;컬러와 그레이스케일 영상을 함께 출력한 결과&lt;/h3&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv3/opencv3-3.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;결론&quot;&gt;결론&lt;/h2&gt;

&lt;p&gt;Matplotlib과 OpenCV를 활용하면 다양한 방식으로 이미지를 출력할 수 있습니다.&lt;br /&gt;
이번 포스팅에서 다룬 방법을 응용하여 더 나은 데이터 시각화를 시도해보세요!&lt;/p&gt;
</description>
        <pubDate>Wed, 04 Mar 2020 00:00:00 +0900</pubDate>
        <link>https://Changhyun-song.github.io/opencv/cv-3/</link>
        <guid isPermaLink="true">https://Changhyun-song.github.io/opencv/cv-3/</guid>
        
        <category>matplotlib</category>
        
        <category>opencv</category>
        
        <category>vision</category>
        
        
        <category>opencv</category>
        
      </item>
    
      <item>
        <title>[OpenCV] OpenCV를 이용한 실습 (사진 불러오기)</title>
        <description>&lt;h2 id=&quot;개요&quot;&gt;개요&lt;/h2&gt;

&lt;p&gt;이번 포스팅에서는 OpenCV를 활용해 자주 사용하는 기본적인 함수들을 정리하고, 이를 활용한 사진 불러오기 예제를 소개합니다.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;1-opencv-기본-함수-알아보기&quot;&gt;1. OpenCV 기본 함수 알아보기&lt;/h2&gt;

&lt;h3 id=&quot;11-영상-파일-불러오기-cv2imread&quot;&gt;1.1 영상 파일 불러오기: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.imread&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;imread&lt;/code&gt; 함수를 사용하여 이미지 파일을 불러올 수 있습니다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Flags&lt;/strong&gt;: 이미지를 컬러, 흑백 등으로 불러오는 설정.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Filename&lt;/strong&gt;: 파일 경로와 확장자(.jpg, .bmp 등) 포함.&lt;/li&gt;
&lt;/ul&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv2/opencv2-1.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;12-영상-파일-저장하기-cv2imwrite&quot;&gt;1.2 영상 파일 저장하기: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.imwrite&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;imwrite&lt;/code&gt; 함수는 이미지를 저장할 때 사용됩니다.&lt;br /&gt;
주로 이미지를 수정한 뒤 저장하는 데 사용됩니다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv2/opencv2-2.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;13-새로운-창-띄우기-cv2namedwindow&quot;&gt;1.3 새로운 창 띄우기: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.namedWindow&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;namedWindow&lt;/code&gt; 함수를 사용하여 이미지를 출력할 창을 생성합니다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;창의 크기와 영상 크기를 조정할 수 있는 &lt;strong&gt;Flags&lt;/strong&gt;를 설정할 수 있습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv2/opencv2-3.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;14-창-닫기-cv2destroywindow&quot;&gt;1.4 창 닫기: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.destroyWindow&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroyWindow&lt;/code&gt; 함수는 특정 창을 닫거나, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroyAllWindows&lt;/code&gt;를 사용하여 모든 창을 닫을 수 있습니다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv2/opencv2-4.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;15-창-위치-이동-cv2movewindow&quot;&gt;1.5 창 위치 이동: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.moveWindow&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;moveWindow&lt;/code&gt; 함수를 사용하여 창을 원하는 위치(x, y 좌표)로 이동시킬 수 있습니다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv2/opencv2-5.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;16-창-크기-변경-cv2resizewindow&quot;&gt;1.6 창 크기 변경: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.resizeWindow&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resizeWindow&lt;/code&gt; 함수는 창의 크기를 조정하는 데 사용됩니다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;원하는 가로(width)와 세로(height)를 설정할 수 있습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv2/opencv2-6.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;17-영상-출력하기-cv2imshow&quot;&gt;1.7 영상 출력하기: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.imshow&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;imshow&lt;/code&gt; 함수는 지정된 창에 이미지를 출력합니다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;변수로 저장된 이미지 데이터를 창에 표시할 수 있습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv2/opencv2-7.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;18-키보드-입력-대기하기-cv2waitkey&quot;&gt;1.8 키보드 입력 대기하기: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv2.waitKey&lt;/code&gt;&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;waitKey&lt;/code&gt; 함수는 키 입력을 대기합니다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;특정 키 입력에 반응하도록 설정할 수도 있습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv2/opencv2-8.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;2-사진-불러오기-예제&quot;&gt;2. 사진 불러오기 예제&lt;/h2&gt;

&lt;p&gt;다음은 OpenCV를 사용하여 사진을 불러오는 간단한 예제입니다.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cv2&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 이미지 파일 읽기
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;example.jpg&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;Image load failed!&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 창 생성 및 이미지 출력
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;namedWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;image&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imshow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;image&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 모든 창 닫기
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;destroyAllWindows&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;코드-설명&quot;&gt;코드 설명&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;이미지 파일 불러오기&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;imread&lt;/code&gt;로 이미지를 읽어 변수 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img&lt;/code&gt;에 저장.&lt;/li&gt;
      &lt;li&gt;파일 경로와 확장자명을 정확히 입력해야 함.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;이미지 로드 실패 처리&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;이미지가 제대로 로드되지 않을 경우 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;None&lt;/code&gt;을 반환.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sys.exit()&lt;/code&gt;로 종료.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;창 생성 및 출력&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;namedWindow&lt;/code&gt;로 창 생성 후, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;imshow&lt;/code&gt;로 이미지를 출력.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;키 입력 대기 및 종료&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;waitKey&lt;/code&gt;로 키 입력을 대기.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroyAllWindows&lt;/code&gt;로 창을 닫음.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;예제-결과&quot;&gt;예제 결과&lt;/h3&gt;

&lt;p&gt;예제 코드를 실행하면 아래와 같이 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;image&lt;/code&gt; 창에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;example.jpg&lt;/code&gt; 이미지가 출력됩니다.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv2/opencv2-10.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;결론&quot;&gt;결론&lt;/h2&gt;

&lt;p&gt;이번 포스팅에서는 OpenCV의 기본 함수와 사진 불러오기 예제를 다뤘습니다. OpenCV의 다양한 기능을 활용하여 컴퓨터 비전 프로젝트를 진행해보세요!&lt;/p&gt;
</description>
        <pubDate>Tue, 03 Mar 2020 00:00:00 +0900</pubDate>
        <link>https://Changhyun-song.github.io/opencv/cv-2/</link>
        <guid isPermaLink="true">https://Changhyun-song.github.io/opencv/cv-2/</guid>
        
        <category>anaconda</category>
        
        <category>opencv</category>
        
        <category>vision</category>
        
        
        <category>opencv</category>
        
      </item>
    
      <item>
        <title>[OpenCV] Mac에서 Anaconda, Python, OpenCV 설치 가이드</title>
        <description>&lt;h2 id=&quot;개요&quot;&gt;개요&lt;/h2&gt;

&lt;p&gt;이 포스트에서는 Mac에서 Anaconda 가상환경을 설정하고, Python과 OpenCV를 설치하는 방법을 다룹니다.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Anaconda 설치&lt;/strong&gt;: Python 기반의 가상환경 설정과 관리.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;가상환경 구성&lt;/strong&gt;: 특정 프로젝트에 필요한 Python 버전 및 라이브러리 설치.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;OpenCV 설치 및 확인&lt;/strong&gt;: 컴퓨터 비전 라이브러리(OpenCV) 설치와 동작 확인.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;1-anaconda-설치&quot;&gt;1. Anaconda 설치&lt;/h2&gt;

&lt;p&gt;Python과 OpenCV를 편리하게 사용하기 위해 Anaconda를 설치합니다. Anaconda는 가상환경을 설정하여 프로젝트별로 필요한 라이브러리를 관리하기 쉽게 해줍니다.&lt;/p&gt;

&lt;h3 id=&quot;설치-과정&quot;&gt;설치 과정&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.anaconda.com/products/individual#download-section&quot;&gt;Anaconda 공식 웹사이트&lt;/a&gt;에서 &lt;strong&gt;MacOS Command Line Installer&lt;/strong&gt;를 다운로드합니다.
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;GUI Installer 대신 Command Line Installer를 사용하는 이유&lt;/em&gt;: 터미널(iTerm2)에서 Anaconda 환경을 바로 사용하기 위해.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv1/opencv1-1.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;터미널에서 &lt;strong&gt;다운로드된 파일&lt;/strong&gt;로 이동하여 설치를 시작합니다.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ~/Downloads
bash Anaconda3-&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;설치 과정을 진행하며 &lt;strong&gt;“Yes”&lt;/strong&gt;를 입력하여 사용 동의를 완료합니다.&lt;/li&gt;
&lt;/ol&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv1/opencv1-3.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;설치 완료 후 환경 초기화를 진행합니다.
    &lt;ul&gt;
      &lt;li&gt;초기화 완료 시 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.zshrc&lt;/code&gt; 파일이 자동으로 업데이트됩니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv1/opencv1-4.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;h3 id=&quot;설치-확인&quot;&gt;설치 확인&lt;/h3&gt;

&lt;p&gt;설치가 완료되면 터미널을 재시작한 후 다음 명령어를 실행하여 Anaconda와 Python이 정상 설치되었는지 확인합니다.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;conda &lt;span class=&quot;nt&quot;&gt;--version&lt;/span&gt;
python &lt;span class=&quot;nt&quot;&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv1/opencv1-6.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;2-anaconda-가상환경-설정&quot;&gt;2. Anaconda 가상환경 설정&lt;/h2&gt;

&lt;p&gt;가상환경을 생성하여 프로젝트별로 Python 버전과 라이브러리를 독립적으로 관리합니다.&lt;/p&gt;

&lt;h3 id=&quot;가상환경-생성&quot;&gt;가상환경 생성&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;터미널에서 다음 명령어를 입력하여 Python 3.8 기반의 새로운 가상환경을 생성합니다.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;conda create &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; tf &lt;span class=&quot;nv&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;3.8
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv1/opencv1-7.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;생성된 가상환경을 활성화합니다.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;conda activate tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv1/opencv1-8.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;h3 id=&quot;opencv-설치&quot;&gt;OpenCV 설치&lt;/h3&gt;

&lt;p&gt;가상환경 활성화 후, OpenCV를 설치합니다.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;opencv-python
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;설치가 완료되면 정상적으로 설치되었는지 확인합니다.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;3-opencv-설치-확인&quot;&gt;3. OpenCV 설치 확인&lt;/h2&gt;

&lt;p&gt;PyCharm 등의 IDE에서 가상환경을 연결한 뒤, OpenCV를 테스트합니다.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;PyCharm에서 가상환경을 연결합니다.&lt;/li&gt;
&lt;/ol&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv1/opencv1-10.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;다음 Python 코드를 실행하여 OpenCV 설치를 확인합니다.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cv2&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;OpenCV Version:&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__version__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;OpenCV 버전이 출력되면 설치가 성공적으로 완료된 것입니다.&lt;/li&gt;
&lt;/ol&gt;

&lt;p align=&quot;center&quot;&gt;
  &lt;img src=&quot;https://github.com/Changhyun-song/Changhyun-song.github.io/blob/main/_posts/images/cv/opencv1/opencv1-11.png?raw=1&quot; width=&quot;800&quot; /&gt;
&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;결론&quot;&gt;결론&lt;/h2&gt;

&lt;p&gt;이번 포스트에서는 Mac에서 Anaconda를 사용하여 Python과 OpenCV를 설치하는 방법을 알아보았습니다. 가상환경을 활용하면 프로젝트별로 다양한 Python 버전과 라이브러리를 쉽게 관리할 수 있습니다. OpenCV 설치를 완료했다면 다양한 컴퓨터 비전 프로젝트를 시작해보세요! 😊&lt;/p&gt;
</description>
        <pubDate>Mon, 02 Mar 2020 00:00:00 +0900</pubDate>
        <link>https://Changhyun-song.github.io/opencv/cv-1/</link>
        <guid isPermaLink="true">https://Changhyun-song.github.io/opencv/cv-1/</guid>
        
        <category>anaconda</category>
        
        <category>opencv</category>
        
        <category>vision</category>
        
        
        <category>opencv</category>
        
      </item>
    
  </channel>
</rss>