- 博客(11)
- 资源 (4)
- 收藏
- 关注
原创 Keras自定义IOU
def iou(y_true, y_pred, label: int): """ Return the Intersection over Union (IoU) for a given label. Args: y_true: the expected y values as a one-hot y_pred: the predicted...
2019-01-23 13:06:57 3228 18
转载 keras 指定显卡
import osos.environ["CUDA_VISIBLE_DEVICES"] = "2"转载:https://blog.csdn.net/A632189007/article/details/77978058
2019-01-23 13:03:50 783
转载 查看keras版本
pythonimport kerasprint(keras.__version__)转载:https://blog.csdn.net/pursuit_zhangyu/article/details/85309329
2019-01-23 13:02:14 9103
原创 pytorch交叉熵损失函数的weight参数
class_weight = torch.FloatTensor([0.13859937, 0.5821059, 0.63871904, 2.30220396, 7.1588294, 0]).cuda()必须将权重也转为Tensor的cuda格式。
2019-01-22 14:50:58 10043 7
原创 Pytorch之CrossEntropyLoss() 与 NLLLoss() 的区别
CrossEntropyLoss()输入:未做过softmax的预测结果(如(batch,class,h, w)) 未做one-hot 的真实标签其内部先做softmax,再取log,最后取负。NLLLoss()输入:做过logsoftmax的预测结果 未做one-hot 的真实标签其内部直接取负。...
2019-01-22 14:49:20 1164
原创 pytorch 在验证时出现CUDA error: out of memory
虽然使用net.eval()调到了验证阶段,但是还是要使用 with torch.no_grad(): outputs = Net_(inputs)来取消验证阶段的loss。个人猜测出现此原因是由于梯度在验证阶段不回传,造成梯度的累计。我做实验发现,在验证阶段,batch0不会报错,batch1就报错。...
2019-01-22 14:45:03 14670 14
原创 自定义的torch中与np.nanmean同功能的函数(只能做一维的)
def torch_nanmean(x): num = torch.where(torch.isnan(x), torch.full_like(x, 0), torch.full_like(x, 1)).sum() value = torch.where(torch.isnan(x), torch.full_like(x, 0), x).sum() return valu...
2019-01-22 10:43:40 2172 1
原创 np.where和torch.where的使用区别
两者都是三个输入参数,第一个是判断条件,第二个是符合条件的设置值,第三个是不满足条件的设置值。区别在于,torch要将设置值全部改为Tensor类型的mask_true = torch.where(torch.isnan(y_true), torch.full_like(y_true, 0), torch.full_like(y_true, 1))mask_true = np.w...
2019-01-22 10:41:21 31779
转载 Torch中和np.reshape相同功能的函数
>>> import torch>>> t = torch.ones((2, 3, 4))>>> t.size()torch.Size([2, 3, 4])>>> t.view(-1, 12).size()torch.Size([2, 12])转载:https://discuss.pytorch.org/t/e...
2019-01-22 10:36:27 811
原创 one of the variables needed for gradient computation has been modified by an inplace operation
Pytorch 运行错误:RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation主要原因是由原位运算操作引起的梯度反向传播的问题,检查代码中是否有 inplace=True 或者 x += y 这一类的原位操作,修改为inp...
2019-01-22 10:32:26 6181
转载 PyTorch中使用指定的GPU
转载请注明出处:http://www.cnblogs.com/darkknightzh/p/6836568.htmlPyTorch默认使用从0开始的GPU,如果GPU0正在运行程序,需要指定其他GPU。有如下两种方法来指定需要使用的GPU。1. 类似tensorflow指定GPU的方式,使用CUDA_VISIBLE_DEVICES。1.1 直接终端中设定:CUDA_...
2019-01-22 10:25:33 3704
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人