Comments (21)
你运行哪个py报这个错
from hed-unet.
Did you get the mail?
from hed-unet.
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.
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.
Yes, that looks like it should work.
from hed-unet.
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.
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.
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.
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.
How to solve this problem “ No module named 'attr' ”
from hed-unet.
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.
from hed-unet.
from hed-unet.
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.
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.
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.
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.
from hed-unet.
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
from hed-unet.
from hed-unet.
How to make the edge branch be learned when it is around the edge of the image
from hed-unet.
Related Issues (18)
- How could I get the complete images on result HOT 1
- Training steps HOT 4
- Is the image input during the training process the original image and the binary image? HOT 17
- Testing data HOT 7
- Whether this program can handle .png files. If you can’t handle it, can you convert the .tif file to a .png file? HOT 1
- AttributeError: 'Array' object has no attribute 'numpy' HOT 1
- RuntimeError: Given groups=1, weight of size [16, 3, 1, 1], expected input[8, 4, 256, 256] to have 3 channels, but got 4 channels instead HOT 10
- Hello, my training is successful, then I would like to ask how to test my own data? HOT 1
- About Loss HOT 5
- About mutil classes HOT 19
- Hed HOT 7
- Weight Map HOT 2
- I have some questions about testing. HOT 6
- About the differences between predictions and queries. HOT 3
- Does the edge detection task have an impact on the semantic segmentation task in this model? HOT 1
- Can you please share the pre-trained weights for interence HOT 1
- Can the author provide code for prediction
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hed-unet.