Can you share documentation for using torch hub?
Hi @FateScript ,
I wrote the model loading code, but can you share the documentation so I can write the prediction code?
Example Yolov5: https://docs.ultralytics.com/tutorials/pytorch-hub/
import cv2
import torch
from PIL import Image
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
# Images
for f in ['zidane.jpg', 'bus.jpg']:
torch.hub.download_url_to_file('https://ultralytics.com/images/' + f, f) # download 2 images
img1 = Image.open('zidane.jpg') # PIL image
img2 = cv2.imread('bus.jpg')[:, :, ::-1] # OpenCV image (BGR to RGB)
imgs = [img1, img2] # batch of images
# Inference
results = model(imgs, size=640) # includes NMS
# Results
results.print()
results.save() # or .show()
results.xyxy[0] # img1 predictions (tensor)
results.pandas().xyxy[0] # img1 predictions (pandas)
# xmin ymin xmax ymax confidence class name
# 0 749.50 43.50 1148.0 704.5 0.874023 0 person
# 1 433.50 433.50 517.5 714.5 0.687988 27 tie
# 2 114.75 195.75 1095.0 708.0 0.624512 0 person
# 3 986.00 304.00 1028.0 420.0 0.286865 27 tie
I need this to integrate the yolox model into the SAHI library.
Hi @FateScript ,
Does yolox not support the torch_hub library?
Hi @FateScript ,
Does yolox not support the torch_hub library?
It should support such feature. Any issue raised? Could you please paste your error log?
Hi @FateScript ,
I need the source code so I can write prediction code. I can't see code in hubconf.py file. Codes of other yolo models:
My Code: It gives an error on line 4.
model = torch.hub.load("Megvii-BaseDetection/YOLOX", "yolox_s")
image = torch.from_numpy(cv2.imread('data/highway1.jpg'))
image = image.permute(2, 0, 1).unsqueeze(0).float()
prediction = model(image)
Error Message:
File ".../.cache\torch\hub\Megvii-BaseDetection_YOLOX_main\yolox\models\yolox.py", line 33, in forward
assert targets is not None
AssertionError
How can I write these codes without source code or documentation? What should I do to use the device parameter? Can you help with this?
assert targets is not None
Plz add the following code.
model.eval()
Thank you. After applying postprocces I get 'None'. How can I fix? Code:
import torch
import cv2
from yolox.utils import postprocess
model = torch.hub.load("Megvii-BaseDetection/YOLOX", "yolox_s")
image = torch.from_numpy(cv2.imread('data/highway1.jpg'))
image = image.permute(2, 0, 1).unsqueeze(0).float()
prediction = model.eval()(image)
outputs = postprocess(prediction, num_classes=80, conf_thre=0.7, nms_thre=0.45, class_agnostic=False)
print(outputs)
Output:
None
How can I fix?
Not sure what's in your picture. From code your posted, I believe that you might need to cv2.resize image to size 640(this value is provided in README) before using network to predict. I also notice that you are using high conf_threshold 0.7, if you really want to filter conf value greater than 0.7, you might need to use value 0.7**2 = 0.49 here.
code to refer: https://github.com/Megvii-BaseDetection/YOLOX/blob/main/tools/demo.py#L133-L184
How can I fix?
Not sure what's in your picture. From code your posted, I believe that you might need to
cv2.resizeimage to size 640(this value is provided in README) before using network to predict. I also notice that you are using highconf_threshold0.7, if you really want to filter conf value greater than 0.7, you might need to use value0.7**2 = 0.49here.code to refer: https://github.com/Megvii-BaseDetection/YOLOX/blob/main/tools/demo.py#L133-L184
Thank you. I ran the yolox model using the hub library. I want to change the image_size value. https://github.com/Megvii-BaseDetection/YOLOX/blob/main/yolox/models/build.py#L60
exp.input_size= input_size
Can we add this? I would like to open a PR if you agree to this change.
In my opinion, pre-trained yolox should resize image to 640 to maintain the consistency of training process and eval process. I'm not sure what the true purpose of changing it. @kadirnar
For satellite images, the img_size value must be large. That's why I wanted to give a manual value. Image
I changed the image_size parameter using the preproc function. Thank you for the repo. I forced it while coding pip and torch.hub. It will be much more comfortable if you write documentation for them.