data.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:voc-classification 作者: philkr 项目源码 文件源码
def dataAsImageDataLayer(voc_dir, tmp_dir, image_set='train', **kwargs):
    from caffe_all import L
    from os import path
    from python_layers import PY
    Py = PY('data')
    voc_data = VOCData(voc_dir, image_set)

    # Create a text file with all the paths
    source_file = path.join(tmp_dir, image_set+"_images.txt")
    if not path.exists( source_file ):
        f = open(source_file, 'w')
        for n in voc_data.image_names:
            print('%s 0'% voc_data.image_path[n], file=f)
        f.close()

    # Create a label file
    lbl_file = path.join(tmp_dir, image_set+"_images.lbl")
    if not path.exists( lbl_file ):
        np.save(open(lbl_file, 'wb'), [voc_data.labels[n] for n in voc_data.image_names])
    cs = kwargs.get('transform_param',{}).get('crop_size',0)
    return L.ImageData(source=source_file, ntop=2, new_width=cs, new_height=cs, **kwargs)[0], Py.LabelData(label=lbl_file, batch_size=kwargs.get('batch_size',1))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号