Python script to package the information of tracking benchmarks like LaSOT and GOT-10k into json files for Siamese network based trackers
############################################################################################
#### Fot LaSOT dataset
############################################################################################
import os
import numpy as np
import json
import pdb LaSOT_path = "/home/wangxiao/Downloads/pysot/testing_dataset/LaSOT/"
video_files = os.listdir(LaSOT_path)
video_files = np.sort(video_files) ## use this class to avoid some array or other format issues in json.
class NumpyEncoder(json.JSONEncoder):
""" Special json encoder for numpy types """
def default(self, obj):
if isinstance(obj, (np.int_, np.intc, np.intp, np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64)):
return int(obj)
elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)):
return float(obj)
elif isinstance(obj, (np.ndarray,)): #### This is the fix
return obj.tolist()
return json.JSONEncoder.default(self, obj) dict = {} # for idx in range(len(video_files)):
for idx in range(5): ## for test this code work or not.
video_name = video_files[idx]
img_path = LaSOT_path + video_name + '/img/'
gt_path = LaSOT_path + video_name + '/groundtruth.txt' print("==>> video Name: ", video_name, " current-index/total: ", idx, "/", len(video_files), ", please wait ... ") img_files = sorted([p for p in os.listdir(img_path) if os.path.splitext(p)[1] == '.jpg']) # pdb.set_trace() gt_files = np.loadtxt(gt_path, delimiter=',')
init_rect = gt_files[0]
init_rect_first = init_rect.tolist() # pdb.set_trace()
img_names_list = []
gt_files_list = [] #### for each image and ground truth
for img_idx in range(len(img_files)):
img_names = video_name + '/img/' + img_files[img_idx]
img_names_list.append(img_names)
gt_files_list.append(gt_files[img_idx]) # pdb.set_trace() #### collect and save into one dict.
dict_collect = {'video_dir': video_name, 'init_rect': init_rect_first, 'img_names': img_names_list, 'gt_rect': gt_files_list}
dict[video_name] = dict_collect dumped = json.dumps(dict, cls=NumpyEncoder)
with open('LaSOT_test.json', 'w+') as f:
json.dump(dumped, f) print("==>> Done !") file = open('LaSOT_test.json','r',encoding='utf-8')
benchmark_info = json.load(file)
print(benchmark_info)
=================== Attention ===================
when you load the json file, you will find:
" ... [541.0, 280.0, 76.0, 27.0]], "attr": [], "absent": []}}' "
there is a ' at the begining and end of the dict, directly load this json (I mean run the pysot tracker with this json file) will cause following errors:
File "/home/wangxiao/Downloads/pysot/toolkit/datasets/__init__.py", line 26, in create_dataset
dataset = LaSOTDataset(**kwargs)
File "/home/wangxiao/Downloads/pysot/toolkit/datasets/lasot.py", line 81, in __init__
pbar = tqdm(meta_data.keys(), desc='loading '+name, ncols=100)
AttributeError: 'str' object has no attribute 'keys'
Thus, you need to modify the lasot.py (about line 69):
to remove the two ' (this operation actually change the string to dict)
Of course, you also need to add this package: import ast
Then, everything will be OK.
=========
Reference: https://www.cnblogs.com/sunshine2016/p/6197836.html
Python script to package the information of tracking benchmarks like LaSOT and GOT-10k into json files for Siamese network based trackers的更多相关文章
- java + spring (jython\python\script) Error:SyntaxError: no viable alternative at character '\n'
使用Jython结合java和Python开发功能时,要是遇到如下情况: 2016-03-10 16:16:49 DEBUG [com.freedom.orion.configs.JyhtonConf ...
- python模块module package
python模块module package module package 常用模块 模块与包的区别 模块分为内置模块.第三方模块,自定义模块 程序会先从内置到第三方再到当前工作目录下去找你导入的 ...
- Windows 配置Apache以便在浏览器中运行Python script的CGI模式
打开httpd.conf,找到”#ScriptInterpreterSource Registry “,移除前面的注释# (如果找不到这行,就自己添加进去) 找到“Options Indexes Fo ...
- Notepad++插件Emmet和Python Script的安装
最近在做一个项目,涉及到大量的HTML.CSS代码的编写,手动写代码效率实在 是低下.于是想搜索一下,有没有Notepad++插件可以支持自动生成的,果不其然还真有.Emmet,这款神器其实就是 Ze ...
- rc.local 注意事項,call python script, file position
如果要在 rc.local 呼叫 python script python script 的位置需使用絕對路徑 其 python script 裡的有關 file 的位置也需使用 絕對路徑 如果要在 ...
- python 包(package)和模块(module)的创建和引入(import)
python 包(package)和模块(module)的创建和引入(import) 名词解释 实际上,Python中的函数(Function).类(Class).模块(Module).包库(Pack ...
- import 本地Python module或package
很基础很重要的一课,虽然很简单,但是防止以后忘了,还是记下来 这个笔记里说的都是import本地的,自己创建的,或者复制粘贴的别人的,总之“不是安装到library”的module or packag ...
- A python script to check NE syncfail and get log from CIPS
#! /usr/bin/env python # -*- coding: UTF-8 -*- """The script is to check whether NE i ...
- ## Python中的Package和Jupyter中import包问题
前言 关于python包的一些知识 Java中的package概念 我们知道在java中的import package概念, java中的包就是一个目录,里面包含着子目录,子目录套着子目录,当需要引入 ...
随机推荐
- Linux对变量的截取替换
//对变量截取 ${variable} 对变量值的修正(增删数据),仅仅修改输出后的结果对源值,并不做修改 #变数后对接字符 # ## //截取从前面开始 % %% //截取从后面开始 / // // ...
- ireport(1.2.7)的IllegalAccessError异常
IllegalAccessError异常: Exception in thread "main" java.lang.IllegalAccessError: tried to ac ...
- P1525 关押罪犯[扩展域并查集]
题目来源:洛谷 题目描述 S城现有两座监狱,一共关押着N名罪犯,编号分别为1−N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用“怨气值”(一个正整 ...
- pipy配置镜像源
新电脑第一次使用使用pip命令下载贼慢 我们需要使用国内pipy镜像,参考如下 https://mirrors.tuna.tsinghua.edu.cn/help/pypi/ 所以只要设置一下就行了: ...
- Python +urllib+urllib2 带数据的post请求实例
#coding:utf-8 ''' Created on 2017年11月2日 @author: li.liu ''' import urllib import urllib2 import re f ...
- python打造seo必备工具-自动查询排名
因为工作需要,利用业余时间开发的,可以查询百度排名+360排名工具,附上代码. #360搜索排名查询 # -*- coding=utf-8 -*- import requests from lxml ...
- Flume架构以及应用介绍(转)
在具体介绍本文内容之前,先给大家看一下Hadoop业务的整体开发流程: 从Hadoop的业务开发流程图中可以看出,在大数据的业务处理过程中,对于数据的采集是十分重要的一步,也是不可避免的一步,从而引出 ...
- about云Hadoop相关技术总结
让你真正明白spark streaminghttp://www.aboutyun.com/forum.php?mod=viewthread&tid=21141(出处: about云开发)
- Spring框架:Controller和RestController区别
了解如何利用SpringMVC的注释创建RESTful Web服务. Spring的基于注释的MVC框架简化了创建RESTful Web服务的过程.传统的Spring MVC控制器和RESTful W ...
- web自动化测试-selenium的三种等待
一.等待的作用 1.在系统的功能运行过程中,所有的内容是需要一定的时间来实现展示, 2.时间耗费长短与网络速度.系统框架设定.接口的执行复杂度有关, 3.因此需要设置缓冲时间,若未设置缓冲时间,容易导 ...