Giter VIP home page Giter VIP logo

Comments (21)

CVUsers avatar CVUsers commented on July 20, 2024 1

你运行哪个py报这个错

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024 1

Did you get the mail?

from hed-unet.

khdlr avatar khdlr commented on July 20, 2024

Hey mate, a quick google search for "semantic segmentation data loader" should prove insightful on how to implement a data loader for your use case. You can use any custom dataloader with the code.

The speed of the network depends greatly on your usecase (image resolution, etc.), but in our tests we found it to be ~30% slower than a regular UNet.

Cheers,
Konrad

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

I am assuming there is a folder which contains sub-folders image and mask. The filenames are same. This is a template you can modify it and use. All the best.
import torch.utils.data as data

class DataLoaderSegmentation(data.Dataset):
def init(self, folder_path):
super(DataLoaderSegmentation, self).init()
self.img_files = glob.glob(os.path.join(folder_path,'image','*.png')
self.mask_files = []
for img_path in img_files:
self.mask_files.append(os.path.join(folder_path,'mask',os.path.basename(img_path))

def __getitem__(self, index):
        img_path = self.img_files[index]
        mask_path = self.mask_files[index]
        data = use opencv or pil read image using img_path
        label =use opencv or pil read label  using mask_path
        return torch.from_numpy(data).float(), torch.from_numpy(label).float()

def __len__(self):
    return len(self.img_files)

Can I use this method to replace your data reading part? You use NPY,

from hed-unet.

khdlr avatar khdlr commented on July 20, 2024

Yes, that looks like it should work.

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

Hi, I trained with my data. The picture is 256 wide and high for 3 channels, and GT is 256 wide and high for 1 channel. My mask has only the edge (only the edge is white, and other places are black). I trained thousands of pieces several times. The loss is about - 1000, and the ACC is about 60. The effect is very poor, but your training is very good. There should be no problem in the data reading part. Ask for advice

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

I train several pieces of data similar to yours (not TIF). GT is also white to fill the target area, and loss is also negative. The effect is very poor

from hed-unet.

khdlr avatar khdlr commented on July 20, 2024

Well the code assumes that your input is a segmentation mask and not an edge mask. If you want to train directly on edge masks, you will need to change the code.

The loss will only be negative if your input mask has invalid values (either negative ones or ones that are greater than 1), so it might be a good idea to check that (i.e. by calling print(target.min(), target.max()) before line 137 in train.py.

My guess would be that in your data loading code you're reading the white values as 255. Building on the code you posted above, it should help to change the last line like this:

def __getitem__(self, index):
    img_path = self.img_files[index]
    mask_path = self.mask_files[index]
    data = use opencv or pil read image using img_path
    label =use opencv or pil read label  using mask_path

    return torch.from_numpy(data).float() / 255, torch.from_numpy(label > 0).float()

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

print(target.min(), target.max()) :::: tensor(0.) tensor(255.);
use your code: tensor(0.) tensor(1.)
I' m training,thanks
How many milliseconds does it take to infer a 256 size image?

from hed-unet.

wxm123wxm avatar wxm123wxm commented on July 20, 2024

How to solve this problem “ No module named 'attr' ”

from hed-unet.

khdlr avatar khdlr commented on July 20, 2024

print(target.min(), target.max()) :::: tensor(0.) tensor(255.);

Yep, that was the issue. Glad that's fixed now :)

Re inference time: For batched inference (on a NVidia V100), we measured inference times of 3.3 ms for the HED-UNet model on tiles of size 256x256 as opposed to 2.8 ms for a plain UNet. But this will depend a lot on data loading, pre-processing and other stuff of course.

from hed-unet.

wxm123wxm avatar wxm123wxm commented on July 20, 2024

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

from hed-unet.

khdlr avatar khdlr commented on July 20, 2024

The term attr isn't used in this package at all, so the error is likely due to some broken dependencies. Can you try with a new virtualenv / conda environment?

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

Hello, my training data is a white mask on the edge (only the edge). The training effect is good. I wrote a detect code myself to infer the graph of 256256,3, edge_ PRED is correct, but SEG_ PRED is all black, which is a little strange (although my work is document edge extraction + correction). Let me show you my code: in addition, do I need to turn my GT diagram (only one circle of white on the edge) into a mask with all white inside the edge? Will this improve the accuracy?

dict = torch.load(r'D:\cver\Cls\Auto_Classification\hed_unet\HED-UNet\logs\2022-03-30_10-48-08\checkpoints/10.pt', map_location="cpu")
model.load_state_dict(dict)
idx = 0
img = cv2.imread(r'E:\IMG_1546.jpg')
# img = DataLoader(img,1)

# print(img.size())
img = cv2.resize(img, (256, 256))
cv2.imshow('demo_ori', img)
img = np.transpose(img, (2, 0, 1))  # [3,224,224]
img = torch.from_numpy(img).float() / 255
img = img.unsqueeze(0)
img = img.to(dev)
time1 = time.time()
y_hat, y_hat_levels = model(img)
# print('model inference time: ', time.time()-time1)
seg_pred = torch.argmax(y_hat[:, 1:], dim=1)
edge_pred = (y_hat[:, 0] > 0).float()
# print(seg_pred)
# print(edge_pred)

# seg_pred_image = seg_pred.mul(255).byte() # 取值范围
seg_pred_image = seg_pred.cpu().numpy().transpose((1, 2, 0)) # 改变数据大小
seg_pred_image = np.array(seg_pred_image, dtype=np.uint8)
edge_pred_image = edge_pred.cpu().numpy().transpose((1, 2, 0)) # 改变数据大小

print('Total time: ', time.time()-time1)

cv2.imshow('demo1', seg_pred_image)
# edge_pred_image = edge_pred.mul(255).byte() # 取值范围
cv2.imshow('demo2', edge_pred_image)
cv2.waitKey(0)

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

Hi training on CUDA device, pytorch1 7.1 GPU version, but the video memory only occupies 227mb. It's strange that the code hasn't been moved. Model To () is correct,

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

Hello, I have a full screen target. After generating the mask, it is all white. Go to training. The data of other shapes are good. All white data can not be recognized even if it is a training set;

The segmentation rate of each edge changes gradually, but the segmentation rate of epoch changes gradually.

Finally, the edges of our mask, GT and PRED are jagged, but looking at the data, the jagged mask is not serious. I'll send you a picture later

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

from hed-unet.

khdlr avatar khdlr commented on July 20, 2024

Hello, I have a full screen target. After generating the mask, it is all white. Go to training. The data of other shapes are good. All white data can not be recognized even if it is a training set;

An white mask will have no edges, so the edge-head becomes useless in that setup I would say.

The segmentation rate of each edge changes gradually, but the segmentation rate of epoch changes gradually.

Not sure what you mean by that.

Finally, the edges of our mask, GT and PRED are jagged, but looking at the data, the jagged mask is not serious. I'll send you a picture later

I didn't receive any picture, feel free to contact me at  image

from hed-unet.

wxm123wxm avatar wxm123wxm commented on July 20, 2024

from hed-unet.

CVUsers avatar CVUsers commented on July 20, 2024

How to make the edge branch be learned when it is around the edge of the image

from hed-unet.

Related Issues (18)

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.