- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
关于如何像在 Torch 中一样在 Caffe 中实现空间反射填充有什么想法吗?
(x): nn.SpatialReflectionPadding(l=1, r=1, t=1, b=1)
(x): nn.SpatialConvolution(64 -> 64, 3x3)
(x): nn.ReLU
最佳答案
一种方法是使用 Python Layer咖啡。然后您可以自己设置功能并根据您的需要进行自定义。但是,该层只能在 CPU 中运行,因此它可能会降低您的模型速度,尤其是当您在网络中间使用它时。
在下文中,我使用 Python 层定义了一个零填充输入层,您可以对其进行修改以满足您的需要:
import caffe
import numpy as np
class SpatialReflectionPadding(caffe.Layer):
def setup(self,bottom,top):
if len(bottom) != 1: # check that a single bottom blob is given
raise Exception("Expected a single blob")
if len(bottom[0].shape) != 4: # check that it is 4D
raise Exception("Expected 4D blob")
params = eval(self.param_str) # get the params given in the prototxt
self.l = params["l"]
self.r = params["r"]
self.t = params["t"]
self.b = params["b"]
def reshape(self,bottom,top):
top[0].reshape(bottom[0].shape[0],bottom[0].shape[1],bottom[0].shape[2]+self.t+self.b,bottom[0].shape[3]+self.r+self.l) # set the shape of the top blob based on the shape of the existing bottom blob
def forward(self,bottom,top):
for i in range(0,top[0].shape[2]):
for j in range(0,top[0].shape[3]):
if (i < self.t or i >= self.t+bottom[0].shape[2]) or (j < self.l or j >= self.l+bottom[0].shape[3]):
top[0].data[:,:,i,j] = 0 # for the padded part, set the value to 0
else:
top[0].data[:,:,i,j] = bottom[0].data[:,:,i-self.t,j-self.l] # for the rest, copy the value from the bottom blob
def backward(self,top,propagate_down,bottom):
bottom[0].diff[...] = np.full(bottom[0].shape,1) * top[0].diff[:,:,self.t:self.t+bottom[0].shape[2],self.l:self.l+bottom[0].shape[3]] # set the gradient for backward pass
然后,在您的 prototxt 文件中,您可以将其用作:
layer {
name: "srp" # some name
type: "Python"
bottom: "some_layer" # the layer which provides the input blob
top: "srp"
python_param {
module: "caffe_srp" # whatever is your module name
layer: "SpatialReflectionPadding"
param_str: '{ "l": 1, "b": 1, "t": 1, "r": 1}'
}
}
我不能 100% 确定它是否正常工作,但当我使用它时,它似乎确实如此。无论如何,它应该给出一个想法和一个关于如何进行的起点。另外,您可以引用this question and its answers .
关于neural-network - Caffe 中的空间反射填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44830512/
我正在使用AWS中的VM设置Elasticsearch集群。 我知道每个节点都会自动尝试加入一个在同一网络中具有相同群集名称的现有群集。 但是,我无法理解“同一网络” 是什么。 为了了解同一网络,我发
我尝试部署一个已经存在于 Kovan 网络上的合约实例,以通过 web3 和 metamask 与其交互。 首先,我将 metamask 设置为我的当前提供者,然后我部署了一个合约实例,如下所示:
停止 docker 后,它拒绝重新启动。它提示另一个名为 docker0 的网桥已经存在: level=warning msg="devmapper: Base device already exis
我正在使用“docker network create --d bridge mynet”创建一个 docker 网络。我想获取与此 docker 网络关联的网桥名称。 我知道我可以使用“-o”来提供
我的一位同事的VPN连接有问题。似乎他的操作系统重设了代理设置,并且他需要手动将其更改回。有没有办法使用Powershell设置VPN和代理? 他正在使用Windows 7,因此可以使用Powersh
我在 Azure VM 中有一个虚拟机,我想获取网络输入/网络输出指标。 在 Azure 门户中,我将诊断设置和指标设置为存储到选定的存储表中。但存储的指标与我在 Azure 门户中看到的指标之间存在
我有一个用例,我的 Docker 容器的第二个接口(interface)需要共享主机的第二个网络接口(interface)的接口(interface)。这可能使用 docker network con
我在 Azure VM 中有一个虚拟机,我想获取网络输入/网络输出指标。 在 Azure 门户中,我将诊断设置和指标设置为存储到选定的存储表中。但存储的指标与我在 Azure 门户中看到的指标之间存在
我想了解一些关于 Docker 的事情: 如何找到我的容器所在的网络? 我可以动态分离我的容器并附加到其他网络吗?怎么样? 如果我有两个容器正在运行,如何检查这两个容器是否在同一个网络?我可以 pin
我已经开发了一款使用Reaction Native和世博会的应用程序,并想在它的末尾添加一个横幅广告。当我在Android模拟器上的开发版本上运行应用程序时,应用程序的其余部分在没有应用程序的情况下运
我已经编辑了 eth0,但我犯了一个错误,我的 VPS 现在处于脱机状态,甚至无法连接到 ssh,并在故障恢复控制台显示以下消息: “网络不可达”。 配置/编辑网络的命令是什么!? Photo 最佳答
今天早上我启动了我的 GCE 实例,并且 4/6 完全无法访问。所有这些都在同一个 us-east1-d 区域中。 SSH 连接也无法正常工作,因此我使用串行控制台连接到有问题的实例之一。 当我尝试
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 5年前关闭。 Improve this qu
我正在使用 Network.Browser 4000.0.9 检索网页: import Network.Browser import Network.HTTP main = do (uri
我正在尝试更新我在 docker 容器中的 apt 存储库,但我做不到。 docker run -it --dns 8.8.8.8 --dns 8.8.4.4 debian apt-get 更新 ..
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
Axios 是否可以区分以下内容: 由于客户端没有网络连接而失败的请求发出请求的时间 - (ERR_CONNECTION_REFUSED)。 由于网络连接丢失而失败的请求之后已发出请求,但在收到响应之
Unity 已升级其网络系统,并将旧网络称为遗留网络。 那么我们如何将 RPC 调用更改为新的 Unity Networking?这种方法的等价物是什么?我们应该为它编写自己的方法吗? (发送字节数组
在机器学习工具 vowpal wabbit ( https://github.com/JohnLangford/vowpal_wabbit/ ) 中,通常训练线性估计器 y*=wx。但是,可以添加前向
我正在尝试将 Boost 用于某些 IPv6 和多播网络通信。我需要构建一个使用特定网络接口(interface)索引的 IPv6 多播套接字。 我能够在 boost/asio/ip/detail/s
我是一名优秀的程序员,十分优秀!