从网站上下载数据集并解压——以coco数据集为例

2023-05-16

最近在阅读源码时发现了一段值得学习的源码,实现从网址下载coco数据集到本地,并解压,在这里做下记录,以备借鉴使用。

###以下载annotations为例
# Setup annotations data paths
annDir = "{}/annotations".format(dataDir)
if dataType == "minival": #给出不同子文件夹的文件夹名、文件名和网址
   annZipFile = "{}/instances_minival2014.json.zip".format(dataDir)
   annFile = "{}/instances_minival2014.json".format(annDir)
   annURL = "https://dl.dropboxusercontent.com/s/o43o90bna78omob/instances_minival2014.json.zip?dl=0"
   unZipDir = annDir
elif dataType == "valminusminival":
   annZipFile = "{}/instances_valminusminival2014.json.zip".format(dataDir)
   annFile = "{}/instances_valminusminival2014.json".format(annDir)
   annURL = "https://dl.dropboxusercontent.com/s/s3tw5zcg7395368/instances_valminusminival2014.json.zip?dl=0"
   unZipDir = annDir
else:
   annZipFile = "{}/annotations_trainval{}.zip".format(dataDir, dataYear)
   annFile = "{}/instances_{}{}.json".format(annDir, dataType, dataYear)
   annURL = "http://images.cocodataset.org/annotations/annotations_trainval{}.zip".format(dataYear)
   unZipDir = dataDir
# print("Annotations paths:"); print(annDir); print(annFile); print(annZipFile); print(annURL)

# Download annotations if not available locally
if not os.path.exists(annDir): #生成文件夹
   os.makedirs(annDir)
if not os.path.exists(annFile):
   if not os.path.exists(annZipFile):
       print("Downloading zipped annotations to " + annZipFile + " ...")
       with urllib.request.urlopen(annURL) as resp, open(annZipFile, 'wb') as out: 
           shutil.copyfileobj(resp, out) #使用urllib包下载压缩包
       print("... done downloading.")
   print("Unzipping " + annZipFile)
   with zipfile.ZipFile(annZipFile, "r") as zip_ref: #解压操作
       zip_ref.extractall(unZipDir)
   print("... done unzipping")
print("Will use annotations in " + annFile)

参考地址

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从网站上下载数据集并解压——以coco数据集为例 的相关文章

