Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test.py #122

Open
Qirui-Y opened this issue Oct 9, 2019 · 34 comments
Open

test.py #122

Qirui-Y opened this issue Oct 9, 2019 · 34 comments

Comments

@Qirui-Y
Copy link

Qirui-Y commented Oct 9, 2019

Thanks for providing open source code, can you provide test.py ?

@jaemin93
Copy link

jaemin93 commented Oct 10, 2019

@stonessss yes, i write test code.

  1. copy and overwrite.
    https://github.com/jaemin93/pytorch-deeplab-xception/blob/master/test.py
    https://github.com/jaemin93/pytorch-deeplab-xception/blob/master/dataloaders/__init__.py

  2. add test.txt(you want to test img id) in VOC path /ImageSets/Segmentation
    test.txt is like val, train.txt

  3. cmd
    python --test
    --dataset pascal
    --backbone xception
    --out_stride 16
    --crop_size 513
    --model /your/checkpoint.pth.tar
    --save_path /prediction/image/path

@Qirui-Y
Copy link
Author

Qirui-Y commented Oct 10, 2019

@stonessss yes, i write test code.

  1. copy and overwrite.
    https://github.com/jaemin93/pytorch-deeplab-xception/blob/master/test.py
    https://github.com/jaemin93/pytorch-deeplab-xception/blob/master/dataloaders/__init__.py
  2. add test.txt(you want to test img id) in VOC path /ImageSets/Segmentation
    test.txt is like val, train.txt
  3. cmd
    '
    python --test
    --dataset pascal
    --backbone xception
    --out_stride 16
    --crop_size 513
    --model /your/checkpoint.pth.tar
    --save_path /prediction/image/path
    '
    python --test\ --dataset pascal \ --backbone xception \ --out_stride 16 \ --crop_size 513 \ --model /your/checkpoint.pth.tar \ --save_path /prediction/image/path

@Qirui-Y Qirui-Y closed this as completed Oct 10, 2019
@Qirui-Y Qirui-Y reopened this Oct 10, 2019
@Qirui-Y
Copy link
Author

Qirui-Y commented Oct 10, 2019

Thank you very much, I found an open source code to test a single image.

@jaemin93
Copy link

@stonessss I can test a lot of data so see if needed. :)

@Qirui-Y
Copy link
Author

Qirui-Y commented Oct 10, 2019

There are some problems in the code, error in pascal.py.

@jaemin93
Copy link

tell me what error.

@Qirui-Y
Copy link
Author

Qirui-Y commented Oct 10, 2019

Thank you for your sharing.
Error 1: NUM_CLASSES = 21;
Error 2: The label image should be in .jpg format(There was no error in the previous version.)
And I thinkl “assert” can remove.

@jaemin93
Copy link

I didn't have that problem. Can you copy your error and show it to me?

@Qirui-Y
Copy link
Author

Qirui-Y commented Oct 10, 2019

I think a bit misunderstanding, the error occurred in the link code you shared, I don't understand why it is different from the original code, the system may not be updated in time. There is no problem in the original code, I have solved these problems.Anyway thank you very much !

@jaemin93
Copy link

okay, I'm glad to solve the problem.

@mm86443
Copy link

mm86443 commented Dec 8, 2019

how can i use test.py to test sityscapes?
since i change pascal to sicyscapes,an error has occurred

AttributeError: 'Namespace' object has no attribute 'batch_size'

@jaemin93
Copy link

jaemin93 commented Dec 8, 2019

@mm86443
Since I changed the repo template, I'll help you if i can see your code.

@mm86443
Copy link

mm86443 commented Dec 9, 2019

@mm86443
Since I changed the repo template, I'll help you if i can see your code.

thank you,i reslove this problem last night.
i remake the code in dataloader.init.py , so i can run your 'test.py' successful.

elif args.dataset == 'cityscapes' and args.test: test_set = cityscapes.CityscapesSegmentation(args, split='test') num_class = test_set.NUM_CLASSES test_loader = DataLoader(test_set, batch_size=1, shuffle=False) ids = test_set.files['test'] return test_loader, ids, num_class

thanks for you provide your code again.

@huidemie
Copy link

@mm86443
Since I changed the repo template, I'll help you if i can see your code.

hello, your test.py link is not available now?Could you share it again?Thank you so much .

@YLiu-creator
Copy link

why the above link has 404 not found error? Please give a test.py file again, thanks!! @jaemin93

@jaemin93
Copy link

@yang8595 @huidemie I'm sorry keep your waiting. test.py is renamed inference.py

@brx290
Copy link

brx290 commented Apr 8, 2020

@jaemin93 Hello, thanks for sharing. I am a beginner, I would like to ask where is the model generated after training with my own data set? And what other areas do you need to modify besides using your inference.py file? I use xception.

@jaemin93
Copy link

jaemin93 commented Apr 9, 2020

@brx290
0. if you can find experiment_{0, 1, ...} folder, there is checkpoint file (*.pth.tar).

  1. Then, you define deeplabv3 model (backbone xception) and load checkpoint file.
  2. Just give the data as my inference.py data flows.

