############################################################################################
#### 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):

meta_data = ast.literal_eval(meta_data)

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.

=========

Referencehttps://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的更多相关文章

  1. 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 ...

  2. python模块module package

    python模块module   package module package 常用模块 模块与包的区别 模块分为内置模块.第三方模块,自定义模块 程序会先从内置到第三方再到当前工作目录下去找你导入的 ...

  3. Windows 配置Apache以便在浏览器中运行Python script的CGI模式

    打开httpd.conf,找到”#ScriptInterpreterSource Registry “,移除前面的注释# (如果找不到这行,就自己添加进去) 找到“Options Indexes Fo ...

  4. Notepad++插件Emmet和Python Script的安装

    最近在做一个项目,涉及到大量的HTML.CSS代码的编写,手动写代码效率实在 是低下.于是想搜索一下,有没有Notepad++插件可以支持自动生成的,果不其然还真有.Emmet,这款神器其实就是 Ze ...

  5. rc.local 注意事項,call python script, file position

    如果要在 rc.local 呼叫 python script python script 的位置需使用絕對路徑 其 python script 裡的有關 file 的位置也需使用 絕對路徑 如果要在 ...

  6. python 包(package)和模块(module)的创建和引入(import)

    python 包(package)和模块(module)的创建和引入(import) 名词解释 实际上,Python中的函数(Function).类(Class).模块(Module).包库(Pack ...

  7. import 本地Python module或package

    很基础很重要的一课,虽然很简单,但是防止以后忘了,还是记下来 这个笔记里说的都是import本地的,自己创建的,或者复制粘贴的别人的,总之“不是安装到library”的module or packag ...

  8. 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 ...

  9. ## Python中的Package和Jupyter中import包问题

    前言 关于python包的一些知识 Java中的package概念 我们知道在java中的import package概念, java中的包就是一个目录,里面包含着子目录,子目录套着子目录,当需要引入 ...

随机推荐

  1. Linux添加硬盘创建新的逻辑卷方式

    有同仁看了上文<Linux添加硬盘扩充已有分区存储空间方式>一文后,提出疑问,现在很多云服务器本来没有逻辑卷,添加数据盘后需要自行添加,如何处理? 此文将以某云服务器为例,详细进行解说. ...

  2. FriendlyCore overlayfs 挂载方式

    友善 friendlycore 挂载 overlayfs 过程: uboot 引导系统启动的时候加载 ramdisk.img  这个 cpio 格式的 initrd(虚拟文件系统). 注意: ramd ...

  3. vue父组件触发子组件方法

    比如应用场景是弹窗中的组件,想要点弹窗时更新该组件展示对应记录的的值 methods: { edit (record) { this.mdl = Object.assign({}, record) t ...

  4. C语言基础知识-数组和字符串

    C语言基础知识-数组和字符串 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.数组概述 在程序设计中,为了方便处理数据把具有相同类型的若干变量按有序形式组织起来的方式我们称为数组 ...

  5. 基于tornado---异步并发接口

    1.目的 由于有多个程序和脚本需要对mysql进行读写数据库,每次在脚本中进行数据库的连接.用cursor进行操作过于麻烦,因此希望可以有一个脚本开放接口,只需要传入sql语句,就可以返回结果回来.因 ...

  6. Codeforecs H. Subsegments

    思路: 刚开始: 利用map来统计长度为k的一段上的数字及其出现次数,不断更新区段位置,减去退出区段的数字的出现次数,加上新出现的数字及其出现次数,每次都从后向前遍历一遍map,如果遇到一个数且出现次 ...

  7. 深入详解JVM内存模型

    JVM内存结构 由上图可以清楚的看到JVM的内存空间分为3大部分: 堆内存 方法区 栈内存 其中栈内存可以再细分为java虚拟机栈和本地方法栈,堆内存可以划分为新生代和老年代,新生代中还可以再次划分为 ...

  8. python面试题&练习题之嵌套循环

    1.打印如下结果: 1*5=5 2*10=20 3*15=45 ... 10*50=500 for i in range(1,11): print(str(i)+'x'+str((i*5))+'='+ ...

  9. http服务读取配置文件,交叉编译

    因为是在windows上编译的代码,在linux上不可执行,所以需要交叉编译 package main import ( "flag" "gopkg.in/ini.v1& ...

  10. learning java Charset 查看支持的字符集类型

    import java.nio.charset.Charset; import java.util.SortedMap; public class CharsetTest { public stati ...