-
Notifications
You must be signed in to change notification settings - Fork 61
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
Test errors on own dataset #569
Comments
Why are the results different after two consecutive runs? It was right the first time. The second time I ran it by saving features_galleries, the result was ridiculously wrong. |
@snow-wind-001 Hi! Could you please reformat the code so it's easier to read? |
I reformat the code@AlekseySh |
Hey, @snow-wind-001 Once again. The problem is that The script looks okay for me:
Do you have the problem when you don't cache features? It's hard to debug from my place, but you need to find the exact moment when you have differences between two runs. Are models the same? Are datasets the same and not shuffled after reloading? Are features the same? PS. You don't need to reimplement ViTExtractor to be able to load weights from the disk. You can just provide path to your weights as |
@AlekseySh |
import torch
import pandas as pd
import random
from pathlib import Path
from torch.utils.data import DataLoader
from typing import Union, Optional
from pprint import pprint
from oml.const import PATHS_COLUMN
from oml.datasets.base import DatasetQueryGallery
from oml.inference.flat import inference_on_dataframe, inference_on_images
from oml.inference.pairs import pairwise_inference_on_images
from oml.models import ConcatSiamese, ViTExtractor
from oml.registry.transforms import get_transforms_for_pretrained
from oml.retrieval.postprocessors.pairwise import PairwiseImagesPostprocessor
from oml.utils.misc_torch import pairwise_dist
from oml.utils.io import download_checkpoint_one_of
from NumpyImageDataset import *
from pathlib import Path
from PIL import Image # 正确导入 Image
import os
def print_dataset_paths(dataset):
for i in range(len(dataset)):
data = dataset[i]
print(f"Index {i}: Path {data['path']}")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
checkpoints_path = './best.ckpt'
model = ViTExtractor(weights=checkpoints_path, arch='vits16', normalise_features =True)
transform, _ = get_transforms_for_pretrained("vits16_dino")
from oml.transforms.images.torchvision import get_normalisation_resize_torch
transform = get_normalisation_resize_torch(im_size=224, mean=[0.40590053,0.40100682,0.35496407], std=[0.20830545,0.18484329,0.19726294])
#读取不同文件夹的图片,组成query和gallery
image_is_query_path = Path('/home/snowolf/dataset/bottle_test/is_query/1')
image_is_gallery_path = Path('/home/snowolf/dataset/bottle_test/is_gallery/1')
query_path = []
gallery_path = []
for img_file in image_is_query_path.glob('*.jpg'): # 假设图像文件是.jpg格式
query_path.append(img_file)
for img_file in image_is_gallery_path.glob('*.jpg'): # 假设图像文件是.jpg格式
gallery_path.append(img_file)
print("Image paths from folder 1:")
print(query_path)
print("\nImage paths from folder 2:")
print(gallery_path)
num_workers = 4
batch_size = 16
verbose = True
output_tensor = pairwise_inference_on_images(
model=model,
paths1=query_path,
paths2=gallery_path,
transform=transform,
num_workers=num_workers,
batch_size=batch_size,
verbose=verbose
)
print(output_tensor)
ii_closest = torch.argmin(output_tensor, dim=1)
print(ii_closest) ### I tried your method but reality lacks predict method. |
I try to use OML to perform image recognition on objects such as bottles. I input the test image and the standard image of a known category into OML, and ultimately hope to achieve good recognition results. I hope you can give us a demo to facilitate our implementation of this application. |
wait a second, why do you use What do you mean by recognition results? What exactly do you do? |
We have encountered such a need to identify beverage bottles. Originally there were 172 types of bottles, which may be expanded to more than 600 types in the future. Currently we use vit to implement a bottle classification model. Although the effect is good, the training cost for subsequent addition of new categories is very high, so we hope to use the OML project to implement this function. My plan is to set the views of all bottles in four directions as gallery, and through training, let the network judge the distance between the input image and the gallery image to achieve classification, and in the future, a small amount of training will be required to change the gallery at the same time. Data sets to achieve algorithm scalability. I saw this example of PyTorch Metric Learning with our Pipelines just follow the standard tutorial of adding custom loss. But there is no val code for sorting the input image output by correlation with the gallery image. I don’t know if my idea is correct, and can I provide an idea for calling the OML algorithm. |
@snow-wind-001 As far as I understood your task -- yes, it's a metric learning problem suitable for OML. There is validation, you probably missed an example. If you saw this validation but found it not convenient to analyze your outputs you can try reworked validation that will be published soon with OML 3.0. If you don' want to wait, just jump into |
hey @snow-wind-001 We've just released OML 3.0 where we made work with retrieved items more transparent and simple. Take a look at the examples: https://github.com/OML-Team/open-metric-learning?tab=readme-ov-file#examples. I hope your problem will be automatically solved. |
The text was updated successfully, but these errors were encountered: