CIHP_PGN icon indicating copy to clipboard operation
CIHP_PGN copied to clipboard

@LogWell found a solution how to prepare DATASETS. You can use following files structure:

Open lemon1220 opened this issue 4 years ago • 21 comments

@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.

Originally posted by @rcrvano in https://github.com/Engineering-Course/CIHP_PGN/issues/26#issuecomment-496198813

lemon1220 avatar Sep 04 '19 03:09 lemon1220

hi friends. Do you know HOW can I run this script under windows matlab? I didnot have matlab on ubuntu.

lemon1220 avatar Sep 04 '19 03:09 lemon1220

excuse me. who can tell me how run the following code? `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`

lemon1220 avatar Sep 05 '19 13:09 lemon1220

can you tell me a python equivalent of the above code logwell_script.m . I dont have matlab license with me. Thanks in advance.

mukundhan3 avatar Oct 01 '19 07:10 mukundhan3

I'm sorry, I don't use it on Windows, but the code should be almost the same @lemon1220

I don't know how to implement it, just use it @mukundhan3

The author may not be able to receive information, or ask friends around you.

LogWell avatar Oct 03 '19 00:10 LogWell

I write a python script to prepare the data, maybe you want to try it https://gist.github.com/qzane/4d07b7551914f97f2bf8b9c79138ab14

qzane avatar Oct 24 '19 06:10 qzane

I write a python script to prepare the data, maybe you want to try it https://gist.github.com/qzane/4d07b7551914f97f2bf8b9c79138ab14

@qzane Can you explain how to run this script? an example command to run? I tried but failed. I am trying like this python datasets/CIHP/images CIHP but can't run.

MuhammadAsadJaved avatar Dec 03 '19 02:12 MuhammadAsadJaved

I write a python script to prepare the data, maybe you want to try it https://gist.github.com/qzane/4d07b7551914f97f2bf8b9c79138ab14

@qzane Can you explain how to run this script? an example command to run? I tried but failed. I am trying like this python datasets/CIHP/images CIHP but can't run.

@MuhammadAsadJaved try python make_dataset.py datasets/CIHP/images CIHP2 if you use the same name the image may be override (you should first check the images folder, maybe they have already been removed).

qzane avatar Dec 03 '19 02:12 qzane

@qzane Yes sir you are right. CIHP2 generates 3 folders edges, images and list. Do I only need this information for generate segmented image? Note: The edges folder contains only empty black images.

MuhammadAsadJaved avatar Dec 03 '19 03:12 MuhammadAsadJaved

Yes, edges are for evaluation only which you don't need but has to be there

qzane avatar Dec 03 '19 03:12 qzane

@qzane Thank you very much sir. So nice of you. Stay blessed.

MuhammadAsadJaved avatar Dec 03 '19 03:12 MuhammadAsadJaved

@qzane i generated list and edges for existing images in the dataset folder of this repo using your script. then i run python test_pgn.py and generate output like this. Where is the problem? Can you give me some suggestion?

pgan1 pgan2 pgan3

MuhammadAsadJaved avatar Dec 05 '19 11:12 MuhammadAsadJaved

@MuhammadAsadJaved Can you send me these images? I can try that on my computer.

qzane avatar Dec 05 '19 19:12 qzane

I have sent these pictures to your personal email address sir.

On Fri, Dec 6, 2019 at 3:37 AM qzane [email protected] wrote:

Can you send me these images? I can try that on my computer.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Engineering-Course/CIHP_PGN/issues/38?email_source=notifications&email_token=AG4GR5EOFPU4275XVNUKN73QXFJ6PA5CNFSM4ITM6LNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGB4EAA#issuecomment-562283008, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG4GR5H54FVMAYXILJQL7W3QXFJ6PANCNFSM4ITM6LNA .

MuhammadAsadJaved avatar Dec 06 '19 03:12 MuhammadAsadJaved

In January, 2020, the script is named write_edge.m. Full path: CIHP_PGN/datasets/CIHP/tool/write_edge.m

neonb88 avatar Jan 26 '20 13:01 neonb88

@lemon1220 Also, doesn't this approach not make sense? The whole point of their training the PGN network(s) is so they can segment and label everything with the neural network. This script dumbly uses old computer vision techniques like gradients. I think there's a better way to do this. Will update when I find it

neonb88 avatar Jan 26 '20 14:01 neonb88

