# AttributeError: 'Prediction' object has no attribute 'label'

**URL:** https://discuss.roboflow.com/t/attributeerror-prediction-object-has-no-attribute-label/3912
**Category:** 🤝  Community Help
**Created:** [December 6, 2023, 9:44pm UTC](https://discuss.roboflow.com/t/attributeerror-prediction-object-has-no-attribute-label/3912 "2023-12-06T21:44:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Yashamaskaev](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/yashamaskaev/32/4223_2.png) [@Yashamaskaev](https://discuss.roboflow.com/u/Yashamaskaev)
#### Post date: [December 6, 2023, 9:44pm UTC](https://discuss.roboflow.com/t/attributeerror-prediction-object-has-no-attribute-label/3912/1 "2023-12-06T21:44:52Z")

</div>

Hi! I have a code for recognizing road signs. Everything is implemented on Raspberry Pi 4. The code itself is below:

```auto
import requests
import cv2
import numpy as np
from picamera import PiCamera
from roboflow import Roboflow

# Инициализируем клиент Roboflow
rf = Roboflow(api_key="my_api_key")
project = rf.workspace().project("project_name")
model = project.version(1).model

# Инициализация камеры
camera = PiCamera()

# Загружаем классы для вывода результатов
classes = ['Stop', '60 km/h', '40 km/h', 'Forward']

# Захватываем видеопоток с камеры
camera.start_preview()
while True:
    # Снимаем фрейм с камеры и сохраняем его
    camera.capture('frame.jpg')

    # Загружаем фрейм и изменяем его размер
    image = cv2.imread('frame.jpg')
    image = cv2.resize(image, (300, 300))

    # Конвертируем изображение в формат RGB
    image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    # Предсказываем на изображении
    result = model.predict(image_rgb)

    # Извлекаем информацию о дорожных знаках из результата
    detections = result.predictions

    for detection in detections:
        class_name = detection.label
        confidence = detection.confidence
        box = detection.bounding_box

        # Извлекаем координаты прямоугольника и делаем преобразования соответствующим образом

        # Рисуем прямоугольник и текст на изображении

    # Выводим результаты на экран
    cv2.imshow("Road Sign Detection", image)

    # Выход из цикла по нажатию клавиши 'q'
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Закрываем окна и освобождаем ресурсы камеры
cv2.destroyAllWindows()
camera.stop_preview()

```

But I get an error and I don’t understand which correct attribute is needed here.

```auto
Traceback (most recent call last): File "/home/rasberrypi/Desktop/Проект 3/ai17.py", 
line 38, in <module> class_name = detection.label 
AttributeError: 'Prediction' object has no attribute 'label' 

```

**The error itself occurs when I show the desired road sign to the camera (that is, at the recognition stage)**

---

<div class="post-metadata">

### Author: ![Lenny](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/lenny/32/2383_2.png) [@Lenny](https://discuss.roboflow.com/u/Lenny)
#### Post date: [December 6, 2023, 9:46pm UTC](https://discuss.roboflow.com/t/attributeerror-prediction-object-has-no-attribute-label/3912/2 "2023-12-06T21:46:26Z")

</div>

Your code seems to be well-structured for running inference on a Raspberry Pi using Roboflow. However, it seems like the code is incomplete, as the last line is cut off.

Here’s a similar code snippet from the extracts that might help you:

```python
from roboflow import Roboflow
rf = Roboflow(api_key="API_KEY")
project = rf.workspace().project("PROJECT_NAME")
model = project.version(MODEL_VERSION, local="http://localhost:9001").model

# infer on a local image
print(model.predict("your_image.jpg", confidence=40, overlap=30).json())

# visualize your prediction
# model.predict("your_image.jpg", confidence=40, overlap=30).save("prediction.jpg")

# infer on an image hosted elsewhere
# print(model.predict("URL_OF_YOUR_IMAGE", hosted=True, confidence=40, overlap=30).json())

```

[Source](https://roboflow.com/how-to-deploy/yolov5-raspberry-pi)

In your case, you might want to replace `"your_image.jpg"` with the image captured from your camera. Also, you might want to adjust the `confidence` and `overlap` parameters according to your needs.

For the incomplete part of your code, if you’re trying to break the loop when a certain key is pressed, you can use something like this:

```python
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

```

This will break the loop when ‘q’ is pressed.

Please note that the code snippets provided are based on the information extracts and might need to be adjusted to fit your specific use case.

* * *

> Hi! I’m Roboflow’s AI powered bot. This is an automated response powered using AI with knowledge from our docs, blog, and forum. If this solves your issue, please mark it as the solution using the checkbox icon. If this doesn’t solve your issue, please follow up with what you’ve tried/why, and the community will continue to chime in as usual.

---

<div class="post-metadata">

### Author: ![Yashamaskaev](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/yashamaskaev/32/4223_2.png) [@Yashamaskaev](https://discuss.roboflow.com/u/Yashamaskaev)
#### Post date: [December 6, 2023, 9:54pm UTC](https://discuss.roboflow.com/t/attributeerror-prediction-object-has-no-attribute-label/3912/3 "2023-12-06T21:54:57Z")

</div>

Also tried attributes: class/classes/class\_id/label

roboflow ver. 1.1.12

Python 3.9

---

<div class="post-metadata">

### Author: ![leo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/leo/32/2228_2.png) [@leo](https://discuss.roboflow.com/u/leo)
#### Post date: [December 10, 2023, 7:07am UTC](https://discuss.roboflow.com/t/attributeerror-prediction-object-has-no-attribute-label/3912/4 "2023-12-10T07:07:05Z")

</div>

Hi @Yashamaskaev

Sorry to hear you’re having trouble. The hosted inference API, which the Roboflow Python package uses, returns the following format. The class name is returned in a property called `class` under an array `predictions`.

If you already tried this, there might be another issue, so could you add a print statement, below that to see what the model result is?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/bb6edbfa56d0cf2ee603f061e9e09103502cc8cc.png) [@system](https://discuss.roboflow.com/u/system)
#### Post date: [December 31, 2023, 7:07am UTC](https://discuss.roboflow.com/t/attributeerror-prediction-object-has-no-attribute-label/3912/5 "2023-12-31T07:07:55Z")

</div>

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
