- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用多标签数据训练 caffenet。然而,在训练阶段,损失并没有减少。我现在尝试检查 backward()
是否无法正常工作。我有这段代码来检查是否存在渐变。
import numpy as np
import os.path as osp
import matplotlib.pyplot as plt
from pprint import pprint
from copy import copy
% matplotlib inline
plt.rcParams['figure.figsize'] = (6, 6)
caffe_root = '../' # this file is expected to be in {caffe_root}/examples
sys.path.append(caffe_root + 'python')
import caffe # If you get "No module named _caffe", either you have not built pycaffe or you have the wrong path.
from caffe import layers as L, params as P # Shortcuts to define the net prototxt.
sys.path.append("pycaffe/layers") # the datalayers we will use are in this directory.
sys.path.append("pycaffe") # the tools file is in this folder
import tools #this contains some tools that we need
# set data root directory, e.g:
peta_root = osp.join('/root/data/PETA/')
# these are the PASCAL classes, we'll need them later.
#classes = np.asarray(['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'])
# make sure we have the caffenet weight downloaded.
if not os.path.isfile(caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'):
print("Downloading pre-trained CaffeNet model...")
!../scripts/download_model_binary.py ../models/bvlc_reference_caffenet
# initialize caffe for gpu mode
caffe.set_mode_gpu()
caffe.set_device(1)
# helper function for common structures
def conv_relu(bottom, ks, nout, stride=1, pad=0, group=1):
conv = L.Convolution(bottom, kernel_size=ks, stride=stride,
num_output=nout, pad=pad, group=group)#,weight_filler=dict(type='xavier'))
return conv, L.ReLU(conv, in_place=True)
# another helper function
def fc_relu(bottom, nout):
fc = L.InnerProduct(bottom, num_output=nout)
return fc, L.ReLU(fc, in_place=True)
# yet another helper function
def max_pool(bottom, ks, stride=1):
return L.Pooling(bottom, pool=P.Pooling.MAX, kernel_size=ks, stride=stride)
# main netspec wrapper
def caffenet_multilabel(data_layer_params, datalayer):
# setup the python data layer
n = caffe.NetSpec()
n.data, n.label = L.Python(module = 'peta_multilabel_datalayers', layer = datalayer,
ntop = 2, param_str=str(data_layer_params))
# the net itself
n.conv1, n.relu1 = conv_relu(n.data, 11, 96, stride=4)
n.pool1 = max_pool(n.relu1, 3, stride=2)
n.norm1 = L.LRN(n.pool1, local_size=5, alpha=1e-4, beta=0.75)
n.conv2, n.relu2 = conv_relu(n.norm1, 5, 256, pad=2, group=2)
n.pool2 = max_pool(n.relu2, 3, stride=2)
n.norm2 = L.LRN(n.pool2, local_size=5, alpha=1e-4, beta=0.75)
n.conv3, n.relu3 = conv_relu(n.norm2, 3, 384, pad=1)
n.conv4, n.relu4 = conv_relu(n.relu3, 3, 384, pad=1, group=2)
n.conv5, n.relu5 = conv_relu(n.relu4, 3, 256, pad=1, group=2)
n.pool5 = max_pool(n.relu5, 3, stride=2)
n.fc6, n.relu6 = fc_relu(n.pool5, 4096)
n.drop6 = L.Dropout(n.relu6, in_place=True)
n.fc7, n.relu7 = fc_relu(n.drop6, 4096)
n.drop7 = L.Dropout(n.relu7, in_place=True)
n.score = L.InnerProduct(n.drop7, num_output=2)
n.loss = L.SigmoidCrossEntropyLoss(n.score, n.label)
return str(n.to_proto())
workdir = './peta_multilabel_with_datalayer'
if not os.path.isdir(workdir):
os.makedirs(workdir)
solverprototxt = tools.CaffeSolver(trainnet_prototxt_path = osp.join(workdir, "trainnet.prototxt"), testnet_prototxt_path = osp.join(workdir, "valnet.prototxt"))
solverprototxt.sp['display'] = "1"
solverprototxt.sp['base_lr'] = "0.0001"
solverprototxt.write(osp.join(workdir, 'solver.prototxt'))
# write train net.
with open(osp.join(workdir, 'trainnet.prototxt'), 'w') as f:
# provide parpeta_multilabel_with_datalayerameters to the data layer as a python dictionary. Easy as pie!
data_layer_params = dict(batch_size = 128, im_shape = [227, 227], split = 'train', peta_root = peta_root)
f.write(caffenet_multilabel(data_layer_params, 'PetaMultilabelDataLayerSync'))
# write validation net.
with open(osp.join(workdir, 'valnet.prototxt'), 'w') as f:
data_layer_params = dict(batch_size = 128, im_shape = [227, 227], split = 'val', peta_root = peta_root)
f.write(caffenet_multilabel(data_layer_params, 'PetaMultilabelDataLayerSync'))
solver = caffe.SGDSolver(osp.join(workdir, 'solver.prototxt'))
#solver.net.copy_from(caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel')
solver.test_nets[0].share_with(solver.net)
#solver.step(1)
solver.net.top_names
solver.net.backward()
solver.step(1)
print solver.net.params['fc6'][0].data[...]
print solver.net.blobs['fc6'].data[...]
print solver.net.blobs['fc6'].diff[...]
然而梯度的输出似乎为零并且权重根本没有更新。
[[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
...,
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]]
[[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
...,
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]]
[[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
...,
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]]
有人知道发生了什么吗?
最佳答案
查看您的params
的值:它们都是零。您没有为图层定义filler
,因此您得到的只是零。
为权重定义随机初始值设定项并再次运行。
仅运行 backward()
是没有意义的 - 损失是在 forward()
传递期间计算的,没有通过网络传播的损失信息供后向传递使用.
在 backward()
之前调用 forward()
来进行一次完整的前后传递。
关于machine-learning - caffe - 网络产生零梯度并且不学习,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47278518/
// Assuming that data are on the CPU initially, and we have a blob. const Dtype* foo; Dtype* bar;
我计划使用 NYU depth v2 数据集实现一个 CNN,它可以从单个图像估计深度。通过本教程,我了解到在 Caffe 上实现处理分类问题的 CNN 很容易。我很好奇 Caffe 是否适合涉及多维
我用图像训练了一个模型。现在想将 fc-6 功能提取到 .npy 文件中。我正在使用 caffe.set_mode_gpu() 运行 caffe.Classifier 并提取特征。 而不是每帧提取和保
我通过 apt install 命令在我的 Ubuntu v18 VM 上安装了 caffe-cpu。我正在努力找出安装目录所在的位置,如果我错了请纠正我,但我相信没有安装目录。我尝试执行的 NN 模
这个问题在这里已经有了答案: how to calculate a net's FLOPs in CNN [closed] (4 个回答) 4年前关闭。 我在tensorflow tutorial看到
似乎this related PR现在已经死了,有没有解决方法可以使用 early stopping在咖啡厅?也许在 Caffe 之上使用 Python? 最佳答案 第一部分很容易手动完成:让我们监控
当我尝试在MacbookPro(El Capitan)上安装最新的caffe时,出现以下错误。怎么了?如何解决? 我在此网站上发现了一些类似的问题,不幸的是显示的修复似乎是ubuntu特有的。 先感谢
average_loss有什么用?有人可以举一个例子或用外行的术语解释吗? 最佳答案 您可以登录 caffe.proto文件。当前版本中的第 151 行对 average_loss 给出了以下注释:
我想先分别处理不同类型的数据,然后将它们融合到一个公共(public)层中。这在 Caffe 中是否可行,如果可以,最好的方法是什么? 我读过可以在同一个 prototxt 文件中定义多个数据层。但是
我正在尝试将几个底部 Blob 合并为一个顶部 Blob ,然后将其馈送到下一层。 这些 Blob 来自不同的卷积/FC层,因此它们的形状不同。 我尝试了 concat 层,但使用轴 0 或 1 时,
包 Digits 需要使用 Caffe 安装目录的位置设置环境变量。 安装Caffe的简单方法是apt-get install caffe-cuda .但是,我无法弄清楚它的安装位置。没有安装在hom
我在 Caffe 中训练过 imagenet。现在我正在尝试为我的模型和 caffe 提供的训练模型计算 ROC/AUC。我有两个问题: 1) ROC/AUC 主要用于二进制类,但我也发现在某些情况下
我正在尝试使我的 Caffe 代码适应 tensorflow。我想知道将我的 train.txt 和 test.txt 转换为适用于 tensorflow 的最佳方法是什么。 在我的 train.tx
有没有办法安装/运行修改后的 Caffe 项目,例如 SegNet或FCN-Berkley-Vision在 Windows 上? 有Microsoft-led project to bring Caf
我想用python设置一个caffe CNN,使用caffe.NetSpec()界面。虽然我看到我们可以把测试网放在 solver.prototxt , 我想写在model.prototxt具有不同的
我有一个预训练的 faster-rcnn caffemodel。我可以使用 net.params[pr][0].data 获取模型的权重。到目前为止,权重是 numpy float32 类型。我想将它
我正在做一个将 keras json 模型转换为 caffe prototxt 的项目 caffe 支持任意填充值 keras(在 tensorflow 之上)支持“相同”和“有效”值 对于 caff
我正在尝试让 CaffeOnSpark 在本地运行,并且我按照 CaffeOnSpark wiki 上的此过程进行操作:https://github.com/yahoo/CaffeOnSpark/wi
我通过caffe使用我自己的数据集训练了网络,现在我想用C++写一个分类代码。我的机器 (linux) 仅适用于 CPU! (我使用 GPU 在 VM 中训练网络)。 当我尝试“包含”特定的 Caff
我知道可以(以编程方式)使用 caffe.Netspec() 设计一个网络,基本上主要目的是编写它的 prototxt。 net = caffe.NetSpec() .. (define) .. wi
我是一名优秀的程序员,十分优秀!