can you tell me a python equivalent of the above code logwell_script.m . I dont have matlab license with me. Thanks in advance.

@mukundhan3 : You can use octave, the free version of MATLAB. Also, this might also be useful to show how to run scripts from the command line

neonb88 avatar Jan 26 '20 14:01 neonb88

@qzane i generated list and edges for existing images in the dataset folder of this repo using your script. then i run python test_pgn.py and generate output like this. Where is the problem? Can you give me some suggestion?

@MuhammadAsadJaved I know it's a bit late to comment this, but I had the same problem like this. My problem was the misplacement of pre-trained model. At first, I thought I should place all the files in the pre-trained model (checkpoint / model.ckpt-593292.data-00000-of-00001 / model.ckpt-593292.index / model.ckpt-593292.meta), but it didn't work. What we should do is just extract zip file to checkpoint directory, so the checkpoint directory would be like checkpoint/CIHP_pgn/(somefiles).

I hope this will help you.

ynyBonfennil avatar Mar 31 '20 07:03 ynyBonfennil

I write a python script to prepare the data, maybe you want to try it https://gist.github.com/qzane/4d07b7551914f97f2bf8b9c79138ab14

@qzane Thank you for your python script. But this only generates the edges file and the respective blank(black) images. Do you have a python script to generate labels as well?

gayalkuruppu avatar May 27 '20 12:05 gayalkuruppu

I write a python script to prepare the data, maybe you want to try it https://gist.github.com/qzane/4d07b7551914f97f2bf8b9c79138ab14

@qzane Thank you for your python script. But this only generates the edges file and the respective blank(black) images. Do you have a python script to generate labels as well?

@gayalkuruppu I don't think you need labels to get the correct output. I created a folder with custom images, ran the python script that was linked to in a previous comment (https://gist.github.com/qzane/4d07b7551914f97f2bf8b9c79138ab14 and I saved it as prepare_dataset.py) with

python prepare_dataset.py custom_dataset/CIHP/images CIHP

and it created a new folder within datasets/ called CIHP (it'll be named whatever you use as the last argument in the previous python command).

The new folder has the structure

CIHP_PGN/
├─ datasets/
│  ├─ CIHP/
│  │  ├─ edges/
│  │  │  ├─ image0.png
│  │  │  ├─ image1.png
│  │  ├─ images/
│  │  │  ├─ image0.png
│  │  │  ├─ image1.jpg
│  │  ├─ list/
│  │  │  ├─ val_id.txt
│  │  │  ├─ val.txt

and then I was able to run python test_pgn.py and see the results in CIHP_PGN/output/cihp_parsing_maps/

mdrews93 avatar Jun 14 '21 20:06 mdrews93

If anyone needs it I have a working example of the model here : https://colab.research.google.com/drive/15uGzI5adMsZ7mIfVsr3Ruda25JswraPU?usp=sharing

confifu avatar Jun 16 '21 15:06 confifu

I write a python script to prepare the data, maybe you want to try it https://gist.github.com/qzane/4d07b7551914f97f2bf8b9c79138ab14

@qzane Thank you for your python script. But this only generates the edges file and the respective blank(black) images. Do you have a python script to generate labels as well?

@gayalkuruppu I don't think you need labels to get the correct output. I created a folder with custom images, ran the python script that was linked to in a previous comment (https://gist.github.com/qzane/4d07b7551914f97f2bf8b9c79138ab14 and I saved it as prepare_dataset.py) with

python prepare_dataset.py custom_dataset/CIHP/images CIHP

and it created a new folder within datasets/ called CIHP (it'll be named whatever you use as the last argument in the previous python command).

The new folder has the structure

CIHP_PGN/
├─ datasets/
│  ├─ CIHP/
│  │  ├─ edges/
│  │  │  ├─ image0.png
│  │  │  ├─ image1.png
│  │  ├─ images/
│  │  │  ├─ image0.png
│  │  │  ├─ image1.jpg
│  │  ├─ list/
│  │  │  ├─ val_id.txt
│  │  │  ├─ val.txt

and then I was able to run python test_pgn.py and see the results in CIHP_PGN/output/cihp_parsing_maps/

Sorry to bother you now, I just tried to run this script, but the resulting edges are full black images and not producing the correct edge images. How to solve this please? Thank you~

l-mengwei avatar Jul 30 '22 08:07 l-mengwei