您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關tensorflow語義分割api之使用deeplab訓練cityscapes的示例分析的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
安裝教程:
cityscapes訓練:
- tensorflow1.8+CUDA9.0+cudnn7.0+annaconda3+py3.5
- 使用最新的tensorflow1.12或者1.10都不行,報錯:報錯不造卷積算法(convolution algorithm...)
# Exit immediately if a command exits with a non-zero status. set -e CURRENT_DIR=$(pwd) WORK_DIR="." # Root path for Cityscapes dataset. CITYSCAPES_ROOT="${WORK_DIR}/cityscapes" # Create training labels. python "${CITYSCAPES_ROOT}/cityscapesscripts/preparation/createTrainIdLabelImgs.py" # Build TFRecords of the dataset. # First, create output directory for storing TFRecords. OUTPUT_DIR="${CITYSCAPES_ROOT}/tfrecord" mkdir -p "${OUTPUT_DIR}" BUILD_SCRIPT="${CURRENT_DIR}/build_cityscapes_data.py" echo "Converting Cityscapes dataset..." python "${BUILD_SCRIPT}" \ --cityscapes_root="${CITYSCAPES_ROOT}" \ --output_dir="${OUTPUT_DIR}" \
- 首先當前conda環境下安裝cityscapesScripts模塊,要支持py3.5才行;
- 由于cityscapesscripts/preparation/createTrainIdLabelImgs.py里面默認會把數據集gtFine下面的test,train,val文件夾json文件都轉為TrainIdlandelImgs.png;然而在test文件下有很多json文件編碼格式是錯誤的,大約十幾張,每次報錯,然后將其剔除!!!
- 然后執行build_cityscapes_data.py將img,lable轉換為tfrecord格式。
- 將訓練代碼寫成腳本文件:train_deeplab_cityscapes.sh
#!/bin/bash # CUDA_VISIBLE_DEVICES=0,1,2,3 python train.py --backbone resnet --lr 0.01 --workers 4 --epochs 40 --batch-size 16 --gpu-ids 0,1,2,3 --checkname deeplab-resnet --eval-interval 1 --dataset coco PATH_TO_INITIAL_CHECKPOINT='/home/rjw/tf-models/research/deeplab/pretrain_models/deeplabv3_cityscapes_train/model.ckpt' PATH_TO_TRAIN_DIR='/home/rjw/tf-models/research/deeplab/datasets/cityscapes/exp/train_on_train_set/train/' PATH_TO_DATASET='/home/rjw/tf-models/research/deeplab/datasets/cityscapes/tfrecord' WORK_DIR='/home/rjw/tf-models/research/deeplab' # From tensorflow/models/research/ python "${WORK_DIR}"/train.py \ --logtostderr \ --training_number_of_steps=40000 \ --train_split="train" \ --model_variant="xception_65" \ --atrous_rates=6 \ --atrous_rates=12 \ --atrous_rates=18 \ --output_stride=16 \ --decoder_output_stride=4 \ --train_crop_size=513 \ --train_crop_size=513 \ --train_batch_size=1 \ --fine_tune_batch_norm=False \ --dataset="cityscapes" \ --tf_initial_checkpoint=${PATH_TO_INITIAL_CHECKPOINT} \ --train_logdir=${PATH_TO_TRAIN_DIR} \ --dataset_dir=${PATH_TO_DATASET}
參數分析:
training_number_of_steps: 訓練迭代次數;
train_crop_size:訓練圖片的裁剪大小,因為我的GPU只有8G,故我將這個設置為513了;
train_batch_size: 訓練的batchsize,也是因為硬件條件,故保持1;
fine_tune_batch_norm=False :是否使用batch_norm,官方建議,如果訓練的batch_size小于12的話,須將該參數設置為False,這個設置很重要,否則的話訓練時會在2000步左右報錯
tf_initial_checkpoint:預訓練的初始checkpoint,這里設置的即是前面下載的../research/deeplab/backbone/deeplabv3_cityscapes_train/model.ckpt.index
train_logdir: 保存訓練權重的目錄,注意在開始的創建工程目錄的時候就創建了,這里設置為"../research/deeplab/exp/train_on_train_set/train/"
dataset_dir:數據集的地址,前面創建的TFRecords目錄。這里設置為"../dataset/cityscapes/tfrecord"
- 驗證腳本:
#!/bin/bash # CUDA_VISIBLE_DEVICES=0,1,2,3 python train.py --backbone resnet --lr 0.01 --workers 4 --epochs 40 --batch-size 16 --gpu-ids 0,1,2,3 --checkname deeplab-resnet --eval-interval 1 --dataset coco PATH_TO_INITIAL_CHECKPOINT='/home/rjw/tf-models/research/deeplab/pretrain_models/deeplabv3_cityscapes_train/' PATH_TO_CHECKPOINT='/home/rjw/tf-models/research/deeplab/datasets/cityscapes/exp/train_on_train_set/train/' PATH_TO_EVAL_DIR='/home/rjw/tf-models/research/deeplab/datasets/cityscapes/exp/train_on_train_set/eval/' PATH_TO_DATASET='/home/rjw/tf-models/research/deeplab/datasets/cityscapes/tfrecord' WORK_DIR='/home/rjw/tf-models/research/deeplab' # From tensorflow/models/research/ python "${WORK_DIR}"/eval.py \ --logtostderr \ --eval_split="val" \ --model_variant="xception_65" \ --atrous_rates=6 \ --atrous_rates=12 \ --atrous_rates=18 \ --output_stride=16 \ --decoder_output_stride=4 \ --eval_crop_size=1025 \ --eval_crop_size=2049 \ --dataset="cityscapes" \ --checkpoint_dir=${PATH_TO_INITIAL_CHECKPOINT} \ --eval_logdir=${PATH_TO_EVAL_DIR} \ --dataset_dir=${PATH_TO_DATASET}
- rusult:model.ckpt-40000為在初始化模型上訓練40000次迭代的模型;后面用初始化模型測試miou_1.0還是很低,不知道是不是有什么參數設置的問題!!!
- 注意,如果使用官方提供的checkpoint,壓縮包中是沒有checkpoint文件的,需要手動添加一個checkpoint文件;初始化模型中是沒有提供chekpoint文件的。
INFO:tensorflow:Restoring parameters from /home/rjw/tf-models/research/deeplab/datasets/cityscapes/exp/train_on_train_set/train/model.ckpt-40000 INFO:tensorflow:Running local_init_op. INFO:tensorflow:Done running local_init_op. INFO:tensorflow:Starting evaluation at 2018-12-18-07:13:08 INFO:tensorflow:Evaluation [50/500] INFO:tensorflow:Evaluation [100/500] INFO:tensorflow:Evaluation [150/500] INFO:tensorflow:Evaluation [200/500] INFO:tensorflow:Evaluation [250/500] INFO:tensorflow:Evaluation [300/500] INFO:tensorflow:Evaluation [350/500] INFO:tensorflow:Evaluation [400/500] INFO:tensorflow:Evaluation [450/500] miou_1.0[0.478293568] INFO:tensorflow:Waiting for new checkpoint at /home/rjw/tf-models/research/deeplab/pretrain_models/deeplabv3_cityscapes_train/ INFO:tensorflow:Found new checkpoint at /home/rjw/tf-models/research/deeplab/pretrain_models/deeplabv3_cityscapes_train/model.ckpt INFO:tensorflow:Graph was finalized. 2018-12-18 15:18:05.210957: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0 2018-12-18 15:18:05.211047: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-12-18 15:18:05.211077: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0 2018-12-18 15:18:05.211100: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N 2018-12-18 15:18:05.211645: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 9404 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1) INFO:tensorflow:Restoring parameters from /home/rjw/tf-models/research/deeplab/pretrain_models/deeplabv3_cityscapes_train/model.ckpt INFO:tensorflow:Running local_init_op. INFO:tensorflow:Done running local_init_op. INFO:tensorflow:Starting evaluation at 2018-12-18-07:18:06 INFO:tensorflow:Evaluation [50/500] INFO:tensorflow:Evaluation [100/500] INFO:tensorflow:Evaluation [150/500] INFO:tensorflow:Evaluation [200/500] INFO:tensorflow:Evaluation [250/500] INFO:tensorflow:Evaluation [300/500] INFO:tensorflow:Evaluation [350/500] INFO:tensorflow:Evaluation [400/500] INFO:tensorflow:Evaluation [450/500] miou_1.0[0.496331513]
- 在vis目錄下生成分割結果圖
#!/bin/bash # CUDA_VISIBLE_DEVICES=0,1,2,3 python train.py --backbone resnet --lr 0.01 --workers 4 --epochs 40 --batch-size 16 --gpu-ids 0,1,2,3 --checkname deeplab-resnet --eval-interval 1 --dataset coco PATH_TO_CHECKPOINT='/home/rjw/tf-models/research/deeplab/datasets/cityscapes/exp/train_on_train_set/train/' PATH_TO_VIS_DIR='/home/rjw/tf-models/research/deeplab/datasets/cityscapes/exp/train_on_train_set/vis/' PATH_TO_DATASET='/home/rjw/tf-models/research/deeplab/datasets/cityscapes/tfrecord' WORK_DIR='/home/rjw/tf-models/research/deeplab' # From tensorflow/models/research/ python "${WORK_DIR}"/vis.py \ --logtostderr \ --vis_split="val" \ --model_variant="xception_65" \ --atrous_rates=6 \ --atrous_rates=12 \ --atrous_rates=18 \ --output_stride=16 \ --decoder_output_stride=4 \ --vis_crop_size=1025 \ --vis_crop_size=2049 \ --dataset="cityscapes" \ --colormap_type="cityscapes" \ --checkpoint_dir=${PATH_TO_CHECKPOINT} \ --vis_logdir=${PATH_TO_VIS_DIR} \ --dataset_dir=${PATH_TO_DATASET}
感謝各位的閱讀!關于“tensorflow語義分割api之使用deeplab訓練cityscapes的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。