> For the complete documentation index, see [llms.txt](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-si-men-ke-juan-ji-shen-jing-wang-luo-convolutional-neural-networks/convolutional-neural-networks/special-applications/49-nei-rong-dai-jia-han-shu-ff08-content-cost-function.md).

# 4.8 内容代价函数（Content cost function）

$$J(G)$$的第一部分$$J\_{content}(C,G)$$，它表示内容图片C与生成图片G之间的相似度

使用的CNN网络是之前训练好的模型，例如Alex-Net。C，S，G共用相同模型和参数

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/d54256309adfc1e140390a334bfc49ee.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/d54256309adfc1e140390a334bfc49ee.png)

CNN的每个隐藏层分别提取原始图片的不同深度特征，由简单到复杂。如果$$l$$太小，则G与C在像素上会非常接近，没有迁移效果；如果$$l$$太深，则G上某个区域将直接会出现C中的物体。所以在实际中，层$$l$$在网络中既不会选的太浅也不会选的太深

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/5b63e8b0c5c991bc19838b709524b79d.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/5b63e8b0c5c991bc19838b709524b79d.png)

衡量内容图片和生成图片在内容上的相似度：

令$$a^{\[l]\[C]}$$和$$a^{\[l]\[G]}$$代表图片$$C$$和$$G$$的$$l$$层的激活函数值。如果这两个激活值相似，意味着两个图片的内容相似

定义：

$$
J\_{content}(C,G) =  \frac{1}{4 \times n\_H \times n\_W \times n\_C}\sum \_{ \text{all entries}} (a^{\[l]\[C]} - a^{\[l]\[C]})^2
$$

为两个激活值不同或者相似的程度

后面如果对$$J(G)$$做梯度下降来找$$G$$的值时，整个代价函数会激励这个算法来找到图像$$G$$，使得隐含层的激活值和内容图像的相似


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-si-men-ke-juan-ji-shen-jing-wang-luo-convolutional-neural-networks/convolutional-neural-networks/special-applications/49-nei-rong-dai-jia-han-shu-ff08-content-cost-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
