Code Monkey home page Code Monkey logo

pretrained-backbones-unet's Introduction

Hi there, I'm Berkay ๐Ÿ‘‹

About me ๐Ÿ”ญ

  • ๐Ÿ–ฅ I'm a full-stack ML & DL developer
  • ๐ŸŽ“ I'm an Electrical and Electronics Engineer
  • ๐Ÿ’ป I love data science and deep learning
  • ๐ŸŒฑ Iโ€™m currently learning everything about AI ๐Ÿค”
  • ๐Ÿ‘ฏ Iโ€™m looking to collaborate with other content creators
  • โšก Fun fact: I love to programming
  • ๐ŸŒ You can access all my open-source projects in this profile

Connect with me:

clothessegmentation

Languages and Tools:

c cplusplus java python django javascript html5 css3 sass git


๐Ÿ”” My Recent GitHub Activity


โšก Github Stats

ย mberkay0 mberkay0

๐Ÿ’ช Maybe you want to star my projects

mberkay0

mberkay0

pretrained-backbones-unet's People

Contributors

mberkay0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pretrained-backbones-unet's Issues

'DataLoader' is not defined

Hi, when I am trying to start the training I am getting the following error:

NameError                                 Traceback (most recent call last)
/tmp/ipykernel_21140/3294596851.py in <module>
     14 val_dataset = SemanticSegmentationDataset(val_img_path, val_mask_path)
     15 
---> 16 train_loader = DataLoader(train_dataset, batch_size=2)
     17 val_loader = DataLoader(val_dataset, batch_size=2)
     18 

NameError: name 'DataLoader' is not defined

Do you have any suggestions to how to solve it?

Thanks!

Training loss is not decreasing

Hello, I am using Unet decoder and HRNet encoder model but i realize that the training loss is not decreasing, instead it seems to remain the same. Also the training logs appear in separate lines which is a problem becuase 1 epoch take around 200 lines and not gets output in one line.
Screenshot from 2023-06-16 19-27-31

I have trained it for 10 epochs but the loss keeps jumping between 0.99 and 1

Missing argument error in trainer.py when setting lr_scheduler

In trainer.py (line 101) there is a missing argument. Here's how I define optimiser and lr_scheduler in train.py:

optimizer = torch.optim.Adam(params, lr=0.001, weight_decay=0.0001)
scheduler = lr_scheduler.ReduceLROnPlateau(optimizer, factor=0.1, patience=6, verbose=1, min_lr=0.000001)
trainer = Trainer(
    model,
    criterion=BCEDiceLoss(),
    optimizer=optimizer,
    lr_scheduler=scheduler,   
    epochs=500
)

That throws the following error:

File "/home/seg/backbones_unet/utils/trainer.py", line 127, in _train_one_epoch
    self.lr_scheduler.step() # this was originally: self.lr_scheduler.step()
TypeError: step() missing 1 required positional argument: 'metrics'

If I then set line 101 to self.lr_scheduler.step(loss) that seems to fix the error. However, when I start training I get this:

Training Model on 500 epochs:   0%|                            | 0/500 [00:00<?, ?it/s
Epoch 00032: reducing learning rate of group 0 to 1.0000e-04.  | 31/800 [00:03<00:54, 14.03 training-batch/s, loss=1.1]
Epoch 00054: reducing learning rate of group 0 to 1.0000e-05.  | 53/800 [00:04<00:51, 14.38 training-batch/s, loss=1.09]
Epoch 00062: reducing learning rate of group 0 to 1.0000e-06.  | 61/800 [00:05<00:54, 13.45 training-batch/s, loss=1.06]
^Epoch 1:  13%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ                              | 104/800 [00:08<00:58, 11.84 training-batch/s, loss=1.05]

I haven't seen that before when training models with code from other repos. If that is normal, then all is OK, I just wanted to report the missing argument error in trainer.py.

Model saving functionality missing

Thanks for creating this library, I was trying to implement the same, coz segmentation models pytorch library doesn't really provide the convnext as encoder.

I hope you implement the saving functionality soon..

Thank you.

Unable to train on small patches (64x48)

I am trying to train using the efficientnet_b0 backbone using an image size of 64x48, but get the following error:

  File "/home/seg/bbunet/train.py", line 85, in <module>
    trainer.fit(train_loader, val_loader)
  File "/home/seg/bbunet/backbones_unet/utils/trainer.py", line 82, in fit
    self._train_one_epoch(train_loader, epoch)
  File "/home/seg/bbunet/backbones_unet/utils/trainer.py", line 111, in _train_one_epoch
    preds = self.model(images)
  File "/home/miniconda3/envs/pt/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/seg/bbunet/backbones_unet/model/unet.py", line 174, in forward
    x = self.decoder(x)
  File "/home/miniconda3/envs/pt/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/seg/bbunet/backbones_unet/model/unet.py", line 334, in forward
    x = b(x, skip)
  File "/home/miniconda3/envs/pt/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/seg/bbunet/backbones_unet/model/unet.py", line 276, in forward
    x = torch.cat([x, skip], dim=1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 4 but got size 3 for tensor number 1 in the list.

I tried with and without pretrained model but got the same error each time.

Dimension issues with predict method

Hello,

I am trying to use your framework to perform mask extraction on images I have with the following code :

import os

import torchvision.transforms as transforms
from backbones_unet.model.unet import Unet
from PIL import Image

PATH="path_to_folder" # Replaced for confidentiality reasons 
CELLS_PATH = PATH + "cells/"

# Model init
model = Unet(backbone='xception71', in_channels=3, num_classes=1)
transform = transforms.Compose([transforms.ToTensor()])

# Data processing
for filename in os.listdir(CELLS_PATH):
    image = Image.open(CELLS_PATH + filename)
    tensor = transform(image).unsqueeze(0)
    print(tensor.shape)
    mask = model.predict(tensor)
    print(mask)

For the moment I just print masks to check what they look like before saving them. But I get the following error when trying to run the code :

Traceback (most recent call last):
File "hidden/mask.py", line 19, in
mask = model.predict(tensor)
File "env/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "env/lib/python3.10/site-packages/backbones_unet/model/unet.py", line 160, in predict
x = self.forward(x)
File "env/lib/python3.10/site-packages/backbones_unet/model/unet.py", line 142, in forward
x = self.decoder(x)
File "env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "env/lib/python3.10/site-packages/backbones_unet/model/unet.py", line 304, in forward
x = b(x, skip)
File "env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "env/lib/python3.10/site-packages/backbones_unet/model/unet.py", line 246, in forward
x = torch.cat([x, skip], dim=1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 14 but got size 13 for tensor number 1 in the list.

And when printing dimensions of my input tensor as well as x and skip which are concatenated, I get in the same order :

torch.Size([1, 3, 207, 204])
torch.Size([1, 2048, 14, 14])
torch.Size([1, 1024, 13, 13])

Would you know where this come from / how to fix it ?

Test script?

Do you have a working test script for these models? I just need to get prediction masks from a test set, I don't need metrics.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.