20_提取目标-iObjects Python with JupyterHub for K8s
从影像数据中检测并提取符合特征的地物,结果信息输出到GeoJSON文件中。
在JupyterLab中调用iObjects Python实现,过程与代码如下:
In [6]:
import os import time from iobjectspy import open_datasource from iobjectspy.ai.recognition import detection
In [7]:
#data_dir = '' data_dir = '/home/jovyan/data/smdata/' out_dir = os.path.join(data_dir, 'out/') model_path = os.path.join(data_dir, 'model/det/1') print(model_path) category_name = ['plane']
输出:
/home/jovyan/data/smdata/model/det/1
In [8]:
if not os.path.exists(out_dir): os.makedirs(out_dir) def extract_plane_file(): """ 影像文件格式支持 ‘tif’、‘img’(Erdas Image)、'jpg'、'png' 等 目标检测结果为GeoJSON文件,包含目标位置、类型等信息 """ start_time = time.time() detection(data_dir + 'plane.tif', category_name, model_path, out_data=out_dir, out_name='out_plane.json') end_time = time.time() print('耗时{}s'.format(end_time-start_time))
In [9]:
if __name__ == '__main__': # 基于影像文件进行飞机目标检测 extract_plane_file()
输出信息:
INFO:tensorflow:Saver not created because there are no variables in the graph to restore INFO:tensorflow:The specified SavedModel has no variables; no checkpoints were restored. 耗时5.122027635574341s