我正在训练 PyTorch 模型来执行二元分类。我的少数群体约占数据的 10%,所以我想使用加权损失函数。的文档BCELoss说CrossEntropyLoss我可以为每个示例使用 a 'weight'。
但是,当我声明CE_loss = nn.BCELoss()ornn.CrossEntropyLoss()然后 do CE_Loss(output, target, weight=batch_weights), where output, target, and batch_weightsare Tensors of 时batch_size,我收到以下错误消息:
forward() got an unexpected keyword argument 'weight'
Run Code Online (Sandbox Code Playgroud) I use the brokenaxes package (https://github.com/bendichter/brokenaxes) to break the y-axis (//). Now I want a second Y-axis, which should also be broken (//) just like the first one.
How do I do this in the following example?
import numpy as np
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
fig, ax = plt.subplots()
plt.gca().axes.get_yaxis().set_visible(False)
bax = brokenaxes(ylims=((0, 1.1), (60, 80)), hspace=.05)
x = np.linspace(0, 1, 100)
bax.plot(x, 5 * np.sin(10 * x) + 70)
bax.plot(x, 0.25* np.cos(40 * …Run Code Online (Sandbox Code Playgroud) 我一定在使用 fast-ai 库时遇到了严重问题,因为我似乎是唯一遇到此问题的人。每次我尝试学习率查找器或训练网络时,它都会给我一个错误。我花了一周时间才产生这个特定的错误信息,这让我检查了掩码值。事实证明,背景像素为 0,前景像素为 255。这是一个问题,因为我只有两个类。如何在我的 Databunch 对象中将 255 个值更改为 1?有没有办法将每个掩码值除以 255 或者我是否需要事先以某种方式进行?我有点迷失在这个过程中。
这是我收到的错误消息:
LR Finder is complete, type {learner_name}.recorder.plot() to see the graph.
---------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
LR Finder is complete, type {learner_name}.recorder.plot() to see the graph.
---------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
这也是我设置数据的方式:
RuntimeError Traceback (most recent call last)
<ipython-input-20-c7a9c29f9dd1> in <module>()
----> 1 learn.lr_find()
2 learn.recorder.plot()
8 frames
/usr/local/lib/python3.6/dist-packages/fastai/train.py in lr_find(learn, start_lr, end_lr, num_it, stop_div, wd)
39 cb = LRFinder(learn, start_lr, end_lr, num_it, stop_div)
40 epochs = int(np.ceil(num_it/len(learn.data.train_dl)))
---> 41 learn.fit(epochs, start_lr, callbacks=[cb], wd=wd)
42
43 …Run Code Online (Sandbox Code Playgroud) 我有一个带有 PyTorch 和 Tensorflow 的 conda 环境,它们都需要 CUDA 9.0(来自 conda 的~cudatoolkit 9.0)。在使用torchvision和cudatoolkit(就像他们在他们的网站上提供的)安装pytorch之后,我想安装Tensorflow,这里的问题是我收到这个错误:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: /
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failed
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment: …Run Code Online (Sandbox Code Playgroud) 我使用一些类似于以下的代码 - 用于数据增强:
from torchvision import transforms
#...
augmentation = transforms.Compose([
transforms.RandomApply([
transforms.RandomRotation([-30, 30])
], p=0.5),
transforms.RandomHorizontalFlip(p=0.5),
])
Run Code Online (Sandbox Code Playgroud)
在测试过程中,我想修复随机值,以在每次更改模型训练设置时重现相同的随机参数。我该怎么做?
我想做类似的事情,np.random.seed(0)所以每次我第一次以概率调用随机函数时,它将以相同的旋转角度和概率运行。换句话说,如果我根本不更改代码,那么当我重新运行它时,它必须重现相同的结果。
或者,我可以单独进行变换,使用p=1,将角度min和固定max为特定值,并使用 numpy 随机数来生成结果,但我的问题是我是否可以保持上面的代码不变。
pytorch ×4
python ×2
conda ×1
fast-ai ×1
mask ×1
matplotlib ×1
tensorflow ×1
torch ×1
torchvision ×1