inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

딥러닝 웹서비스 프로젝트 1 - 기본편. Object Detect 불량품 판별

flask Method Not Allowed The method is not allowed for the requested URL오류발생

1157

청테이프

작성한 질문수 9

0

항상 좋은 강의 감사합니다.

열씸히 따라 하다 웹앱 웹서비스 테스트 마지막 부분에서 flask main.py실행 하였으나 제목 처럼 오류가 발생했습니다.

main.py에서 methods는 ['POST']이고 host:127.0.0.1입니다. 

여기저기 구글링 검색해도 명확한 답이 나오지 않아 이렇게 질문 드립니다.

main.py 코드는 다음과 같습니다. 감사합니다

from flask import Flask, request, Response, jsonify
import base64
from flask_cors import CORS
import numpy as np
import cv2
from PIL import Image
from io import BytesIO

confthres=0.5 #confidence값 0.5이상 값만 찾음
nmsthres=0.1

app = Flask(__name__)
CORS(app)

@app.route('/mobileweb/yolo'methods=['POST']) #web주소 세팅
def main():
    labelsPath="./model/coco.names"
    configpath="./model/yolov3.cfg"
    weightspath="./model/yolov3.weights"
    print("[INFO] loading YOLO models...")
    LABELS = open(labelsPath).read().strip().split("\n")
    net = cv2.dnn.readNetFromDarknet(configpath, weightspath) #yolo file loading

  #image file -> ascii converter
    file = request.form['image']
    starter = file.find(',')
    image_data = file[starter+1:]
    image_data = bytes(image_data, encoding="ascii")
    img = Image.open(BytesIO(base64.b64decode(image_data)))

    #img = cv2.imread('./railworker.jpg')

    npimg=np.array(img)
    image=npimg.copy()
    image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
    (H, W) = image.shape[:2]

    ln = net.getLayerNames()
    ln = [ln[i[0] - 1for i in net.getUnconnectedOutLayers()] #yolo model적용시 사용

    blob = cv2.dnn.blobFromImage(image, 1 / 255.0, (416416),
                                 swapRB=Truecrop=False)
    net.setInput(blob)
    layerOutputs = net.forward(ln)

    boxes = []
    confidences = []
    classes = []
    results = []

    for output in layerOutputs:
        for detection in output:
            scores = detection[5:]
            classID = np.argmax(scores)
            confidence = scores[classID]

            if confidence > confthres: #50%이상값만 찾음
                box = detection[0:4] * np.array([W, H, W, H])
                (centerX, centerY, width, height) = box.astype("int")

                x = int(centerX - (width / 2))
                y = int(centerY - (height / 2))

                boxes.append([x, y, int(width), int(height)])
                confidences.append(float(confidence))
                classes.append({'id'int(classID), 'name': LABELS[classID]})

    idxs = cv2.dnn.NMSBoxes(boxes, confidences, confthres, nmsthres)

    if len(idxs) > 0:
        for i in idxs.flatten():
            results.append({'class': classes[i], 'confidence': confidences[i], 'bbox': boxes[i]}) 

    return jsonify(results)

if __name__ == '__main__':
    app.run(debug=Truehost='127.0.0.1')

구글-앱-엔진 IONIC pwa flask

답변 2

0

청테이프

네~~감사합니다

0

노마드크리에이터

안녕하세요?

코드만 봐서는 문제 없어보이는데 Client에서 POST방식으로 Request를 하신 것인지 플라스크에서 확인해 보세요.

가끔 Client에서 PUT방식을 사용하면 유사한 에러가 생깁니다.

감사합니다.

노션 링크

0

29

3

노션 권한요청하였습니다 언제쯤 볼수있나요

0

31

2

5번 강의 1분까지 완료 후 오류가 뜹니다

0

23

2

노션 접속 권한 요청드립니다.

0

24

2

윈도우 사용자 환경설정

0

26

2

5-4-1. VCP 스캐너 만들기 프롬프트 질문

0

29

1

"gemini-2.0-flash". ->"gemini-2.5-flash".

0

27

2

알고리즘에 사용되는 상수값들이나 지표들에 대해 문의드립니다.

0

27

1

Claude Desktop Update에 따른 변화

0

29

2

t수강생 노션승인

0

49

2

노션접속권한요청

0

43

4

학습 관련 질문

0

52

2

노션 학습자료 문의

0

62

2

코드 다운로드

0

419

3

다른 모델을 웹페이지에 적용

0

421

0

동시 요청

0

340

0

from flask import Flask, request, Resopnse, jsonify 여기서 에러가 나와요..!

0

354

1

밑에 분들하고 비슷한 에러네요...

0

1041

1

에러 뜨면서 안되는데 어떻게 해야할까요

0

313

1

바운딩박스 조정

0

454

1

궁금한사항 올립니다.

0

299

2

400 Bad Request 발생합니다.

0

467

1

app.yaml파일에 관해서

0

214

2

python main.py실행하면 아무런 반응이 없습니다.

0

649

3