############################################################################################
#### 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. 约束布局ConstraintLayout

    Android新特性介绍,ConstraintLayout完全解析 约束布局ConstraintLayout用法全解析 约束布局ConstraintLayout看这一篇就够了

  2. tomcat 安装记录 centos7 开放对外端口

    //端口查询 [root@CentOS7 bin]# firewall-cmd --query-port=9090/tcp no //添加端口 [root@CentOS7 bin]# firewall ...

  3. js 数组去重求和 (转载)

    方法一:js数组id去重,value值相加问题 来源:https://www.jianshu.com/p/8f79e31b46ed // js let arr = [ { id: 1, value: ...

  4. 【Python】eval 函数

    eval() 函数十分强大 -- 将字符串 当成 有效的表达式 来求值,并返回计算结果 # 基本的熟悉计算 print(eval("1 + 1")) # 字符串重复 print(e ...

  5. PDF 补丁丁 0.6.2 测试版发布

    如题. 不知不觉,这个软件已经出来十个年头了. 0.6.2 版可能是 PDF 补丁丁的最后一版.它在未来将不再更新.谢谢关注.

  6. Powershell-抛文档并捕获异常

    #source1 file location $source1 = "C:\users\me\desktop\test1" #dest1 file location $dest1 ...

  7. Eclipse安装JDK11方式

    安装JDK11JDK下载网址:https://www.oracle.com/technetwork/java/javase/downloads Java SE Development Kit 11ht ...

  8. myshell

    要求 利用fork,exec,wait编写一个具有执行命令功能的shell

  9. c语言的可变参数实例

    可变参数函数实现的步骤如下: 1.在函数中创建一个va_list类型变量 2.使用va_start对其进行初始化 3.使用va_arg访问参数值 4.使用va_end完成清理工作 接下来我们来实现一个 ...

  10. EF实体类指定部分属性不映射数据库标记

    命名空间 ;using System.ComponentModel.DataAnnotations.Schema; 实体部分 public partial class Student { [NotMa ...