-
大小: 72KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-05-14
- 语言: Python
- 标签:
资源简介
Keras实现实时语义分割的深层神经网络架构ENET
代码片段和文件信息
# coding=utf-8
from __future__ import absolute_import print_function
from PIL import Image as PILImage
import numpy as np
import os
import six
import sys
from keras import backend as K
from keras.preprocessing.image import array_to_img
from src.data import datasets utils
from src.experiments.core import Experiment
import models
def color_output_image(colormap img mode=‘bw‘):
“““
move this into datasets.py
:param dataset:
:param img:
:param mode:
:return:
“““
cv_image = np.zeros((img.shape[0] img.shape[1] 3) dtype=np.uint8)
if mode == ‘bw‘:
cv_image[img > 0] = 255
elif mode == ‘class_palette‘:
img = np.asarray(img dtype=np.uint8).reshape(img.size[0] img.size[1])
for cid color in six.iteritems(colormap):
cv_image[img == cid] = color
else:
raise ValueError(‘Unknown coloring mode: Expected one of {}; got {}‘.format([‘bw‘ ‘class_palette‘] mode))
return cv_image
def predict(segmenter img h=None w=None):
np.random.seed(1337) # for reproducibility
try:
oh ow = img.shape[0] img.shape[1]
h = oh if h is None else h
w = ow if w is None else w
img = utils.resize(img target_h=h target_w=w)
img = np.expand_dims(utils.normalize(img) axis=0)
pred = segmenter.predict(img)[0]
nc = pred.shape[-1]
scores = np.max(pred axis=1)
pred = np.argmax(pred axis=1)
scores_per_class = [np.sum(scores[pred == c]) / np.sum(scores) for c in range(nc)]
pred = np.reshape(pred (h w)) # dh x dw
pred = np.expand_dims(pred axis=2) # dh x dw x 1
# pred = np.repeat(pred repeats=3 axis=2) # dh x dw x 3
pred = utils.resize(pred target_h=oh target_w=ow) # oh x ow x 1 (original shape)
pred = utils.img_to_array(pred)
return pred scores_per_class
except:
if img is None:
print(‘Skipping corrupted image‘)
return None
else:
raise
def load_mscoco_data():
data_type = ‘val2014‘
out_directory = os.path.join(‘data‘ ‘out‘ model_name)
config = {‘dataset_name‘: ‘MSCOCO‘
‘data_dir‘: ‘data/MSCOCO‘
‘data_type‘: data_type}
dataset = getattr(datasets config[‘dataset_name‘])(**config)
instance_mode = False
keep_context = 0.2
if len(sys.argv) > 1:
filetxt = sys.argv[1]
with open(filetxt) as fin:
basedir = os.path.dirname(filetxt)
files = [os.path.join(basedir line.rstrip(‘\n‘)) for line in fin]
data_gen = (utils.load_image(imfile) for imfile in files)
else:
data_gen = (sample[0] for sample in
dataset.flow())
data = {
‘generator‘: data_gen
‘root_dir‘: ‘data‘
‘num_instances‘: dataset.num_instances
‘dir_target‘: out_directory
‘keep_context‘: keep_context
‘dataset_name‘: ‘MSCOCO‘
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\
文件 1246 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\.gitignore
文件 1063 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\LICENSE
文件 2447 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\README.md
目录 0 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\config\
文件 477 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\config\README.md
文件 182 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\config\evaluation.json.default
文件 664 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\config\solver.json.default
目录 0 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\data\
文件 51 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\data\README.md
文件 726 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\environment.yml
目录 0 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\experiments\
文件 291 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\experiments\README.md
文件 161 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\overfit.sh
文件 62 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\predict.sh
目录 0 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\pretrained\
文件 244 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\pretrained\README.md
文件 346 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\requirements.txt
文件 221 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\setup.sh
目录 0 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\
文件 15 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\__init__.py
目录 0 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\
文件 15 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\__init__.py
文件 1667 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\coco_extract_labels.py
文件 4286 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\data_loader.py
文件 24481 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\datasets.py
目录 0 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\pycocotools\
文件 199 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\pycocotools\Makefile
文件 0 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\pycocotools\__init__.py
文件 11439 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\pycocotools\_mask.pyx
文件 18296 2017-11-22 09:56 PavlosMelissinos-enet-keras-168b7e0\src\data\pycocotools\coco.py
............此处省略43个文件信息
相关资源
- Python-RNNoiseRNN音频噪声抑制学习
- Python-手势识别使用在TensorFlow中卷积神
- Python-Keras实现的DeepSpeech端到端语音识
- Python-FastFCN用于语义分割的RethinkingD
- Python-使用RNN股市预测
- Python-使用最新版本的tensorflow实现se
- Python-人工智能和基于机器学习的机器
- Python-用TensorFlow实现神经网络实体关系
- Python-单目3D人体姿态检测
- Python-PyTorch实现基于Transformer的神经机
- Python-2019年百度的实体链指比赛ccks2
- Python-PyTorch实现的NEAT神经进化算法
- Python-DoWhy微软出品的Python因果推断库
- Python-训练和可视化分层注意网络Hie
- Python-通过神经网络和遗传算法进化的
- Python-DQNchainerPython用Chainer实现的Deep
- Python-图神经网络GNN文献大列表
- Python-基于视频的车辆计数系统使用
- Python-PythonTensorflowKeras实现参数tSNE算法
- Python-图像分割Keras在Keras中实现Segne
评论
共有 条评论