boostcampaitech3 / final-project-level3-cv-17

[2022.05.16 ~ 2022.06.10] 🌤️미세먼지 없는 맑은 사진📷 - 부스트캠프 AI Tech 3기 최종 프로젝트
13 stars 3 forks source link

[feat] Finish Sky Selection #23

Closed hyoseok1223 closed 2 years ago

hyoseok1223 commented 2 years ago

What is this PR?

Sky Selection, Segmentation, Resize 등등 피드백을 받았던 것들을 대부분 수정한 2차 프로토 타입입니다.

Changes

수정된 부분이 많아 차차 정리하겠습니다. 간단한 사용법만 언급하자면 python main.py --image_path /opt/ml/input/final-project-level3-cv-17/data/dehazed_images/1.png --option "a dark night sky" --challenge 와 같은 커맨드를 통해 사용하실 수 있고 옵션 주실 때 "" 붙이시는 거 주의만 해주시면 될 것 같습니다. 현재 가능한 옵션의 목록은 다음과 같습니다.

a pink sky, a blue sky, a sunset sky, a sky with small clouds , a sky with large clouds, a dark night sky, the starry night sky Serving을 위해서 한글로 바꾼다던가 등 모두 가능하니 수정사항은 편하게 말씀해주세요

추가적으로 imutils라는 패키지와 CLIP이 설치되어야 합니다. ( 코드 단에서 main.py를 사용함에 있어 돌아가지는 않습니다만, import 하는 부분이 있어 일단 해두시면 좋을 것 같습니다.) 추후에 readme를 깔끔하게 정리할 생각이고 우선은 추가적인 패키지는 아래와 같이 설치해주시면 됩니다.

$ pip install imutils
$ pip install ftfy regex tqdm
$ pip install git+https://github.com/openai/CLIP.git

마지막으로 가장 중요한 부분 중 하나인데, 아직 segmentation부분에 대해서는 실험과 코드가 덜 정리된 상태입니다. 현재상황에서 대부분 돌아가지만, 혹시 그냥 돌리셨을 때 에러가 나신다면 --challenge 옵션을 붙이고 돌리시면 대부분 해결될 것으로 보입니다.

To reviewers

omocomo commented 2 years ago

저는 pip install tables 이것도 추가로 설치하고, 드라이브에서 받은 하늘 이미지와 weight 경로에 맞게 넣어주면 간단한 사용법으로 알려주신 python main.py --image_path /opt/ml/input/final-project-level3-cv-17/data/dehazed_images/1.png --option "a dark night sky" --challenge 문제없이 돌아갔습니다. 새로 올려주신 부분까지 포함해 fastapi에서 사용할 수 있도록 수정할 예정입니다.

Dongwoo-Im commented 2 years ago

다음에 push하실 때 몇개 해주셨으면 해서 적어둡니다. (제가 해도 되긴 한데, 작업중이실거같아서..)

생각해봤는데 result 이름을 바꾸면 increment_path 때문에 안되겠네요

Dongwoo-Im commented 2 years ago

replace.py replace_sky 함수 코드를 바꿔봤습니다. 기존과 동일한 값을 출력하면서 시간상으로 꽤 이득이네요.

image

def replace_sky(img,img_mask,ref,ref_mask):

    height, width = img_mask.shape
    sky_resize = cv2.resize(ref, (width, height))

    # before
    start = time.time()
    I_rep=img.copy()
    sz=img.shape
    for i in range(sz[0]):
        for j in range(sz[1]):
            if(img_mask[i,j].any()):
                I_rep[i,j,:] = sky_resize[i,j,:]
    print("before:", time.time() - start)

    # after
    start = time.time()
    mask_bool = (img_mask/255).astype(np.uint8)
    mask_bool_reverse = (1-img_mask/255).astype(np.uint8)
    new_img = np.zeros_like(img)
    new_img += np.repeat(mask_bool[:,:,np.newaxis], 3, axis=2) * sky_resize
    new_img += np.repeat(mask_bool_reverse[:,:,np.newaxis], 3, axis=2) * img
    print("after:", time.time() - start)

    print(img.shape[0]*img.shape[1]*img.shape[2] == np.sum(new_img==I_rep))

    return new_img