迁移学习问题一

  • syncedmem.cpp:64] Check failed: error == cudaSuccess (2 vs. 0)  out of memory

change  segnet_train.prototxt  bench_size:1(from 4 to 1):根据自己的gpu,将segnet_train.prototxt  中的 bench_size改为1.

  • F0725 17:02:42.888584 17046 math_functions.cu:121] Check failed: status == CUBLAS_STATUS_SUCCESS (11 vs. 0)  CUBLAS_STATUS_MAPPING_ERROR
    

 这个问题困扰了我很久很久,一直没解决。

没有弄清楚nyu数据集的label图有多少类,以及对应的class_weighting。有些博客说800多,40类,13类。我就天真的以为从labels40.mat 中提取出来的label就是40类,也苦于找不到合适的计算class_weighting的代码;最终在博客找到计算class_weighting的代码  class_weight.py:

import numpy as np
import argparse
import os
from PIL import Image
from os import listdir
import sys
import collections

# Import arguments
parser = argparse.ArgumentParser()
parser.add_argument('--dir', type=str, help='Path to the folder containing the images with annotations')
args = parser.parse_args()

if args.dir:
    cwd = args.dir
    if not args.dir.endswith('/'): cwd = cwd + '/'
else:
    cwd = os.getcwd() + '/'

image_names = listdir(cwd)
# Keep only images and append image_names to directory
image_list = [cwd + s for s in image_names if s.lower().endswith(('.png', '.jpg', '.jpeg'))]

print "Number of images:", len(image_list)

def count_all_pixels(image_list):
    dic_class_imgcount = dict()
    overall_pixelcount = dict()
    result = dict()
    for img in image_list:
        sys.stdout.write('.')
        sys.stdout.flush()
        for key, value in get_class_per_image(img).items():
            # Sum up the number of classes returned from get_class_per_image function
            overall_pixelcount[key] = overall_pixelcount.get(key, 0) + value
            # If the class is present in the image, then increase the value by one
            # shows in how many images a particular class is present
            dic_class_imgcount[key] = dic_class_imgcount.get(key, 0) + 1
    print "Done"
    # Save above 2 variables in a list
    for (k, v), (k2, v2) in zip(overall_pixelcount.items(), dic_class_imgcount.items()):
        if k != k2: print ("This was impossible to happen, but somehow it did"); exit()
        result[k] = [v, v2]
    return result


def get_class_per_image(img):
    dic_class_pixelcount = dict()
    im = Image.open(img)
    pix = im.load()
    for x in range(im.size[0]):
        for y in range(im.size[1]):
            dic_class_pixelcount[pix[x, y]] = dic_class_pixelcount.get(pix[x, y], 0) + 1
    #del dic_class_pixelcount[11]
    return dic_class_pixelcount


def cal_class_weights(image_list):
    freq_images = dict()
    weights = collections.OrderedDict()
    # calculate freq per class
    for k, (v1, v2) in count_all_pixels(image_list).items():
        freq_images[k] = v1 / (v2 * 360 * 480 * 1.0)
    # calculate median of freqs
    median = np.median(freq_images.values())
    # calculate weights
    for k, v in freq_images.items():
        weights[k] = median / v
    return weights

results = cal_class_weights(image_list)

# Print the results
for k, v in results.items():
    print "    class", k, "weight:", round(v, 4)

print "Copy this:"
for k, v in results.items():
    print "    class_weighting:", round(v, 4)

注意:运行命令

python class_weightpy --dir ~/data/nyu/40_label/labels_deal  #后面加上label图片的路径

最后输出的class_weighting居然有48类!!!怪不得一直出错。 

解决方案:

将segnet_train.prototxt 的最后一个num_output:改为48;ignore_label:改为48 ,class_weighting:也需要改为自己的。

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值