attention_map_normalized_opt = tf.zeros_like(attention_map) for i in range(attention_map.shape[3]): channel = attention_map[:, :, :, i] # channel = np.reshape(attention_map[:, :, i],14,14) # for j in range(attention_map.shape[0]): #14*14 # max_value = np.max(channel) threshold = tf.contrib.distributions.percentile(channel,60)# yu zhi wei 60%,she qu xia yu 60%de bu fen threshold1 = np.full((14,14),threshold) print(channel,type(channel)) print(threshold1,type(threshold1)) normalized_channel = tf.where(channel >= threshold1, channel, 0) attention_map_normalized_opt = tf.concat([attention_map_normalized_opt[:, :, :i], tf.expend_dims(normalized_channel, axis=-1), attention_map_normalized_opt[:, :, i+1:]], axis=-1)有哪些错误,帮我改过来
时间: 2024-03-09 09:49:51 浏览: 216
在这段代码中,有几个错误:
1. `tf.expend_dims` 应该是 `tf.expand_dims`,这是一个打错字的错误。
2. `tf.concat` 中的 `tf.expend_dims(normalized_channel, axis=-1)` 应该修改为 `tf.expand_dims(normalized_channel, axis=-1)`。
3. `threshold1` 应该被转换为 `tf.constant`,以与 `channel` 和其他张量的类型匹配。
4. `attention_map_normalized_opt = tf.concat([attention_map_normalized_opt[:, :, :i], tf.expend_dims(normalized_channel, axis=-1), attention_map_normalized_opt[:, :, i+1:]], axis=-1)` 中的 `tf.expend_dims` 应该改为 `tf.expand_dims`。
下面是修改后的代码:
```
attention_map_normalized_opt = tf.zeros_like(attention_map)
for i in range(attention_map.shape[3]):
channel = attention_map[:, :, :, i]
threshold = tf.contrib.distributions.percentile(channel, 60)
threshold1 = tf.constant(np.full((14, 14), threshold))
normalized_channel = tf.where(channel >= threshold1, channel, 0)
attention_map_normalized_opt = tf.concat([attention_map_normalized_opt[:, :, :i], tf.expand_dims(normalized_channel, axis=-1), attention_map_normalized_opt[:, :, i+1:]], axis=-1)
```
阅读全文