-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Different predict result from preview and my app for same image #683
Comments
@ilanb hi there! 🙌 It sounds like you're experiencing inconsistencies in detection results between the Ultralytics preview and your custom Python application. A possible reason for this could be differences in preprocessing or configuration settings applied to the model before running predictions. Since you’ve experimented with some parameters already, you might want to verify the following:
Additionally, please ensure that you are using the same model version and weights in both your custom app and the preview for a fair comparison. For specific instructions on setting and matching configuration, please refer to the Ultralytics HUB Docs at https://docs.ultralytics.com/hub. Hope this helps! If the issue persists, please provide more details about your image preprocessing steps and model setup in both environments for further diagnosis. 😊 |
Thanks for reply :-) What do you mean by " this could be differences in preprocessing " I only upload image from postman or html like your preview in utltralytics hub. what "Image preprocessing" do you apply in preview ? For the parameters I already tested both with and without. Image used is the same image to serve as training, valid, test here is my simple app: `from ultralytics import YOLO app = Flask(name) YOLO modelyolo_model = None @app.route("/") @app.route("/detect", methods=["POST"]) @app.route("/detecthtml", methods=["POST"]) def detect_objects_on_image(buf):
def detect_objects_on_image_html(buf, confidence_threshold=0.2):
if name == 'main': Thanks |
Hi @ilanb, thanks for providing more details! 😊 When I mention "image preprocessing," I'm referring to how the image is prepared before it's input into the model. This includes resizing, normalization, and possibly other transformations to ensure the image is in the correct format for the model to process. In the Ultralytics preview, images are typically resized and normalized to match the input expectations of the model. It's crucial to ensure that the same preprocessing steps are applied in your app as well. From your code, it looks like you're directly using from PIL import Image
def prepare_image(image_path):
img = Image.open(image_path)
img = img.resize((640, 640)) # Resize the image to the expected input size
return img
# Then use this function to prepare your image before prediction
img = prepare_image(buf)
results = yolo_model.predict(img, iou=0.45, imgsz=640, max_det=1, device="cpu", augment=True, agnostic_nms=True) Make sure that the image size ( Let me know if aligning these preprocessing steps helps or if there's anything else you'd like to explore! 🚀 |
Thank you, I tried to simplify to results = yolo_model.predict(img) but same. with same image, detection working on your preview but failed with my code... `from ultralytics import YOLO app = Flask(name) @app.route("/") @app.route("/detect", methods=["POST"]) @app.route("/detecthtml", methods=["POST"]) def prepare_image(image_path): def detect_objects_on_image(buf):
def detect_objects_on_image_html(buf, confidence_threshold=0.2):
if name == 'main': |
The strange behaviour that is when I try .onnx exported model in unity sentis c# all images are correctly detected too.. Didn't understant what cause the problem with python and .pt model `using System.Collections.Generic; public class RunYOLO8n : MonoBehaviour
} |
Hi @ilanb, It's intriguing that the .onnx model works well in Unity with Sentis but not the .pt model in Python. This could suggest a difference in how the models handle the input data or in the post-processing steps. Here are a couple of things to consider:
If you haven't already, you might also want to try running inference with a very simple setup in Python to rule out any issues with Flask or image handling: from ultralytics import YOLO
from PIL import Image
# Load model
model = YOLO("path_to_your_model.pt")
# Load image
img = Image.open("path_to_your_image.jpg")
img = img.resize((640, 640))
# Predict
results = model.predict(img)
print(results) This minimal example can help isolate the problem by removing potential complications from web server code or image streaming. Let me know how it goes! 🚀 |
Search before asking
Question
Hi, I use PyTorch model in custom python app and I'v for same images no detection with model and good detection (0;95%) in preview (ultralytics)
I use :
results = yolo_model.predict(Image.open(buf), iou=0.45, imgsz=640, max_det=1, device="cpu", augment=True, agnostic_nms=True)
I tried too :
results = yolo_model.predict(Image.open(buf))
This is not happen for every class (I have 50 class) detection work fine in my app
Thanks for help
Additional
No response
The text was updated successfully, but these errors were encountered: