CIHP_PGN
CIHP_PGN copied to clipboard
How to prepare datasets/CIHP/labels and datasets/CIHP/edges
Hello!
Can you explain please how to prepare files, which should be located in this directories: datasets/CIHP/labels and datasets/CIHP/edges
I've prepared the image file datasets/CIHP/images/image.jpg,
file datasets/CIHP/list/val_id.txt with content:
image
and file datasets/CIHP/list/val.txt with content:
images/image.jpg /labels/image.png
But I don't understand how I can generate datasets/CIHP/labels/image.png and datasets/CIHP/edges/image.png ?
Because I need them for test_pgn.py. You answered here that in this dir can be placed any png image. But if I just convert image.jpg to image.png and put converted file into labels and edges dir the execution of the test_pgn.py failed with error
InvalidArgumentError (see above for traceback): assertion failed: [`labels` out of bound] [Condition x < y did not hold element-wise:] [x (mean_iou/confusion_matrix/control_dependency:0) = ] [255 255 255...] [y (mean_iou/ToInt64_1:0) = ] [20]
Please explain how to prepare image files for starting the segmentation process? Because your README.md file doesn't explain how to do it. Just "Prepare the images and store in $HOME/datasets". But what steps need to be done to prepare images in datasets dir?
Inference
- Download the pre-trained model and store in $HOME/checkpoint.
- Prepare the images and store in $HOME/datasets.
- Run test_pgn.py.
- The results are saved in $HOME/output
- Evaluation scripts are in $HOME/evaluation. Copy the groundtruth files (in Instance_ids folder) - into $HOME/evaluation/Instance_part_val before you run the script.
Yes. You can refer to our example images. Or just download the edge images and change the name.
Yes. I refer to the example.
The input directory has the following structure:
./datasets/CIHP/list
./datasets/CIHP/list/val_id.txt
./datasets/CIHP/list/train.txt
./datasets/CIHP/list/val.txt
./datasets/CIHP/list/train_id.txt
./datasets/CIHP/list/train_rev.txt
./datasets/CIHP/labels
./datasets/CIHP/labels/0032190.png
./datasets/CIHP/images
./datasets/CIHP/images/0032190.jpg
./datasets/CIHP/edges
./datasets/CIHP/edges/0032190.png
This file ./datasets/CIHP/images/0032190.jpg - it is an target image file.
And as you can see this file ./datasets/CIHP/labels/0032190.png already partially segmented.
This file: ./datasets/CIHP/edges/0032190.png seems just dark image (but I'm not sure)
Can you tell me please. How I can automatically generate this file labels/0032190.png from initial target image file images/0032190.jpg? Because if I replace images/0032190.jpg with my own, the test script test_pgn.py doesn't want to work, beacuse label image file is wrong.
Please, explain me how I can automatically generate the labels input files for CIHP_PGN test script?
labels/*.png should have only one channel. Have a try?
If I create a grayscale png image from source image I receive this error anyway
tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [`labels` out of bound] [Condition x < y did not hold element-wise:] [x (mean_iou/confusion_matrix/control_dependency:0) = ] [252 252 252...] [y (mean_iou/ToInt64_1:0) = ] [20]
There is another image from your example:
Target image
And label image
I don't understand how to prepare an input data (labels and edges) for your project?
感觉作者的回复有些敷衍, 希望作者能把README写得更清楚点~
Your README file includes following instruction
Inference
- Download the pre-trained model and store in $HOME/checkpoint.
- Prepare the images and store in $HOME/datasets.
- Run test_pgn.py.
But how to prepare images for datasets??
@LogWell found a solution how to prepare DATASETS. You can use following files structure:
datasets/CIHP/images/0002190.png
datasets/CIHP/list/img_list.txt
datasets/CIHP/images/tool/logwell_script.m
datasets/CIHP/images/edges
datasets/CIHP/images/labels
where datasets/CIHP/images/0002190.png - it's a source image
datasets/CIHP/list/img_list.txt contain following data:
0002190.png
and datasets/CIHP/images/tool/logwell_script.m - it's a MATLAB script for prepare edges and labels:
clear;
close all;
fclose all;
%%
imglist = '../list/img_list.txt'; % 00000.png
list = textread(imglist, '%s');
for i = 1:length(list);
imname = list{i};
instance_map = imread(fullfile('../images', imname));
instance_contour = uint8(imgradient(rgb2gray(instance_map)) > 0);
imwrite(instance_contour, fullfile('../edges', imname));
imwrite(instance_contour, fullfile('../labels', imname));
end
Just run this script using command like:
/opt/MATLAB/R2018b/bin/matlab -nodisplay -nojvm -nosplash -nodesktop -r "try, run('tool/logwell_script.m'), catch, exit(1), end, exit(0);"
and after that you can run
python test_pgn.py
for get segmented images.
@rcrvano @LogWell Thank you for the your method. This method can get the result when testing the picture of CIHP, but can't get result on my own prepared data. Can you get the results directly?Just run python test_pgn.py and don‘t need to train on own dataset?
Yes. Right. Prepare datasets as described above and then just run test_pgn
ok.Thank you.I got the result. The reason why it has been unsuccessful is that the picture pixels are too large.
ok.Thank you.I got the result. The reason why it has been unsuccessful is that the picture pixels are too large.
I get the same error. Can you please let me know how did you fix pixel issue?
I think a lot of people got confused about this. I was confused too, initially.
You don't actually have to install MATLAB or Octave, create good edges
and labels
. That won't make the result better. The only reason it takes in edges and labels at all is to measure accuracy and precision.
I just wrote a method that doesn't require MATLAB or Octave, only the python
modules PGN already requires:
import numpy as np
import imageio as ii
from PIL import Image
nxb_img = Image.open('datasets/CIHP/images/front.jpg') # This is your image.
# Reshape their label image to our size
label_img = Image.open('datasets/CIHP/labels/0005008.png') # This is the label image from CIHP.
nxb_label_img = label_img.resize(nxb_img.size, Image.NEAREST)
nxb_label_img.save('datasets/CIHP/labels/front.png')
# Reshape their edge image to our size
edge_img = Image.open('/home/nathanbendich/CIHP_PGN/datasets/CIHP/edges/0005008.png')
nxb_edge_img = edge_img.resize(nxb_img.size, Image.NEAREST)
nxb_edge_img.save('datasets/CIHP/edges/front.png')
You can use Logwell's MATLAB code, but it won't improve performance.