'Deep'에 해당되는 글 2건

  1. 2026.02.07 [YOLO] Pose Estimation 포즈 추정
  2. 2025.01.15 [DL] Keras(TensorFlow) 관련 에러 해결
반응형

YOLO를 이용해 포즈를 추정해 보자.

 

from ultralytics import YOLO

kpt_names = ["nose", "left_eye", "right_eye", "left_ear", "right_ear", "left_shoulder",
             "right_shoulder", "left_elbow", "right_elbow", "left_wrist", "right_wrist",
             "left_hip", "right_hip", "left_knee", "right_knee", "left_ankle", "right_ankle"]

model = YOLO("yolo26n-pose.pt")  # "yolo26n-pose.pt"가 없다면 자동으로 다운로드 받는다
results = model("palvin1.png", save=True)

print(f"Length of results: {len(results)}")
# 1개의 이미지만 사용했으므로 results에는 1개의 원소만 있다

# Access the results
for result in results: # results에는 1개의 원소만 있기 때문에 for 루프를 사용하는 의미는 없다
    xy = result.keypoints.xy  # x and y coordinates
    xyn = result.keypoints.xyn  # normalized
    kpts = result.keypoints.data  # x, y, visibility (if available)
    
    print(f"Number of people: {len(result)}")
        
    for i, kpt in enumerate(kpts):
        print(f"Confidence: {result.boxes.conf[i]}")
        for name, k in zip(kpt_names, kpt):
            if k[2] > 0.3: # k[2]: visibility
                print(f"{name} is at {k}")
            else:
                print(f"{name} is not visible")
        print()

 

 

 

 

 

 

 

 

※ 참고

Predict

Pose Estimation

YOLO8 OpenCV

 

반응형
Posted by J-sean
:
반응형

Keras 관련 에러를 몇 가지 확인하고 해결해 보자.

 

1)

dense = keras.layers.Dense(10, activation='softmax', input_shape=(784, ))

위 명령을 실행하면 아래와 같은 경고가 출력된다.

UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.

경고이므로 무시하고 넘어간다.


model = keras.Sequential(dense)
이어서 위 명령은 아래와 같은 에러가 출력된다.

TypeError: 'Dense' object is not iterable
아래와 같이 바꿔서 해결한다.
model = keras.Sequential([dense])

 

아니면 처음부터 아래와 같이 입력하면 경고나 에러 없이 진행 된다.
model = keras.Sequential([keras.Input(shape=(784, )), keras.layers.Dense(10, activation='softmax')])

 

2)

model.compile(loss='sparse_categorical_crossentropy', metrics='accuracy')

위 명령을 실행하면 아래와 같은 에러가 출력된다.

ValueError: Expected `metrics` argument to be a list, tuple, or dict. Received instead: metrics=accuracy of type <class 'str'>

아래와 같이 바꿔서 해결한다.
model.compile(loss='sparse_categorical_crossentropy', metrics=['accuracy'])

 

 

 

※ 참고

혼자 공부하는 머신러닝 + 딥러닝

 

반응형
Posted by J-sean
: