• 카테고리

    질문 & 답변
  • 세부 분야

    컴퓨터 비전

  • 해결 여부

    해결됨

KerasYolo3_학습및_Detection 그레이 이미지 출력 에러( 커스텀 데이터)

20.09.14 13:47 작성 조회수 421

0

안녕하세요 강사님 오랜만에 인사드립니다. 강사님이 저번에 가르쳐 주셔서 labellmg 을 이용해서 직접 Dataset을 만들어
공부를 하고 있습니다. 그런데 문제가 발생했습니다. 그레이스케일을 그대로 출력하는 문제입니다.

강사님 강의중 "Raccoon 데이터 세트를 YOLO V3로 학습" Code를 이용하여 학습 모델까지 만들었는데 아래 마지막 이미지와 같이 "TypeError: function takes exactly 1 argument (3 given)" 에러가 발생했습니다. 

그레이스케일을 RGB로 다시 변경해주는 코드를 생성해줘야하는것은 강의를 들어서 이해했는데  어느부분 Code를 어떻게 수정해야할 지.. 막막해서 질문드립니다.

  • 그레이이미지 그대로 디텍션 하려면 어느부분의 Code가 수정되야할 지 궁금합니다.

답변 8

·

답변을 작성해보세요.

1

JH S님의 프로필

JH S

2020.09.14

39번째 실행 셀에

img = Image.open("c(25).png")
rgbimg = img.convert('RGB')



또는
img = Image.open("c(25).png")
rgbimg = Image.new("RGBA", img.size)
rgbimg.paste(img)

를  이용해서 gray scale image를 rgb로 바꿔보시는 건 어떠신지요?

이 페이지를 참고해서 해보세요. 

https://stackoverflow.com/questions/18522295/python-pil-change-greyscale-tif-to-rgb

0

지금 detect_image()에서 오류가 나는건 맞죠?

전체 소스코드와 학습 데이터를 colab에 올려 주시면 제가 함 테스트 해보겠습니다. 코랩용 실습 코드를 참조하셔서 작성하시고 저에게 URL을 알려 주시면 될 것 같습니다.

0

감사합니다. 강사님  두방법다 하루동안 여러가지로 적용해보았지만 여전히

TypeError: function takes exactly 1 argument (3 given) 발생하네요 

스텍오버플로우 쫌 더 뒤적 뒤적 해보겠습니다. ^^

0

바로 RGB를 Greyscale로 바꾸는건 위에 JH S님이 주신것 같고, 아래와 같이 grayscale을 ndarray로 변환한 뒤에 다시 Image변환을 하신 후 입력해보심이 어떨지요?

from skimage import color
from skimage import io
from PIL import Image

# RGB를 Grayscale로 ndarray 변환
img = color.rgb2gray(io.imread('image.png'))
print(img.shape)

# ndarray를 PIL Image로 변환
img2 = Image.fromarray(img)
print(type(img2), img2.width, img2.height)

0

안녕하세요 강사님 답변 감사합니다. 학습용 데이터는 보다 싶이 Grayscale 입니다.

제가 수정하고 싶은 부분은 img = Image.open 부분이 현재RGB 로 나오는데 이것을 
Grayscale 원본으로 보고 싶은 것입니다. 

  • 에러가 나는 부분은 코드 부분입니다.

detected_img = raccoon_yolo.detect_image(img)

plt.figure(figsize=(12, 12))
plt.imshow(detected_img)

  •  에러 메시지는 아래와 같습니다.
(416, 416, 3)
Found 1 boxes for img
ag_contamination 0.41 (27, 36) (66, 71)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-2cded698421e> in <module>
----> 1 detected_img = raccoon_yolo.detect_image(img)
      2 
      3 plt.figure(figsize=(12, 12))
      4 plt.imshow(detected_img)

~/DLCV/Detection/yolo/keras-yolo3/yolo.py in detect_image(self, image)
    159             draw.rectangle(
    160                 [tuple(text_origin), tuple(text_origin + label_size)],
--> 161                 fill=self.colors[c])
    162             draw.text(text_origin, label, fill=(0, 0, 0), font=font)
    163             del draw

~/anaconda3/envs/tf113/lib/python3.6/site-packages/PIL/ImageDraw.py in rectangle(self, xy, fill, outline, width)
    246     def rectangle(self, xy, fill=None, outline=None, width=1):
    247         """Draw a rectangle."""
--> 248         ink, fill = self._getink(outline, fill)
    249         if fill is not None:
    250             self.draw.draw_rectangle(xy, fill, 1)

~/anaconda3/envs/tf113/lib/python3.6/site-packages/PIL/ImageDraw.py in _getink(self, ink, fill)
    117                 if self.palette and not isinstance(fill, numbers.Number):
    118                     fill = self.palette.getcolor(fill)
--> 119                 fill = self.draw.draw_ink(fill)
    120         return ink, fill
    121 

TypeError: function takes exactly 1 argument (3 given)

0

먼저 오류가 어떤 라인에서 나는지 확인이 필요할 것 같습니다.

raccoon_yolo.detect_image()인지 , plt.imshow() 인지 확인이 필요할 것 같습니다. 전체 오류 메시지를 이미지 캡처 하지마시고 텍스트로 복사해서 올려 주십시요.

학습용 데이터는 3차원 RGB 인가요? 아님 Grayscale인가요?

그리고 반환 데이터인 detected_img.shape 로 shape 정보도 업데이트 부탁드립니다.

0

권철민 강사님 위에 도움주신 다른 수강자 말대로 해도

TypeError: function takes exactly 1 argument (3 given) 에러가 발생합니다. 

혹시 강사님이 추천해주실 방법이...

0

안녕하십니까,

저도 모르고 있었던 방법인데, JH S 님이 올려 주신 방법으로 한번 해보시고, 내용 업데이트 부탁드립니다.

감사합니다.