@brx290
Copy link

brx290 commented Apr 9, 2020

@jaemin93
Thank you for your answer. I found my checkpoint file. Can you explain in detail how do I define the deeplabv3 model (backbone xception) and load the checkpoint file. Do I need to copy all your files to my folder?

@jaemin93
Copy link

jaemin93 commented Apr 9, 2020

@brx290
No, you don't have to. you make inference.py

# define
model = DeepLab(num_classes=self.nclass,
                        backbone=args.backbone,
                        output_stride=args.out_stride,
                        sync_bn=False,
                        freeze_bn=False)

# load
checkpoint = torch.load('your/pth.tar/file', map_location='cpu')
model.load_state_dict(checkpoint['state_dict'])

# prepare inference 
model.eval()
test_img = Image.open('test.png').convert('RGB')
test_array = np.array(test_img).astype(np.float32)

# Normalize
test_array /= 255.0
test_array -= (0.485, 0.456, 0.406)
test_array /= (0.229, 0.224, 0.225)
test_tensor = torch.from_numpy(test_array)

# inference 
with torch.no_grad():
    # you can get prediction
    output = model(test_tensor)

the code is not perfect. but I hope it helps.

@brx290
Copy link

brx290 commented Apr 9, 2020

@jaemin93
Thank you for your help. I have run successfully. Is the generated picture a mask picture? The following is the result of my operation.
ACL0001_001
ACL0001_001

@jaemin93
Copy link

@brx290
you need to map the predicted values ​​to RGB values.
[[0, 0, 0],
[0, 1, 0],
[0, 1, 1]]
There is no difference between 0 and 1 in human view in grayscale values.

@brx290
Copy link

brx290 commented Apr 16, 2020

@jaemin93
Thank you for your guidance, I can already get the split picture. There is still a problem that bothers me. How to draw a loss curve. I found summaries.py in the utils file and I don't know how to use it.

@jaemin93
Copy link

@brx290
That's because the file(summaries.py) imports the tensorboardX package.
It would be helpful to refer to this. https://pytorch.org/docs/stable/tensorboard.html
It's simple and you'll understand right away. Then I hope you enjoy coding :)

@WangHeHehehehe
Copy link

@brx290
you need to map the predicted values ​​to RGB values.
[[0, 0, 0],
[0, 1, 0],
[0, 1, 1]]
There is no difference between 0 and 1 in human view in grayscale values.

I have the same question,but i do not know how to modify it specifically.Can you tell me the details.Thank you so much!

@WangHeHehehehe
Copy link

Thank you for your inference.py code! I set --backbone resnet --dataset pascal --epoch 100 to train process, and get miou 77%.However when i test the images, I get the results like this.i dont know where is the problem.
图片
图片
Looking forward to your reply!

@zhujiesuper
Copy link

@mm86443
Since I changed the repo template, I'll help you if i can see your code.

thank you,i reslove this problem last night.
i remake the code in dataloader.init.py , so i can run your 'test.py' successful.

elif args.dataset == 'cityscapes' and args.test: test_set = cityscapes.CityscapesSegmentation(args, split='test') num_class = test_set.NUM_CLASSES test_loader = DataLoader(test_set, batch_size=1, shuffle=False) ids = test_set.files['test'] return test_loader, ids, num_class

thanks for you provide your code again.

hello,can you show me your test.py?

@jaemin93
Copy link

jaemin93 commented Apr 29, 2020 via email

@zhujiesuper
Copy link

