1 Star 0 Fork 0

wangye707/deeplabv3-Tensorflow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
data_utils.py 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
anxiang 提交于 2019-05-11 22:53 +08:00 . modify
import cv2, os
import numpy as np
from sklearn.model_selection import train_test_split
import tensorflow as tf
class DataSet():
'''
通过读入文件生成数据集
'''
def __init__(self, image_path, label_path):
self.image_path = np.array(image_path)
self.label_path = np.array(label_path)
self.batch_count = 0
self.epoch_count = 0
def num_examples(self):
'''
得到样本的数量
:return:
'''
return self.image_path.shape[0]
def next_batch(self, batch_size):
'''
next_batch函数
:param batch_size:
:return:
'''
start = self.batch_count * batch_size
end = start + batch_size
self.batch_count += 1
if end > self.image_path.shape[0]:
self.batch_count = 0
random_index = np.random.permutation(self.image_path.shape[0])
self.image_path = self.image_path[random_index]
self.label_path = self.label_path[random_index]
self.epoch_count += 1
start = self.batch_count * batch_size
end = start + batch_size
self.batch_count += 1
image_batch, label_batch = self.read_path(self.image_path[start:end],
self.label_path[start:end])
return image_batch, label_batch
def read_path(self, x_path, y_path):
'''
将路径读为图片
:param x_path:
:param y_path:
:return:
'''
x = []
y = []
for i in range(x_path.shape[0]):
x.append(self.transform(cv2.imread(x_path[i], cv2.CAP_MODE_RGB)))
y.append(cv2.imread(y_path[i], cv2.CAP_MODE_GRAY))
return np.array(x), np.array(y)
def transform(self, img):
return img
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangye707/deeplabv3-Tensorflow.git
git@gitee.com:wangye707/deeplabv3-Tensorflow.git
wangye707
deeplabv3-Tensorflow
deeplabv3-Tensorflow
master

搜索帮助