小编Bit*_*ver的帖子

Caffe中的欧几里德损失层

我目前正在尝试在caffe中实现我自己的损失层,并且在尝试这样做时,我正在使用其他层作为参考.然而,令我困惑的一件事是使用top[0]->cpu_diff()in Backward_cpu.我将使用它EuclideanLossLayer作为参考.这是我的问题

  • 我的理解是top[0]->cpu_diff()保留了下一层的误差导数,但是如果没有其他层,它是如何初始化的呢?因为它在EuclideanLossLayer没有进行任何检查的情况下使用:

    const Dtype alpha = sign * top[0]->cpu_diff()[0] / bottom[i]->num();
    
    Run Code Online (Sandbox Code Playgroud)
  • 同样,在中EuclideanLossLayer,使用以下代码片段计算与激活有关的错误的派生:

    const Dtype alpha = sign * top[0]->cpu_diff()[0] / bottom[i]->num();
    caffe_cpu_axpby(
      bottom[i]->count(),              // count
      alpha,                              // alpha
      diff_.cpu_data(),                   // a
      Dtype(0),                           // beta
      bottom[i]->mutable_cpu_diff());  // b
    
    Run Code Online (Sandbox Code Playgroud)

    如果我的第一个假设是正确的,并且top[0]->cpu_diff()确实保留了上面层的误差导数,为什么我们只使用第一个元素top[0]->cpu_diff()[0],而不是乘以整个向量即top[0]->cpu_diff()

c++ deep-learning caffe

8
推荐指数
1
解决办法
5143
查看次数

创建预先实现的java类的对象比创建自定义对象快得多?

class DummyInteger {
    private int i;
    public DummyInteger(int i) {
        this.i = i;
    }
    public int getI() {
        return i;
    }
}

long start = System.nanoTime();
DummyInteger n = new DummyInteger(10);
long end = System.nanoTime();
long duration = end - start;
System.out.println(duration);
Run Code Online (Sandbox Code Playgroud)

前面的代码生成以下输出:

341000
Run Code Online (Sandbox Code Playgroud)

鉴于:

long start = System.nanoTime();
ArrayList a = new ArrayList();
long end = System.nanoTime();
long duration = end - start;
System.out.println(duration);
Run Code Online (Sandbox Code Playgroud)

产生以下输出:

17000
Run Code Online (Sandbox Code Playgroud)

现在,我的问题是,为什么我们在运行时间中观察到这种差异,即使DummyIntegerClass 所做的工作最多似乎与ArrayList构造函数所执行的工作一样多?是否与预编译的ArrayList代码有关?或者是影响处理时间的其他因素?

谢谢.

- 编辑 -

我认为比较两种不同类型的对象的问题会出现,但是,即使使用以下代码,与创建一个对象相比ArrayList: …

java oop performance

0
推荐指数
1
解决办法
132
查看次数

标签 统计

c++ ×1

caffe ×1

deep-learning ×1

java ×1

oop ×1

performance ×1