You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the Yolo Tracking issues and found no similar bug report.
Question
Thank you so much for your work. I have two questions.
Question 1
I trained a ReID model with torchreid and it gives me a .pth file. I notices for StrongSORT repo, it's always a .pt file. Would I be able to just use the .pth file that my code below generates? It is especially important for my case as I am tracking non-human/non-vehicle objects.
import os
import torch
import string
import random
import argparse
import torchreid
from glob import glob
import os.path as osp
class NewDataset(torchreid.data.datasets.ImageDataset):
dataset_dir = ''
def __init__(self, root='', **kwargs):
self.train_dir = self.dataset_dir
self.query_dir = self.dataset_dir
self.gallery_dir = self.dataset_dir
train = self.process_dir(self.train_dir, isQuery=False)
query = self.process_dir(self.query_dir, isQuery=True)
gallery = self.process_dir(self.gallery_dir, isQuery=False)
super(NewDataset, self).__init__(train, query, gallery, **kwargs)
def process_dir(self, dir_path, isQuery, relabel=True):
img_paths = glob(osp.join(dir_path, '*.jpg'))
pid_container = set()
for img_path in img_paths:
img_name = img_path.split('/')[-1]
name_splitted = img_name.split('_')
pid = int(name_splitted[1][1:])
pid_container.add(pid)
pid2label = {pid: label for label, pid in enumerate(pid_container)}
data = []
for img_path in img_paths:
img_name = img_path.split('/')[-1]
name_splitted = img_name.split('_')
pid = int(name_splitted[1][1:])
camid = int(name_splitted[0][1:])
if isQuery:
camid += 10 # index starts from 0
if relabel:
pid = pid2label[pid]
data.append((img_path, pid, camid))
return data
def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument('--name', type=str, default='osnet_x1_0', help="ReID model name")
parser.add_argument('--img_h', type=int, default=256, help="image height")
parser.add_argument('--img_w', type=int, default=128, help="image width")
parser.add_argument('--bs', type=int, default=32, help="batch size")
parser.add_argument('--optim', type=str, default='adam', help="optimizer")
parser.add_argument('--lr', type=float, default=0.003, help="learning rate")
parser.add_argument('--lr_sch', type=str, default="single_step", help="learning rate scheduler")
parser.add_argument('--step', type=int, default=5, help="learning rate scheduler's step size")
parser.add_argument('--epochs', type=int, default=20, help="epoch count for the training loop")
parser.add_argument('--eval_freq', type=int, default=5, help="evaluation frequency")
parser.add_argument('--data_path', type=str, default='path/to/data', help="path to the custom dataset")
parser.add_argument('--save_path', type=str, default='path/to/save', help="path to save the model")
args = parser.parse_args()
return args
def main(args):
device = 'cuda' if torch.cuda.is_available() else 'cpu'
NewDataset.dataset_dir = args.data_path
dataset_name = ''.join(random.choices(string.ascii_uppercase + string.digits, k=random.randint(1, 25)))
torchreid.data.register_image_dataset(dataset_name, NewDataset)
datamanager = torchreid.data.ImageDataManager(
sources=dataset_name,
height=args.img_h,
width=args.img_w,
batch_size_train=args.bs,
batch_size_test=100,
transforms=["random_flip", "random_crop"]
)
model = torchreid.models.build_model(
name=args.name,
num_classes=datamanager.num_train_pids,
loss="triplet",
pretrained=True
).to(device).train()
optimizer = torchreid.optim.build_optimizer(
model,
optim=args.optim,
lr=args.lr,
)
scheduler = torchreid.optim.build_lr_scheduler(
optimizer,
lr_scheduler=args.lr_sch,
stepsize=args.step,
)
engine = torchreid.engine.ImageTripletEngine(
datamanager,
model,
optimizer=optimizer,
scheduler=scheduler,
margin=0.3, # by default 0.3
weight_t=1, # weight for triplet loss
weight_x=50, # weight for softmax loss
)
engine.run(
save_dir=f"log/{args.name}",
max_epoch=args.epochs,
eval_freq=args.eval_freq,
print_freq=50,
test_only=False
)
# Save the trained model
model_save_path = os.path.join(args.save_path, f"{args.name}_model.pth")
torch.save(model.state_dict(), model_save_path)
print(f"Trained model saved at: {model_save_path}")
if __name__ == '__main__':
args = get_parser()
main(args)
Question 2
I used the built in tracker in YOLOv8 and the performance was much better. I used a custom weight for my unique class and it worked a lot better than when I used this repo.
👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.
Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!
Search before asking
Question
Thank you so much for your work. I have two questions.
Question 1
I trained a ReID model with torchreid and it gives me a .pth file. I notices for StrongSORT repo, it's always a .pt file. Would I be able to just use the .pth file that my code below generates? It is especially important for my case as I am tracking non-human/non-vehicle objects.
Question 2
I used the built in tracker in YOLOv8 and the performance was much better. I used a custom weight for my unique class and it worked a lot better than when I used this repo.
Better performance when using the following code,
The detections when I use Boxmot look very poor comparatively, making me wonder if the weight loaded properly. What would you advise?
Thank you so much for your time!
The text was updated successfully, but these errors were encountered: