C:\Users\Surperman\anaconda3\envs\pytorch\python.exe C:\Users\Surperman\PycharmProjects\pythonProject\糖尿病遗传风险监测\DNN\train.py Setting up a new session... Traceback (most recent call last): File "C:\Users\Surperman\PycharmProjects\pythonProject\糖尿病遗传风险监测\DNN\train.py", line 123, in <module> train() File "C:\Users\Surperman\PycharmProjects\pythonProject\糖尿病遗传风险监测\DNN\train.py", line 30, in train wind.line([{0., 0.}], [0.], win='train', opts=dict(title='loss&mae', legend=['loss', 'mae'])) File "C:\Users\Surperman\anaconda3\envs\pytorch\lib\site-packages\visdom\__init__.py", line 414, in wrapped_f return f(*args, **kwargs) File "C:\Users\Surperman\anaconda3\envs\pytorch\lib\site-packages\visdom\__init__.py", line 1842, in line return self.scatter( File "C:\Users\Surperman\anaconda3\envs\pytorch\lib\site-packages\visdom\__init__.py", line 414, in wrapped_f return f(*args, **kwargs) File "C:\Users\Surperman\anaconda3\envs\pytorch\lib\site-packages\visdom\__init__.py", line 1766, in scatter return self._send(data_to_send, endpoint=endpoint) File "C:\Users\Surperman\anaconda3\envs\pytorch\lib\site-packages\visdom\__init__.py", line 760, in _send data=json.dumps(msg), File "C:\Users\Surperman\anaconda3\envs\pytorch\lib\json\__init__.py", line 231, in dumps return _default_encoder.encode(obj) File "C:\Users\Surperman\anaconda3\envs\pytorch\lib\json\encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\Users\Surperman\anaconda3\envs\pytorch\lib\json\encoder.py", line 257, in iterencode return _iterencode(o, 0) File "C:\Users\Surperman\anaconda3\envs\pytorch\lib\json\encoder.py", line 179, in default raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type set is not JSON serializable Process finished with exit code 1
时间: 2023-07-17 20:10:40 浏览: 115
这段代码出现了一个错误,错误提示为"TypeError: Object of type set is not JSON serializable"。这是因为在wind.line函数的参数中,将一个集合类型set[{0., 0.}]传递给了函数,而JSON序列化不支持直接将set类型转换为JSON格式。
要解决这个问题,你可以将集合类型set转换为列表类型list,并将其作为参数传递给wind.line函数。修改后的代码如下:
```python
wind.line([[0., 0.]], [0.], win='train', opts=dict(title='loss&mae', legend=['loss', 'mae']))
```
这样就可以避免上述错误,并成功绘制折线图了。
阅读全文