# Creating custom Object Detection model

**URL:** <https://discuss.roboflow.com/t/creating-custom-object-detection-model/2190>\
**Category:** 🤝  Community Help\
**Tags:** export\
**Created:** [May 15, 2023, 3:54am UTC](https://discuss.roboflow.com/t/creating-custom-object-detection-model/2190 "2023-05-15T03:54:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaandle](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/yaandle/32/1942_2.png) [@Yaandle](https://discuss.roboflow.com/u/Yaandle)\
**Post date:** [May 15, 2023, 3:54am UTC](https://discuss.roboflow.com/t/creating-custom-object-detection-model/2190/1 "2023-05-15T03:54:30Z")

</div>

I have a trained Object Detection model that I have exported the code into VS code on Windows. I want to change the code so that I can input a number and the program finds and outputs all the photos in the dataset that contain the corresponding number. If anyone can help me with writing the code please leave a reply. I have tried using ChatGPT to alter the code but it hasn’t had complete success. Leave a reply if you need me to answer and specific question.

---

<div class="post-metadata">

**Author:** ![Yaandle](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/yaandle/32/1942_2.png) [@Yaandle](https://discuss.roboflow.com/u/Yaandle)\
**Post date:** [May 17, 2023, 2:59am UTC](https://discuss.roboflow.com/t/creating-custom-object-detection-model/2190/2 "2023-05-17T02:59:22Z")

</div>

import os  
from flask import Flask, render\_template, request  
from roboflow import Roboflow

app = Flask( **name** )

# Set up Roboflow API

rf = Roboflow(api\_key=“2PEpCGO4fvFma7yeGpP0”)  
project = rf.workspace().project(“rider-number-finder”)  
model = project.version(2).model

# Function to perform object detection based on the user input

def perform\_object\_detection(number):  
# Get a list of all image files in the input\_images directory  
input\_images\_dir = os.path.join(“static”, “input\_images”)  
image\_files = [f for f in os.listdir(input\_images\_dir) if os.path.isfile(os.path.join(input\_images\_dir, f))]

```
# Perform object detection on each image and filter the results
filtered_images = []
for image_file in image_files:
    input_image_path = os.path.join(input_images_dir, image_file)
    predictions = model.predict(input_image_path, confidence=40, overlap=30)

    # Check if the desired number is present in the predictions
    for prediction in predictions:
        for obj in prediction["objects"]:
            if obj["class_name"] == "number" and obj["name"] == number:
                filtered_images.append(image_file)
                break # Found the number, no need to check further objects

# Save the filtered images to the predictions folder
output_images_dir = os.path.join("static", "predictions")
os.makedirs(output_images_dir, exist_ok=True)
for image_file in filtered_images:
    input_image_path = os.path.join(input_images_dir, image_file)
    output_image_path = os.path.join(output_images_dir, image_file)
    os.rename(input_image_path, output_image_path)

return filtered_images

```

@app.route(‘/’, methods=[‘GET’, ‘POST’])  
def home():  
if request.method == ‘POST’:  
number = request.form[‘number’]

```
    # Perform object detection and get the list of filtered images
    filtered_images = perform_object_detection(number)

    return render_template('result.html', images=filtered_images)

return render_template('index.html', css_file='styles.css')

```

if **name** == ‘ **main** ’:  
app.run()

---

<div class="post-metadata">

**Author:** ![Yaandle](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/yaandle/32/1942_2.png) [@Yaandle](https://discuss.roboflow.com/u/Yaandle)\
**Post date:** [May 17, 2023, 3:00am UTC](https://discuss.roboflow.com/t/creating-custom-object-detection-model/2190/3 "2023-05-17T03:00:06Z")

</div>

KeyError: ‘objects’

When I tell chatgpt the error it says to change it to ‘predictions’ then I get the error in reverse.
