ImageNet 数据集下载

一、获取urls

登录官网,  www.image-net.org, SEARCH自己需要的图片种类, 以搜索插座(socket)为例,必须输入英文(这是废话)。可能需要翻墙,不一定,如何翻墙请去隔壁下载VPN

点击需要的选项进入

点击downloads标签,出现URLS类

点击出现很可怕的大量url,下载保存在txt中备用。

二、python脚本批量下载

用python的urlib库批量下载获取的urls,此处用的python2.7环境,代码如下

# from urllib import request
import urllib2, urllib
import signal

path ='/home/hzc/Pictures/URL-TXT/watermeter.txt'


def handler(signum, frame):
    raise AssertionError

file = open(path)

for line in file:
    try:
        signal.signal(signal.SIGALRM, handler)
        signal.alarm(5)

        print(line)
        # # fake header
        # headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'}
        # req = urllib.request.Request(url=line, headers=headers)
        # urllib.request.urlopen(req).read()

        try:
            f = urllib2.urlopen(line)
            data = f.read()
            with open('%s ' % line.split('/')[-1], "wb") as code:
                code.write(data)
        except:
            pass

        # pic_link = line
        # save_path = r'/home/hzc/Pictures/%s.JPG '% line.split('/')[-1]
        # request.urlretrieve(pic_link, save_path)
    except AssertionError:
        print("%s timeout " % line)
        continue

file.close()


得到一大串图片,重命名,加标签的请移步我的另一篇博客:


完毕

阅读更多

没有更多推荐了,返回首页