Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FastAPI] 이미지 처리 레퍼런스 #16

Open
baekkr95 opened this issue May 27, 2022 · 3 comments
Open

[FastAPI] 이미지 처리 레퍼런스 #16

baekkr95 opened this issue May 27, 2022 · 3 comments
Assignees
Labels
📚 documentation Improvements or additions to documentation 📝Discussion

Comments

@baekkr95
Copy link
Contributor

baekkr95 commented May 27, 2022

Background

  • 아이디어 및 레퍼런스 공유 이슈로 사용

Content ( 해결해야 될 문제점 공유 )

1. dehazed image를 웹에 출력
2. dehazed image를 sky segmentation model에 전달
3. on_event("startup")으로 DB 연결, 모델 Load 등.. 여러 로직 실행 가능
4. on_event("shutdown")으로 DB 연결 해제, 로깅 결과 받기(Unique data, 기타 등등)
5. DB에서 가상의 구름&하늘 사진을 받아서 Streamlit에 출력
6. dehazing & segmentation Model의 Inference를 백그라운드에서 실행
7. dehazed와 sky replacement 모델을 서버 실행과 동시에 load_model 한다. → get_prediction에서 load_model을 분리
8. 이미지 다운로드과 함께 input image, 선택한 구름 정보를 db에 저장할 예정 → 추후에 서비스적으로 개선 가능

@baekkr95 baekkr95 added 📚 documentation Improvements or additions to documentation 📝Discussion labels May 27, 2022
@baekkr95
Copy link
Contributor Author

baekkr95 commented May 27, 2022

image

@baekkr95
Copy link
Contributor Author

@omocomo
Copy link
Member

omocomo commented May 27, 2022

dehazed image 출력

frontend.py

def main():
    st.title("Dehazing Model")
    uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg","png"])

    if uploaded_file:
        image_bytes = uploaded_file.getvalue()
        image = Image.open(io.BytesIO(image_bytes))

        st.image(image, caption='Uploaded Image')
        st.write("Dehazing...")

        # 기존 stremalit 코드
        # _, y_hat = get_prediction(model, image_bytes)
        # label = config['classes'][y_hat.item()]
        files = [
            ('files', (uploaded_file.name, image_bytes,
                       uploaded_file.type))
        ]
        response = requests.post("http://localhost:30001/predict", files=files)
        dehaze_image = Image.open(io.BytesIO(response.content)).convert('RGB')
        st.image(dehaze_image)

main.py

from fastapi import Response
import io

@app.post("/predict", description="hazing 결과를 요청합니다.")
async def make_order(files: List[UploadFile] = File(...)):
    for file in files:
        image_bytes = await file.read()
        inference_result = get_prediction(image_bytes)

    img_byte_arr = io.BytesIO()
    inference_result.save(img_byte_arr, format='PNG')
    img_byte_arr = img_byte_arr.getvalue()

    return Response(content=img_byte_arr, media_type="image/png")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation Improvements or additions to documentation 📝Discussion
Projects
None yet
Development

No branches or pull requests

2 participants