日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Unet项目解析(1): run_training.py

發(fā)布時間:2025/3/15 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unet项目解析(1): run_training.py 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

項目GitHub主頁:https://github.com/orobix/retina-unet

參考論文:Retina blood vessel segmentation with a convolution neural network (U-net)?Retina blood vessel segmentation with a convolution neural network (U-net)


1. run_training.py解析

import os, sys # os模塊中主要用于處理文件和目錄 import configparser # Python 3.6中 configparser全使用小寫#config file to read from config = configparser.RawConfigParser() config.readfp(open(r'./configuration.txt')) # 建議使用 config.read('configuration.txt') #'configuration.txt'的內(nèi)容見下面 #=========================================== #name of the experiment name_experiment = config.get('experiment name', 'name') nohup = config.getboolean('training settings', 'nohup') #std output on log file?run_GPU = '' if sys.platform == 'win32' else ' THEANO_FLAGS=device=gpu,floatX=float32 ' #是否用GPU進(jìn)行訓(xùn)練#create a folder for the results 創(chuàng)建文件夾用于保存結(jié)果 result_dir = name_experiment print ("\n 1. Create directory for the results (if not already existing)") if os.path.exists(result_dir):print ("Dir already existing") # 用于保存結(jié)果的test文件夾如果存在就沒有必要創(chuàng)建 elif sys.platform=='win32':os.system('mkdir ' + result_dir) else:os.system('mkdir -p ' +result_dir) # 需要時創(chuàng)建上層目錄,如目錄早已存在則不當(dāng)作錯誤print ("copy the configuration file in the results folder") if sys.platform=='win32':os.system('copy configuration.txt .\\' +name_experiment+'\\'+name_experiment+'_configuration.txt') else:os.system('cp configuration.txt ./' +name_experiment+'/'+name_experiment+'_configuration.txt')# run the experiment if nohup: #作者采用不掛斷的方式運行命令print ("\n2. Run the training with nohup, no GPU ")os.system(' nohup python -u ./src/retinaNN_training.py > ' +'./'+name_experiment+'/'+name_experiment+'_training.nohup') #運行retina_training.py文件 else:print ("\n2. Run the training(no nohup), no GPU")os.system(' python ./src/retinaNN_training.py') # 采用掛起的形式運行命令

配置文件:configuration.txt (使用的是section-option方法,可以利用字符串匹配進(jìn)行參數(shù)解析)

[data paths] #數(shù)據(jù)路徑 以及 訓(xùn)練集 測試集的名字 path_local = ./DRIVE_datasets_training_testing/ #封裝好的訓(xùn)練集圖像+金標(biāo)準(zhǔn) 和 測試集圖像+金標(biāo)準(zhǔn) train_imgs_original = DRIVE_dataset_imgs_train.hdf5 #封裝好的訓(xùn)練集圖像 train_groundTruth = DRIVE_dataset_groundTruth_train.hdf5 #封裝好的訓(xùn)練集金標(biāo)準(zhǔn) train_border_masks = DRIVE_dataset_borderMasks_train.hdf5sks #封裝好的訓(xùn)練集掩膜test_imgs_original = DRIVE_dataset_imgs_test.hdf5 #封裝好的測試集圖像test_groundTruth = DRIVE_dataset_groundTruth_test.hdf5 #封裝好的測試集金標(biāo)準(zhǔn)test_border_masks = DRIVE_dataset_borderMasks_test.hdf5 #封裝好的測試集掩膜[experiment name]name = test[data attributes]# 作者的訓(xùn)練集不多 所以作者采用了分塊進(jìn)行訓(xùn)練的方式,從圖像中裁剪的圖像塊大小為 patch_height*patch_widthpatch_height = 48 patch_width = 48[training settings]#number of total patches:N_subimgs = 190000#if patches are extracted only inside the field of view:inside_FOV = False#Number of training epochsN_epochs = 150batch_size = 32#if running with nohup #不掛斷地運行命令nohup = True[testing settings]#Choose the model to test: best==epoch with min loss, last==last epochbest_last = best#number of full images for the test (max 20)full_images_to_test = 20#How many original-groundTruth-prediction images are visualized in each imageN_group_visual = 1#Compute average in the prediction, improve results but require more patches to be predictedaverage_mode = True#Only if average_mode==True. Stride for patch extraction, lower value require more patches to be predictedstride_height = 5stride_width = 5#if running with nohupnohup = False

總結(jié)

以上是生活随笔為你收集整理的Unet项目解析(1): run_training.py的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。