当前位置:网站首页>Tensorflow learning 6 -- run through UNET image segmentation

Tensorflow learning 6 -- run through UNET image segmentation

2022-05-14 14:02:14Luo Xiaohei's War record is beautiful

Thank the great God of selfless dedication and my senior brother
The great god git library
Great God's video tutorial
The great god CSDN
The following content of this article is based on the great God's tutorial, which is suitable for my own process record

Make your own dataset

Mark the original picture

use labelme Open the picture and mark it , Save as json Format file and put it together with the original drawing

  1. install labelme
    installed pip Can use pip install labelme Install and use . But the code used later should import labelme file , If it had been Windows Of cmd If installed in , When the code runs, it will report an error ModuleNotFoundError: No module named ‘labelme’ . At this time, just in the present pycharm Inside the terminal pip install Just the corresponding library .

  2. Place the original image in dataset\image Folder 【dataset and make_dataset.py In the same directory 】, from labelme Open the folder
     Insert picture description here

  3. Turn on autosave... Before marking Save trouble . The shortcut key to switch to the next picture is D
     Insert picture description here

  4. Click on Create PolyGons marked

  5. preservation josn File to dataset\image Folder

take json Convert file to label picture

Use elder martial brother's make_dataset.py file , Generate JPEGlmages and SegmentationClass The contents of the two folders , One is the original picture .jpg, One is the label diagram .png.

  1. modify make_dataset.py The category in the file is the category of its own data set . My own is seam, The background is the default .
     Insert picture description here
  2. Make sure the folder path is correct , Just run it . It will automatically generate folder and label diagram
     Insert picture description here

Reference tutorials not used in label making

Divide the data set

Divide the available data sets into training sets in proportion 、 Test set, etc.

  1. Put pictures in a folder (dataset\JPEGImages) And label folder (dataset\SegmentationClass) Put it in unet\VOCdevkit\VOC2007.

  2. open unet In the catalog voc_annotation.py The split scale can be modified .
    7:3 Just put 0.9 Change to 0.7
     Insert picture description here

  3. function voc_annotation.py There will be a pile of txt The file in ImageSets/Segmentation Create... In the folder , Inside is a list of pictures

Running training

  1. open train.py Change the classification quantity
    num_classes = 2
  2. Download the weight file from the network disk , In the model_data Folder
    then train.py Write the corresponding path in
    model_path = “model_data/unet_vgg_voc.h5”
    If you don't use the weight of the boss , Just change this to an empty string , But the training effect is probably not good
  3. You can change the number of cycles
     Insert picture description here
    from 0-20 It's training when it's frozen , from 20-40 It's thawing training . I put the thawed epoch It's also written as 20 You can run , Equivalent to I don't change the parameters , Just fine tune . Junk computers can't run training , It used to be 0-50-100 Two stage batch All are 2 Run to 51 Give me an error

Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated. [[{ {node PyFunc}}]]

The reason is that there is not enough memory Fried .

forecast

  1. To open the first unet.py Change some parameters .
    “model_path” : ‘logs/ep020-loss0.001-val_loss0.001.h5’,
    This path is from logs Found in the folder , Choose any one and put it on
    Remember to change the number of categories below
     Insert picture description here
    preservation , Don't run

  2. open predict.py
    Classify and write
    name_classes = [“background”,“seam”]

  3. function predict.py, Then you can predict a single picture by inputting the file path at the bottom
     Insert picture description here

  4. design sketch
    I really can't see the picture of the weld I really can't recognize
     Insert picture description here
    The recognized image can be segmented normally
     Insert picture description here
    Took a new picture to predict , Although the scope is a little small , But the position is right , It seems that more training is needed
     Insert picture description here

  5. There are other modes to try
     Insert picture description here

Calculation mIOU

function unet Under folder get_miou.py Documents obtained mIOU result

  1. confirm unet.py The parameters in have been modified

  2. open get_miou.py Modify the classification inside and run
     Insert picture description here

Semantic segmentation evaluation index –mIOU

原网站

版权声明
本文为[Luo Xiaohei's War record is beautiful]所创,转载请带上原文链接,感谢
https://chowdera.com/2022/134/202205141342543202.html

随机推荐