error: Resource at touchFocusParameter appears in overlay but not in the base package; use to add.

本文介绍了解决Android开发过程中遇到的资源叠加错误方法。当在自定义资源文件中定义了在基本包中未出现的资源时,会触发该错误。文章提供了一种通过使用<add-resource>标签来解决这一问题的有效方案。

error: Resource at touchFocusParameter appears in overlay but not in the base package; use to add.

target R.java/Manifest.java: Camera (out/target/common/obj/APPS/Camera_intermediates/src/R.stamp)
device/htc/bravo/overlay/packages/apps/Camera/res/values/config.xml:24: error: Resource at touchFocusParameter appears in overlay but not in the base package; use <add-resource> to add.
make: *** [out/target/common/obj/APPS/Camera_intermediates/src/R.stamp] Error 1
jay@shelley:~/android/gingerbread$

修改文件:

<resources>
    <!-- Autofocus parameters -->
    <string name="touchFocusParameter">touch-focus</string>
</resources>
<resources>
    <!-- Autofocus parameters -->
    <add-resource type="string" name="touchFocusParameter" />
    <string name="touchFocusParameter">touch-focus</string>
</resources>


红色部分为添加部分。
采取了 http://www.poemcode.net/2010/09/android-sdk-addon/  中 添加 Overlay(Add Resoruce) 的解释。


http://developer.android.com/guide/topics/resources/available-resources.html



在使用 PyTorch 进行模型训练时,如果遇到如下错误: ``` RuntimeError: One of the differentiated Tensors appears to not have been used in the graph. Set allow_unused=True if this is the desired behavior. ``` 该错误通常出现在调用 `torch.autograd.grad()` 或 `loss.backward()` 时,表示某个需要计算梯度的张量(Tensor)并未实际参与当前计算图中的运算。PyTorch 的自动求导机制要求所有需要计算梯度的张量都必须参与前向传播中的运算,否则会抛出此异常。 ### 错误原因 - **张量未参与计算**:某个传入 `grad_tensors` 或 `inputs` 的张量在前向传播中没有被用于任何计算。 - **梯度传播路径断开**:张量在计算过程中被分离(如使用了 `.detach()`)或未被追踪(未设置 `requires_grad=True`)。 - **多输出模型中部分输出未被使用**:在模型具有多个输出的情况下,某些输出可能未被用于梯度计算。 ### 解决方案 - **设置 `allow_unused=True`**:如果确实存在某些张量未参与计算是预期行为,可以在调用 `torch.autograd.grad()` 时设置 `allow_unused=True`,例如: ```python torch.autograd.grad(outputs=output, inputs=input_tensor, allow_unused=True) ``` 该参数会允许某些输入张量未被使用而不抛出异常[^1]。 - **检查张量是否参与计算**:确保所有需要计算梯度的张量在前向传播过程中被使用。可以通过打印计算图或调试方式检查张量的流向。 - **避免使用 `.detach()` 或 `torch.no_grad()` 包裹涉及梯度计算的部分**:这些操作会阻止梯度传播,导致张量未被追踪。 - **多输出模型处理**:确保所有输出张量都参与损失计算,或在调用 `backward()` 时指定 `grad_tensors` 并合理设置其值。 ### 示例代码 以下是一个使用 `allow_unused=True` 的示例: ```python import torch x = torch.randn(3, requires_grad=True) y = x * 2 z = y[0] # z 只依赖于 x[0] grads = torch.autograd.grad(z, x, allow_unused=True) print(grads) # 输出类似 (tensor([2., 0., 0.]),) ``` 在这个例子中,`x[1]` 和 `x[2]` 没有参与 `z` 的计算,但由于设置了 `allow_unused=True`,程序不会抛出异常,而是返回对应的梯度为 `0`。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值