EBI*_*EPH 2 python opencv image keras pytorch
我曾经使用 keras,它遵循的图像格式是 [高度 x 宽度 x 通道 x 样本]。我决定改用 PyTorch。但我没有切换我的数据加载方案。所以现在我有形状为 HxWxCxS 的 numpy 数组,而不是 PyTorch 所需的 SxCxHxW。有没有人有任何想法来转换这个?
Dan*_*ler 5
首先,Keras 格式是(samples, height, width, channels). 您需要做的就是一个moved = numpy.moveaxis(data, -1,1)
(samples, height, width, channels)
moved = numpy.moveaxis(data, -1,1)
如果幸运的是您使用的是非默认 config "channels_first",那么该配置与 PyTorch 的相同,即(samples, channels, height, width).
"channels_first"
(samples, channels, height, width)
当转换为火炬时: data = torch.from_numpy(moved)
data = torch.from_numpy(moved)
归档时间:
6 年,10 月 前
查看次数:
1587 次
最近记录: