0% 0/20 [00:01<?, ?it/s] --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-155-26d05ea2d790> in <cell line: 6>() 4 5 # compute the losses over the main directions of the gradient updates ----> 6 x, y, Z, _ = get_loss_grid(net, data_loader, loss_fn, directions=directions, resolution=(20, 20), scale=loss_coordinates.abs().max().item()) 7 8 # plot the landscape as a contour plot 1 frames /usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py in __getattr__(self, name) 1612 if name in modules: 1613 return modules[name] -> 1614 raise AttributeError("'{}' object has no attribute '{}'".format( 1615 type(self).__name__, name)) 1616 AttributeError: 'Softmax' object has no attribute 'out_features'这个错误怎么修改·
时间: 2023-08-15 16:42:32 浏览: 115
这个错误提示是在调用 `get_loss_grid()` 函数时出现的,具体是因为在该函数内部调用了模型的 `out_features` 属性,但是模型是 `Softmax` 类型的,该类并没有 `out_features` 属性。要解决这个问题,你可以在使用该函数之前检查模型的类型,如果是 `Softmax` 类型,则需要将其转换为能够使用 `out_features` 属性的类型,例如 `nn.Linear` 类型。你可以在模型定义时进行修改,或者在调用 `get_loss_grid()` 函数前对模型进行修改。
相关问题
优化以下SQL语句使该语句可以在MySQL5.0中可以运行:select sum(max(TRUNCATE(cast(t0.disk_space_utilization as decimal(30,8)), 0))) over ( order by max(TRUNCATE(cast(t0.disk_space_utilization as decimal(30,8)), 0)))*1.0/100 as calc from (SELECT a.sync_time, a.equipment_monitor_id, a.equipment_id, a.cpu_load, a.memory_load, a.disk_space, a.disk_space_utilization, a.network_card_throughput, a.control_unit_temperature FROM nec_equipment_monitor_statistics a order by a.sync_time) t0 where (t0.equipment_id='IT-A01-32' AND str_to_date(t0.sync_time,'%Y-%m-%d %H:%i:%s')>=str_to_date('20230519','%Y%m%d') and str_to_date(t0.sync_time,'%Y-%m-%d %H:%i:%s')<str_to_date('20230520','%Y%m%d'))
MySQL 5.0 不支持窗口函数和子查询中的 ORDER BY 子句,因此需要对该 SQL 语句进行重构。我们可以使用 GROUP BY 和 JOIN 来替代窗口函数和子查询中的 ORDER BY 子句。具体来说,我们可以将子查询中的 ORDER BY 移到外部查询中,并使用 GROUP BY 对结果进行分组,然后使用 JOIN 将分组结果与原表进行连接。下面是重构后的 SQL 语句:
```
SELECT SUM(MAX(TRUNCATE(CAST(t.disk_space_utilization AS DECIMAL(30,8)), 0))) * 1.0/100 AS calc
FROM (
SELECT a.equipment_id, MAX(TRUNCATE(CAST(a.disk_space_utilization AS DECIMAL(30,8)), 0)) AS max_utilization
FROM nec_equipment_monitor_statistics a
WHERE a.equipment_id = 'IT-A01-32'
AND STR_TO_DATE(a.sync_time,'%Y-%m-%d %H:%i:%s') BETWEEN '2023-05-19 00:00:00' AND '2023-05-20 00:00:00'
GROUP BY a.equipment_id
) t
JOIN nec_equipment_monitor_statistics s ON t.equipment_id = s.equipment_id AND TRUNCATE(CAST(s.disk_space_utilization AS DECIMAL(30,8)), 0) = t.max_utilization;
```
需要注意的是,由于 MySQL 5.0 不支持 CAST 函数的 DECIMAL 类型参数,因此需要将 DECIMAL(30,8) 修改为 DECIMAL。
select sum(max(TRUNCATE(cast(t0.disk_space_utilization as decimal(30,8)), 0))) over ( order by max(TRUNCATE(cast(t0.disk_space_utilization as decimal(30,8)), 0)))*1.0/100 as calc from (SELECT a.sync_time, a.equipment_monitor_id, a.equipment_id, a.cpu_load, a.memory_load, a.disk_space, a.disk_space_utilization, a.network_card_throughput, a.control_unit_temperature FROM nec_equipment_monitor_statistics a order by a.sync_time) t0 where (t0.equipment_id='IT-A01-32' AND str_to_date(t0.sync_time,'%Y-%m-%d %H:%i:%s')>=str_to_date('20230519','%Y%m%d') and str_to_date(t0.sync_time,'%Y-%m-%d %H:%i:%s')<str_to_date('20230520','%Y%m%d')) 优化sql,是该语句在mysql5.0中可以正常运行。
这个 SQL 语句看起来比较复杂,但是可以进行优化。首先,我们可以使用别名来简化代码,使用 `t` 代替 `t0`。其次,可以将子查询中的排序移动到外部查询中,这样可以避免在子查询中进行排序操作,提高查询效率。最后,我们可以将字符串转换为日期时间类型,这样可以避免在每次比较时进行转换。下面是优化后的 SQL 语句:
```
SELECT SUM(MAX(TRUNCATE(CAST(t.disk_space_utilization AS DECIMAL(30,8)), 0))) OVER() * 1.0/100 AS calc
FROM (
SELECT
a.sync_time,
a.equipment_monitor_id,
a.equipment_id,
a.cpu_load,
a.memory_load,
a.disk_space,
a.disk_space_utilization,
a.network_card_throughput,
a.control_unit_temperature
FROM nec_equipment_monitor_statistics a
WHERE a.equipment_id = 'IT-A01-32'
AND STR_TO_DATE(a.sync_time,'%Y-%m-%d %H:%i:%s') BETWEEN '2023-05-19 00:00:00' AND '2023-05-20 00:00:00'
) t;
```
注意,这个 SQL 语句在 MySQL 5.0 中可能无法运行,因为一些函数或语法可能不支持。如果需要在 MySQL 5.0 中运行,需要根据具体情况进行调整。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![tar](https://img-home.csdnimg.cn/images/20250102104920.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)