FCN数据生成

1.下载数据

下载地址:http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip

from urllib import request
        #回调函数,当连接上服务器、以及相应的数据块传输完毕的时候会触发该回调。我们可以利用这个回调函数来显示当前的下载进度。
        def _progress(count, block_size, total_size):
            #sys.stdout.write等价于print
            sys.stdout.write(
                '\r>> Downloading %s %.1f%%' % (filename, float(count * block_size) / float(total_size) * 100.0))
            sys.stdout.flush()
        #下载指定url中的文件
        filepath, _ = urllib.request.urlretrieve(url_name, filepath, reporthook=_progress)

2.解压压缩包

1.解压zip文件

import zipfile
#压缩包解压
 with zipfile.ZipFile(filepath) as zf:
     zip_dir = zf.namelist()[0]
     zf.extractall(dir_path)

2.解压tar文件

import tarfile
tarfile.open(filepath, 'r:gz').extractall(dir_path)

3.生成训练的数据

3.1生成文件名列表

image——训练数据的地址,annotation——目标图像的地址,filename——文件名

{'training':[{'image': f, 'annotation': annotation_file, 'filename': filename},....
    ...,{'image': f, 'annotation': annotation_file, 'filename': filename}],
'validation':[{'image': f, 'annotation': annotation_file, 'filename': filename},...
    ....,{'image': f, 'annotation': annotation_file, 'filename': filename}]
 }

3.2读取图像

import scipy.misc as misc
image = misc.imread(filename)

3.3生成batch数据

images[start:end], annotations[start:end]

3.3.1从images,annotations列表中从头截取一个batch_size的数据,start=0,end=batch_size

3.3.2继续获取后边batch_size的数据 ,start=end,end=end+batch_size

3.3.3当end超出images的大小后,打乱images后执行3.3.1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值