Test.py is renamed inference.py 보낸 사람: zhujiesuper [email protected] 회신 대상: jfzhang95/pytorch-deeplab-xception [email protected] 날짜: 2020년 4월 29일 수요일 오후 2:22 받는 사람: jfzhang95/pytorch-deeplab-xception [email protected] 참조: Jaemin jung [email protected], Mention [email protected] 주제: Re: [jfzhang95/pytorch-deeplab-xception] test.py (#122) @mm86443https://github.com/mm86443 Since I changed the repo template, I'll help you if i can see your code. thank you,i reslove this problem last night. i remake the code in dataloader.init.py , so i can run your 'test.py' successful. elif args.dataset == 'cityscapes' and args.test: test_set = cityscapes.CityscapesSegmentation(args, split='test') num_class = test_set.NUM_CLASSES test_loader = DataLoader(test_set, batch_size=1, shuffle=False) ids = test_set.files['test'] return test_loader, ids, num_class thanks for you provide your code again. hello,can you show me your test.py? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<#122 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHDTHJOWAK7AFNU3LCMHGJTRO62RHANCNFSM4I65PEIQ.

thank you,but i can not use this inference.py directly,im

@mm86443
Since I changed the repo template, I'll help you if i can see your code.

thank you,i reslove this problem last night.
i remake the code in dataloader.init.py , so i can run your 'test.py' successful.

elif args.dataset == 'cityscapes' and args.test: test_set = cityscapes.CityscapesSegmentation(args, split='test') num_class = test_set.NUM_CLASSES test_loader = DataLoader(test_set, batch_size=1, shuffle=False) ids = test_set.files['test'] return test_loader, ids, num_class

thanks for you provide your code again.

hello ,i can not use test.py or inference.py? can you show me your code?

@2679622694
Copy link

Test.py重命名为inference.py。意图:zhujiesuper [email protected]角色:jfzhang95 / pytorch-deeplab-xception [email protected]角色:2020年4月29日2: 22岁的照片:jfzhang95 / pytorch-deeplab-xception [email protected]注释:Jaemin jung [email protected],提及[email protected]注释: [jfzhang95 / pytorch-deeplab-xception] test.py(#122) @ mm86443 < https://github.com/mm86443>由于我更改了回购模板,因此如果能看到您的代码,我会为您提供帮助。谢谢,我昨晚喜欢这个问题。我在dataloader.init.py中重新制作了代码,因此我可以成功运行您的'test.py'。elif args.dataset =='cityscapes'和args.test:test_set =城市景观.CityscapesSegmentation(args,split ='test')num_class = test_set.NUM_CLASSES test_loader = DataLoader(test_set,batch_size = 1,shuffle = False)ids = test_set .files ['test']返回test_loader,id,num_class谢谢您再次提供代码。你好,你能告诉我你的test.py吗?—您收到此邮件是因为被提及。直接回复此电子邮件,在GitHub < #122(评论) >上查看,或取消订阅< https://github.com。

Hello, when I ran the "inference. py" file, I was prompted that I did not have the "config.json" file. Could you please provide the "config.json" file

@Ellsionjeep
Copy link

Test.py is renamed inference.py 보낸 사람: zhujiesuper [email protected] 회신 대상: jfzhang95/pytorch-deeplab-xception [email protected] 날짜: 2020년 4월 29일 수요일 오후 2:22 받는 사람: jfzhang95/pytorch-deeplab-xception [email protected] 참조: Jaemin jung [email protected], Mention [email protected] 주제: Re: [jfzhang95/pytorch-deeplab-xception] test.py (#122) @mm86443https://github.com/mm86443 Since I changed the repo template, I'll help you if i can see your code. thank you,i reslove this problem last night. i remake the code in dataloader.init.py , so i can run your 'test.py' successful. elif args.dataset == 'cityscapes' and args.test: test_set = cityscapes.CityscapesSegmentation(args, split='test') num_class = test_set.NUM_CLASSES test_loader = DataLoader(test_set, batch_size=1, shuffle=False) ids = test_set.files['test'] return test_loader, ids, num_class thanks for you provide your code again. hello,can you show me your test.py? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<#122 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHDTHJOWAK7AFNU3LCMHGJTRO62RHANCNFSM4I65PEIQ.

hello! I have some problems.why no checkpoint found at 'model_best.pth' in inference.py.But I have modified the path in config.json

@2679622694
Copy link

Test.py被重命名inference.py 보 낸 사 람 :zhujiesuper [email protected] 회 신 대 상 :jfzhang95 / pytorch-deeplab-xception [email protected] 날 짜 :2020 년 4 월 29 일 수 요 일 오 후 2:22 받 는 사 람 : jfzhang95 / pytorch-deeplab-xception [email protected] 참조:Jaemin jung [email protected],提及提及@ noreply.github.com주제:回复:[jfzhang95 / pytorch-deeplab-xception]测试.py(#122)@ mm86443 https://github.com/mm86443由于我更改了回购模板,因此如果我能看到您的代码,就会为您提供帮助。谢谢,我昨晚喜欢这个问题。我在dataloader.init.py中重新编写了代码,因此我可以成功运行您的'test.py'。elif args.dataset =='cityscapes'和args.test:test_set =城市景观.CityscapesSegmentation(args,split ='test')num_class = test_set.NUM_CLASSES test_loader = DataLoader(test_set,batch_size = 1,shuffle = False)ids = test_set .files ['test']返回test_loader,id,num_class,感谢您再次提供代码。你好,你能告诉我你的test.py吗?—您收到此邮件是因为有人提到您。直接回复此电子邮件,在GitHub < #122(评论) >上查看,或退订https:// github。

你好!我有一些问题。为什么在inference.py的'model_best.pth'上找不到检查点,但是我修改了config.json中的路径

May i ask you where is "config.json."? could you provide the file?

@Carina0809
Copy link

@stonessss yes, i write test code.

  1. copy and overwrite.
    https://github.com/jaemin93/pytorch-deeplab-xception/blob/master/test.py
    https://github.com/jaemin93/pytorch-deeplab-xception/blob/master/dataloaders/__init__.py
  2. add test.txt(you want to test img id) in VOC path /ImageSets/Segmentation
    test.txt is like val, train.txt
  3. cmd
    python --test
    --dataset pascal
    --backbone xception
    --out_stride 16
    --crop_size 513
    --model /your/checkpoint.pth.tar
    --save_path /prediction/image/path

Hello! The links you provided are invalid. Could you please provide again? Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests