[深度学习] TensorFlow上实现Unet网络

TensorFlowUnet安装与使用

代码取自于 https://github.com/jakeret/tf_unet
TensorFlow Unet文档 https://tf-unet.readthedocs.io/en/latest/installation.html

TensorFlow Unet安装

确保Tensorflow已安装,如果没有,请参考Tensorflow安装说明 link

  • 克隆github工程 git clone https://github.com/jakeret/tf_unet.git
  • 安装package
    • $ cd tf_unet
    • $ pip install -r requirements.txt
    • $ python setup.py install --user
      在这里插入图片描述
Package使用

在其他工程中使用Tensorflow Unet的一个例子

from tf_unet import unet, util, image_util

#preparing data loading
data_provider = image_util.ImageDataProvider("fishes/train/*.tif")

#setup & training
net = unet.Unet(layers=3, features_root=64, channels=1, n_class=2)
trainer = unet.Trainer(net)
path = trainer.train(data_provider, output_path, training_iters=32, epochs=100)

#verification
...
prediction = net.predict(path, data)
unet.error_rate(prediction, util.crop_to_shape(label, prediction.shape))

img = util.combine_img_prediction(data, label, prediction)
util.save_image(img, "prediction.jpg")

可以利用Tensorboard跟踪学习的进度。tf_unet输出相关指标信息。
在这里插入图片描述

tf_unet Package的几个模块(链接有api和source,不再赘述)
  • unet模块:link
  • image_util模块:link
  • image_util模块:link
  • layers模块:link
工程自带示例程序(都已经亲测)

都是Jupyter notebooks,方便学习

建议使用1.5.0以上版本tensorflow,本人在测试这个代码的时候遇到报错AttributeError: 'module' object has no attribute 'softmax_cross_entropy_with_logits_v2',查了之后,发现1.4版本以下没有这个function,如果没有条件安装1.5.0以上,可git checkout 0.1.0切换至0.1.0版本

from __future__ import division, print_function
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
plt.rcParams['image.cmap'] 
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值