Skip to content
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

Erro trying to finetune model to my dataset #5

Open
J-A-Varsha opened this issue Oct 16, 2024 · 0 comments
Open

Erro trying to finetune model to my dataset #5

J-A-Varsha opened this issue Oct 16, 2024 · 0 comments

Comments

@J-A-Varsha
Copy link

J-A-Varsha commented Oct 16, 2024

I have unlabelled images in my dataset. I forked this repo created a custom_dataset.py that extends base

import os
from PIL import Image
from .base import BaseDataset 

class Images(BaseDataset):
    def __init__(self, root, mode='train', transform=None, k_fold_eval=False, fold_idx=0):
        super().__init__(root, mode, transform, k_fold_eval, fold_idx)
        self.im_paths = []  
        
        # Scan directory for image files
        print(f"Looking for images in: {self.root}")
        for filename in os.listdir(self.root):
            img_path = os.path.join(self.root, filename)
            if os.path.isfile(img_path) and filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
                self.im_paths.append(img_path)

        print(f"Found {len(self.im_paths)} images in {self.root}.")  
        print(f"Sample image paths: {self.im_paths[:5]}")  
        self.ys = []  

    def __len__(self):
        return len(self.im_paths)  
    def __getitem__(self, index):
        im = self.img_load(index)  
        return im, index

    def img_load(self, index):
        im = Image.open(self.im_paths[index])
        if len(im.getbands()) == 1: 
            im = im.convert('RGB') 
        if self.transform is not None:
            im = self.transform(im)
        return im

How to solve this error?


content/drive/MyDrive/stml/code/net/inception.py:124: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  pretrained_dict = torch.load('./code/net/inception.pth')
=> teacher No Checkpoint !!!!!!!!!!!!!
=> student No Checkpoint !!!!!!!!!!!!!
Training parameters: {'LOG_DIR': './mylogs', 'DATA_DIR': '/content/drive/MyDrive', 'dataset': 'images', 'embedding_size': 512, 'bg_embedding_size': 1024, 'sz_batch': 16, 'nb_epochs': 10, 'gpu_id': 0, 'nb_workers': 2, 'model': 'googlenet', 'optimizer': 'adamp', 'lr': 0.0001, 'emb_lr': 0.0001, 'fix_lr': False, 'weight_decay': 0.01, 'num_neighbors': 5, 'bn_freeze': 0, 'student_norm': 0, 'teacher_norm': 1, 'save': True, 'resume': '', 'view': 2, 'delta': 1.0, 'sigma': 3.0, 'momentum': 0.999, 'pretrained': True, 'swav': False, 'remark': '', 'seed': None}
Training for 10 epochs.
100% 1/1 [00:02<00:00,  2.24s/it]
Traceback (most recent call last):
  File "/content/drive/MyDrive/stml/code/main.py", line 284, in <module>
    balanced_sampler = sampler.NNBatchSampler(trn_dataset, model_student, dl_sampling, args.sz_batch, args.num_neighbors, True)
  File "/content/drive/MyDrive/stml/code/dataset/sampler.py", line 63, in __init__
    self.nn_matrix, self.dist_matrix = self._build_nn_matrix(model, seen_dataloader)
  File "/content/drive/MyDrive/stml/code/dataset/sampler.py", line 103, in _build_nn_matrix
    X, T, _ = self._predict_batchwise(model, seen_dataloader)
ValueError: not enough values to unpack (expected 3, got 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant