ebagdasa / backdoor_federated_learning

Source code for paper "How to Backdoor Federated Learning" (https://arxiv.org/abs/1807.00459)
MIT License
273 stars 65 forks source link

TypeError: Object of type 'Tensor' is not JSON serializable #10

Closed Brownchen closed 4 years ago

Brownchen commented 4 years ago

Thank you for publishing this nice work. It reports an error when I run the code at the function 'train()' in training.py, line 663. The following error displayed:

Traceback (most recent call last): File "D:/cmWorks/backdoor_federated_learning-master/training.py", line 667, in is_poison=helper.params['is_poison'], last_weight_accumulator=weight_accumulator) File "D:/cmWorks/backdoor_federated_learning-master/training.py", line 183, in train name='Classification Loss', win='poison') File "D:\cmWorks\backdoor_federated_learning-master\models\simple.py", line 43, in trainvis opts=dict(showlegend=True, width=700, height=400, title='Train loss{0}'.format(self.created_time))) File "E:\Anaconda3\envs\pyTorch\lib\site-packages\visdom__init.py", line 389, in wrapped_f return f(*args, *kwargs) File "E:\Anaconda3\envs\pyTorch\lib\site-packages\visdom__init.py", line 1715, in line update=update, name=name) File "E:\Anaconda3\envs\pyTorch\lib\site-packages\visdom\init__.py", line 389, in wrapped_f return f(args, **kwargs) File "E:\Anaconda3\envs\pyTorch\lib\site-packages\visdom__init.py", line 1640, in scatter return self._send(data_to_send, endpoint=endpoint) File "E:\Anaconda3\envs\pyTorch\lib\site-packages\visdom__init__.py", line 711, in _send data=json.dumps(msg), File "E:\Anaconda3\envs\pyTorch\lib\json\init__.py", line 231, in dumps return _default_encoder.encode(obj) File "E:\Anaconda3\envs\pyTorch\lib\json\encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "E:\Anaconda3\envs\pyTorch\lib\json\encoder.py", line 257, in iterencode return _iterencode(o, 0) File "E:\Anaconda3\envs\pyTorch\lib\json\encoder.py", line 180, in default o.class.name__) TypeError: Object of type 'Tensor' is not JSON serializable

It seems like the function "json.dumps()" can not fit the type of some "kwargs". Is it caused by the version's problems or something else?

Thanks a lot!

Brownchen commented 4 years ago

I finally fix it. The error is caused by "visdom". It would be alright by adding an "item()" after the "loss" argument when passing it to "visdom".