实 例 操 作 教 程 实例操作教程 实例操作教程
电子产品图像检索.ipynb 和 py文件
import os import sys parent_path = os.path.dirname(sys.path[0]) if parent_path not in sys.path: sys.path.append(parent_path)
一 生成 caltech_split.txt 文件
split 文件的模版样本
- 101_ObjectCategories/metronome/image_0004.jpg 0
import pandas as pd import numpy as np import glob import os
# 下面的文件路径需要修改成自己的 path_file = '/data/nextcloud/dbc2017/files/jupyter/PyRetri/main/split_file/caltech_split.txt'
# 下面的文件路径需要修改成自己的数据集的位置 gallery_lst = glob.glob('/data/nextcloud/dbc2017/files/jupyter/test_data_A/gallery/*.jpg') query_lst = glob.glob('/data/nextcloud/dbc2017/files/jupyter/test_data_A/query/*.jpg')
gallery_path = ['101_ObjectCategories/allimg/'+os.path.basename(i) for i in gallery_lst] query_lst = ['101_ObjectCategories/allimg/'+os.path.basename(i) for i in query_lst]
print(len(query_lst)) print(len(gallery_lst))
if os.path.exists(path_file): os.remove(path_file)
with open(path_file,'w') as f: for i in gallery_path: f.write('{0} {1}\n'.format(i,1)) for index,i in enumerate(query_lst): if index != len(query_lst)-1: f.write('{0} {1}\n'.format(i,0)) else: f.write('{0} {1}'.format(i,0))
caltech_split.txt
二 完成 gallery 和 query 的划分
python main/split_dataset.py -d /data/caltech101/ -sf main/split_file/caltech_split.txt
三 令生成 json 数据
python main/make_data_json.py -d /data/caltech101/gallery/ -sp data_jsons/caltech_gallery.json -t general
python main/make_data_json.py -d /data/caltech101/query/ -sp data_jsons/caltech_query.json -t general
四 使用模型抽取特征
python main/extract_feature.py -dj data_jsons/caltech_gallery.json -sp /data/features/caltech/gallery/ -cfg configs/caltech.yaml -si 2000 python main/extract_feature.py -dj data_jsons/caltech_query.json -sp /data/features/caltech/query/ -cfg configs/caltech.yaml -si 2000
注意,这里抽取特征的方法会根据 caltech.yaml 配置文件来进行抽取。
抽取后的特地址默认在 /data/features 文件夹下。
PS: 建议这里使用 screen 或者 nohup 工具挂后台进行抽取。
五 图像检索排序
六 生成提交文件
七 一些自定义操作