零碎的问题及解决

import keras 的时候 遇到 No module named ‘tensorflow.python’

解决:重装tensorflow


读CSV文件时,报错UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xbf in position 2: illegal multibyte sequence

解决:open(csv_path, 'r', encoding='UTF-8')

用utf-8编码时,print出来的csv开头有\ufeff,因此encoding应该为‘UTF-8-sig’


读CSV文件时,报错’utf-8’ codec can’t decode byte 0xb4 in position 0: invalid start byte

解决:保存时 加 encoding=’UTF-8’或’UTF-8-sig’


pytorch load 预训练模型的时候
报错:
Missing key(s) in state_dict: “network.0.conv.weight”, ……
Unexpected key(s) in state_dict: “module.network.0.conv.weight”, ……
是用torch0.4.1版本训练,用0.4.0版本预测的时候报的异常 ??
解决:

1
model.load_state_dict({k.replace('module.',''):v for k,v in torch.load(checkpoint_path)['state_dict'].items()})

Python 报错NotImplementedError
在面向对象编程中,可以先预留一个方法接口不实现,在其子类中实现。如果要求其子类一定要实现,不实现的时候会导致问题,那么采用raise的方式就很好。而此时产生的问题分类 是NotImplementedError。


pytorch: ‘list’ object has no attribute ‘cuda’


pytorch: cuda runtime error(59) in loss.backward()
From the error message it looks like you are using indexing with wrong indices.
A good way to debug these errors is to simply run the exact same code on CPU( model.cpu()), that way you will get a proper stack trace with the exact line that crashed.


pytorch: Assertion cur_target >= 0 && cur_target < n_classes failed
label 从0开始