首页 文章

张量流是如何进行CNN计算的?

提问于
浏览
1

在学习CNN时,我觉得这个博客很受欢迎

他使用C语言做cnn,这是参考Matlab DeepLearnToolbox cnn . 代码就像吹

//---forward Propagation,InputData is image data
void cnnff(CNN* cnn,float** inputData)
{
    int outSizeW=cnn->S2->inputWidth;
    int outSizeH=cnn->S2->inputHeight;
    int i,j,r,c;

    //---the first,convolution C1
    nSize mapSize={cnn->C1->mapSize,cnn->C1->mapSize};
    nSize inSize={cnn->C1->inputWidth,cnn->C1->inputHeight};
    nSize outSize={cnn->S2->inputWidth,cnn->S2->inputHeight};
    for(i=0;i<(cnn->C1->outChannels);i++){
        for(j=0;j<(cnn->C1->inChannels);j++){
            float** mapout=cov(cnn->C1->mapData[j][i],mapSize,inputData,inSize,valid);
            addmat(cnn->C1->v[i],cnn->C1->v[i],outSize,mapout,outSize);
            for(r=0;r<outSize.r;r++)
                free(mapout[r]);
            free(mapout);
        }
        for(r=0;r<outSize.r;r++)
            for(c=0;c<outSize.c;c++)
                cnn->C1->y[i][r][c]=activation_Sigma(cnn->C1->v[i][r][c],cnn->C1->basicData[i]);
    }

    //the second,pooling S2
    outSize.c=cnn->C3->inputWidth;
    outSize.r=cnn->C3->inputHeight;
    inSize.c=cnn->S2->inputWidth;
    inSize.r=cnn->S2->inputHeight;
    for(i=0;i<(cnn->S2->outChannels);i++){
        if(cnn->S2->poolType==AvePool)
            avgPooling(cnn->S2->y[i],outSize,cnn->C1->y[i],inSize,cnn->S2->mapSize);
    }
}

这段代码我可以看到输入图像卷积和合并后的值如何改变以及有多少特征映射 . 那么,我可以在Tensorflow上看到这样吗?

我在tensorflow \ python \ client \ session.py上跟踪Tensorflow代码,代码就像打击一样

def _run_fn(session, feed_dict, fetch_list, target_list, options,
            run_metadata):
  # Ensure any changes to the graph are reflected in the runtime.
  self._extend_graph()
  with errors.raise_exception_on_not_ok_status() as status:
    if self._created_with_new_api:
      return tf_session.TF_SessionRun_wrapper(
          session, options, feed_dict, fetch_list, target_list,
          run_metadata, status)
    else:
      return tf_session.TF_Run(session, options,
                               feed_dict, fetch_list, target_list,
                               status, run_metadata)

当函数“tf_session.TF_Run”时,它只返回(loss,Accuracy),但是看不到值如何改变 .

然后我在C:\ Users \ xxx \ AppData \ Local \ Continuum \ Anaconda3 \ envs \ tensorflow1 \ Lib \ site-packages \ tensorflow \ python \ pywrap_tensorflow_internal.py中跟踪Tensorflow代码,代码就像打击一样

def TF_Run(session, run_options, feed_dict, output_names, target_nodes, out_status, run_outputs):
    return _pywrap_tensorflow_internal.TF_Run(session, run_options, feed_dict, output_names, target_nodes, out_status, run_outputs)
TF_Run = _pywrap_tensorflow_internal.TF_Run

pywrap_tensorflow_internal.py使用_pywrap_tensorflow_internal.pyd,我认为如何更改的值是在这个.pyd上 . 那么,这个.pyd源代码在哪里?因为这个.pyd只能通过“pip install tensorflow”下载 .

2 回答

  • 0

    pyd文件是相似的Windows动态库 .

    这有助于:https://stackabuse.com/differences-between-pyc-pyd-and-pyo-python-files/

    也许你需要了解tensorflow是如何从头开始编译的,以便了解你所有的麻烦.pyd;)

  • 0

    我想你的意思是你想知道如何实现 tf.nn.conv2d 和排序 . 如果您注意到 layers (例如 tf.layers.conv2d )和 nn (例如 tf.nn.conv2d ) . layers 都是 nn 的包装器,所以如果你只是想立即进入实现,请忽略 layers .

    现在,如果您阅读documentation for tf.nn.conv2d,它会说:

    在生成的文件中定义:tensorflow / python / ops / gen_nn_ops.py .

    仅作比较,看一下documentation for tf.nn.conv2d_transpose,其中说:

    在tensorflow / python / ops / nn_ops.py中定义 .

    现在,如果单击 tensorflow/python/ops/nn_ops.py ,它实际上会将您带到定义 tf.nn.conv2d_transpose 的文件 . 但对于您感兴趣的 tf.nn.conv2d ,此链接不存在 . 这是因为你可以在C中编写图层,让TensorFlow生成Python部分,因此在 generated file 中定义了文本 . 实际的实现分布在三个文件中:

相关问题