forked from zhanghang1989/PyTorch-Encoding
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add detail API and other fixes (zhanghang1989#63)
- Loading branch information
1 parent
3ba8d2f
commit 9bc7053
Showing
11 changed files
with
89 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import torch | ||
import encoding | ||
|
||
# Get the model | ||
model = encoding.models.get_model('fcn_resnet50_ade', pretrained=True).cuda() | ||
model.eval() | ||
|
||
# Prepare the image | ||
url = 'https://github.com/zhanghang1989/image-data/blob/master/' + \ | ||
'encoding/segmentation/ade20k/ADE_val_00001142.jpg?raw=true' | ||
filename = 'example.jpg' | ||
img = encoding.utils.load_image( | ||
encoding.utils.download(url, filename)).cuda().unsqueeze(0) | ||
|
||
# Make prediction | ||
output = model.evaluate(img) | ||
predict = torch.max(output, 1)[1].cpu().numpy() + 1 | ||
|
||
# Get color pallete for visualization | ||
mask = encoding.utils.get_mask_pallete(predict, 'ade20k') | ||
mask.save('output.png') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import importlib | ||
import torch | ||
import encoding | ||
from option import Options | ||
from torch.autograd import Variable | ||
|
||
if __name__ == "__main__": | ||
args = Options().parse() | ||
model = encoding.models.get_segmentation_model(args.model, dataset=args.dataset, aux=args.aux, | ||
se_loss=args.se_loss, norm_layer=torch.nn.BatchNorm2d) | ||
print('Creating the model:') | ||
|
||
print(model) | ||
model.cuda() | ||
x = Variable(torch.Tensor(4, 3, 480, 480)).cuda() | ||
with torch.no_grad(): | ||
out = model(x) | ||
for y in out: | ||
print(y.size()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters