105_multi_classification_workflow_landcover

原创
03/19 23:09
阅读数 61

地物分类案例

# !/usr/bin/env python3
# coding=utf-8
import os
import time

from iobjectspy.ml.vision import Trainer, Inference
Using TensorFlow backend.

设置输入数据路径

curr_dir = ''
data_dir = os.path.join(curr_dir, '..','..','example_data')
dom_path = os.path.join(data_dir, 'inference', 'landcover_infer.tif')

设置输出数据路径

out_dir = os.path.join(curr_dir, '..','..','out')
if not os.path.exists(out_dir):
    os.makedirs(out_dir)
def example_create_train_data():
    pass

地物分类模型训练

"""
train the model
"""

print('train start')

train_data_path = os.path.join(data_dir, 'training', 'multi_cls_train_data', 'train_data')
config = os.path.join(curr_dir, '..','..','trainer_config','multi_cls_train_config.sdt')
output_model_path = out_dir
backbone_weight_path = os.path.join(curr_dir, '..','..','backbone','efficientnet-b3_imagenet_1000_notop.h5')

start_time = time.time()

Trainer(train_data_path=train_data_path, config=config, epoch=1, batch_size=1, lr=0.001,
        output_model_path=output_model_path,
        output_model_name='example_multi_cls',
        backbone_name='efficientnetb3',
        backbone_weight_path=backbone_weight_path,
        log_path=os.path.join(out_dir, 'experiment_log')
        ).multi_classify_train()

end_time = time.time()
print('完成,共耗时{}s,结果保存在 {}'.format(
    end_time - start_time, os.path.join(output_model_path, 'example_multi_cls')))
train start
Train on 83 samples, validate on 27 samples
Epoch 1/1
83/83 [==============================] - 532s 6s/step - loss: 1.2738 - acc: 0.4414 - iou_score: 0.3486 - val_loss: 0.8991 - val_acc: 0.5552 - val_iou_score: 0.5489

Epoch 00001: val_loss improved from inf to 0.89909, saving model to ../../out/experiment_log/2019-09-20/multi_classification/checkpoints/multi_classification-0001-0.8991.hdf5
model saved in dir : ../../out/example_multi_cls/example_multi_cls.sdm
完成,共耗时624.5755066871643s,结果保存在 ../../out/example_multi_cls

设置模型路径

output_model_path = os.path.join(out_dir, 'example_multi_cls', 'example_multi_cls.sdm')
out_data = os.path.join(out_dir, 'out_multicls.udb')
out_dataset_name = 'predict_landcover'
start_time = time.time()
Inference(input_data=dom_path,
          model_path=output_model_path,
          out_data=out_data,
          out_dataset_name=out_dataset_name).multi_classify_infer(offset=200, result_type='grid')

end_time = time.time()
print('提取完成,共耗时{}s,结果数据保存在 {} 数据源下 {} 数据集中'.format(
    end_time - start_time, out_data, out_dataset_name))
没有DSM数据,只使用DOM预测
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]100%,16java -cp /home/data/hou/workspaces/iobjectspy/venv/lib/python3.6/site-packages/iobjectspy-10.0.0-py3.6.egg/iobjectspy/_jsuperpy/jars/iobjects-py4j.jar com.supermap.jsuperpy.ApplicationExample 127.0.0.1 58441
[iObjectsPy]: Connection gateway-service successful, Python callback port bind 44639

The multi classification have done!
提取完成,共耗时21.624144077301025s,结果数据保存在 ../../out/out_multicls.udb 数据源下 predict_landcover 数据集中

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部