随机推荐

  • Pytorch源码学习之四:torchvision.models.squeezenet

    0 介绍 Squeezenet网址 torchvision model squeeze官方文档 主要思想 xff1a 堆叠Fire模块 xff0c 每个Fire模块 xff0c 分别采用1x1和3x3两个分支 xff0c 最后做拼 xff1
  • Pytorch源码学习之五:torchvision.models.densenet

    0 基本知识 DenseNet论文地址 DenseNet加强了每个Dense Block内部的连接 xff0c 每层输出与之前所有层进行concat连接 xff0c 使用三个Dense Block的网络示意图如下 xff1a 每个Block
  • Pytorch源码学习之六:torchvision.models.inception_v3

    0 参考和简介 torchvision models inception v3源码 实现的论文地址 部分网络结构 xff1a InceptionA InceptionC InceptionE 一 源码 span class token co
  • 设备管理信息系统

    设备管理系统 设备管理系统 xff08 Equipment Management System xff09 是将信息化了设备技术信息与现代化管理相结合 xff0c 是实现研究级管理信息化的先导 设备管理软件是设备管理模式与计算机技术结合的产
  • Pytorch源码学习之七:torchvision.models.googlenet

    0 基本知识 torchvision models googlenet源码地址 GoogLeNet论文地址 Inception模块 注意 xff0c 代码中第三个模块采取的3x3卷积而非5x5卷积 xff0c 不知为何 GoogLeNet网
  • TensorRT学习常用网址汇总(持续更新)

    一 官方网址 网址名称简介tensorrt support matrixTensorRT支持的硬件和应用详情 TensorRT中文教程中文教程 xff0c 部分翻译TensorRT官方中文文档官方中文文档 xff0c 注意版本号NVIDIA
  • JetsonTX2 之刷机 ——Jetpack 4.3

    2020年再次使用Nvidia Jetson tx2 xff0c Jetpack已经发行了4 4 xff0c TX2默认的系统也升级到了ubuntu 18 04 xff0c 刷机方式也发生了变化 这里记录我的刷机过程 xff0c 亲测有效
  • TX2(ubuntu 18.04)更换清华镜像源

    注意 xff0c 该版本的TX2有两个特点 xff1a Arm架构和ubuntu18 04 一 备份 sudo cp etc apt sources list etc apt sources list bak 先备份原文件sources l
  • ubuntu更换镜像源——全面讲解

    1 更换镜像源方法 我们都知道 xff0c 以清华源为例 xff0c ubuntu更换镜像分为以下几个步骤 xff1a Step1 备份原来的源 Step2 更换清华源 Step3 更新 例如 TX2 ubuntu 18 04 更换清华镜像
  • Jetson TX2刷机后查看CUDA和CUDNN版本——以JetPack4.3为例

    一 查看CUDA版本 nvcc V 输出为 xff1a 即CUDA版本为10 0 二 查看CUDNN版本 cat usr include cudnn h grep CUDNN MAJOR A 2 输出为 xff1a 即版本为7 6 3
  • TX2查看cpu/gpu使用情况方法大全

    一 方法1 tegrastats Jetpack4 3比起之前的3 x版本 xff0c tegrastats文件发生了变化 sudo cp usr bin tegrastats tegrastats sudo tegrastats 二 方法
  • Jetson TX2上升级cmake方法

    我的应用场景要编译TensorRT的sampleuffMaskRCNN xff0c 需要最低cmake版本为3 13 而Jetpack 4 3刷机后自带的为3 12 使用以下两条命令都是失败的 sudo pip3 install cmake
  • Linux之make知识点

    0 GNU Operating System 1 Linux之make的用法讲解
  • TX2 安装cv2需要的依赖——JetPack4.3

    JetPack 4 3自带了opencv 4 1 1 而当使用python3导入cv2时 xff0c 发现仍缺少依赖 xff0c 首先使用清华镜像源因此使用以下代码进行安装 xff1a sudo apt get update sudo ap
  • ipconfig命令详细图解

    一 操作实例 不带参数 xff1b all参数 xff1b release和 renew displaydns参数就是显示本地DNS内容 xff1b 相当多 xff1b 看下 xff0c 上了会网 xff0c 缓存的DNS很多 xff1b
  • 《自己动手写Docker》书摘之二---Linux Cgroups介绍

    Linux Cgroups介绍 上面是构建Linux容器的namespace技术 xff0c 它帮进程隔离出自己单独的空间 xff0c 但Docker又是怎么限制每个空间的大小 xff0c 保证他们不会互相争抢呢 xff1f 那么就要用到L
  • TX2安装tensorflow-gpu(亲测有效)

    安装好JetPack 4 3之后 xff0c 再也不需要从源码对tensorflow进行编译安装 xff0c 可以通过以下两步安装 xff1a Step1 安装h5py sudo apt get install python3 h5py 主
  • TX2编译TensorRT的C++ samples ——Jetpack4.3

    不得不说 xff0c JetPack 4 3实在是太方便了 xff01 1 Where is TensorRT 1 1 C 43 43 版本 与手动安装tensorRT不同 xff0c JetPack自动将TensorRT c 43 43
  • TX2编译安装curl,使其可以解析https

    不小心误删了刷机后自带的Curl 导致安装的curl不能解析https curl安装 以下方式可行 xff1a sudo apt purge curl git clone https github com curl curl git cd
  • 从网站上下载数据集并解压——以coco数据集为例

    最近在阅读源码时发现了一段值得学习的源码 xff0c 实现从网址下载coco数据集到本地 xff0c 并解压 xff0c 在这里做下记录 xff0c 以备借鉴使用 span class token comment 以下载annotation