代码取自于 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模块