Comments (4)
Please run this script to get the predicted label maps.
from fastfcn.
@wuhuikai , Thanks for your replying. How do I get segmentation ground truth of both training and val sets of PContext?
from fastfcn.
import os
import numpy as np
import torch
from PIL import Image
from tqdm import trange
from detail import Detail
def get_voc_pallete(num_cls):
n = num_cls
pallete = [0]*(n*3)
for j in range(0,n):
lab = j
pallete[j*3+0] = 0
pallete[j*3+1] = 0
pallete[j*3+2] = 0
i = 0
while (lab > 0):
pallete[j*3+0] |= (((lab >> 0) & 1) << (7-i))
pallete[j*3+1] |= (((lab >> 1) & 1) << (7-i))
pallete[j*3+2] |= (((lab >> 2) & 1) << (7-i))
i = i + 1
lab >>= 3
return pallete
if not os.path.exists('gts'):
os.makedirs('gts')
root=os.path.expanduser('~/.encoding/data')
BASE_DIR = 'VOCdevkit/VOC2010'
NUM_CLASS = 59
#from detail import mask
root = os.path.join(root, BASE_DIR)
annFile = os.path.join(root, 'trainval_merged.json')
imgDir = os.path.join(root, 'JPEGImages')
detail = Detail(annFile, imgDir, 'val')
ids = detail.getImgs()
# generate masks
_mapping = np.sort(np.array([
0, 2, 259, 260, 415, 324, 9, 258, 144, 18, 19, 22,
23, 397, 25, 284, 158, 159, 416, 33, 162, 420, 454, 295, 296,
427, 44, 45, 46, 308, 59, 440, 445, 31, 232, 65, 354, 424,
68, 326, 72, 458, 34, 207, 80, 355, 85, 347, 220, 349, 360,
98, 187, 104, 105, 366, 189, 368, 113, 115]))
_key = np.array(range(len(_mapping))).astype('uint8')
mask_file = os.path.join(root, 'val.pth')
print('mask_file:', mask_file)
def _class_to_index(mask):
# assert the values
values = np.unique(mask)
for i in range(len(values)):
assert(values[i] in _mapping)
index = np.digitize(mask.ravel(), _mapping, right=True)
return _key[index].reshape(mask.shape)
def _preprocess(mask_file):
masks = {}
tbar = trange(len(ids))
print("Preprocessing mask, this will take a while." + \
"But don't worry, it only run once for each split.")
for i in tbar:
img_id = ids[i]
mask = Image.fromarray(_class_to_index(detail.getMask(img_id)))
masks[img_id['image_id']] = mask
tbar.set_description("Preprocessing masks {}".format(img_id['image_id']))
torch.save(masks, mask_file)
return masks
if os.path.exists(mask_file):
masks = torch.load(mask_file)
else:
masks = _preprocess(mask_file)
for i in trange(len(ids)):
img_id = ids[i]
path = os.path.basename(img_id['file_name'])
mask = masks[img_id['image_id']]
mask.putpalette(get_voc_pallete(256))
outname = os.path.splitext(path)[0] + '.png'
mask.save(os.path.join('gts', outname))
from fastfcn.
You can use above script to generate val
labels. With minor modification, it can be used to generate train
labels. Sorry for the bad code style 😭
from fastfcn.
Related Issues (20)
- Pre-training weights HOT 1
- What do I need change in code to run CPU testing without using CUDA
- What do I need change in code to run "test" script only on CPU without using CUDA?
- I can't successfully run train script on my dataset. HOT 1
- "IndexError: list index out of range" durinng "test" and "test single image" scipt HOT 3
- Need your suggestions HOT 5
- FastFCN has been supported by MMSegmentation. HOT 9
- In order to run this on a different dataset say CamVid what changes need to be made HOT 2
- RuntimeError: Failed downloading url https://hangzh.s3.amazonaws.com/encoding/models/resnet50-ebb6acbb.zip HOT 3
- RuntimeError: => no checkpoint found at 'encnet_jpu_res50_pcontext.pth.tar' HOT 1
- Why use seperable convolutions with dilation factor? HOT 1
- Run Time error when trying to train AdeK20 dataset HOT 1
- What batch size and learning rate would you recommend training for a 24gb GPU?
- Runtime error wile downloading pretrained model
- About the PContext precision results HOT 1
- 训练时出现 raise RuntimeError("{} is a zip archive (did you mean to use torch.jit.load()?)". HOT 5
- 不能下载 HOT 2
- about syncbn HOT 3
- latest版本训练的时候卡住 HOT 1
- How could I set "resume" while running test_single_image? HOT 8
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 fastfcn.