torch7 中图像保存和加载的异常行为

Unusual behavior of image saving and loading in torch7

我注意到 torch7 有异常行为。我对 torch7 略知一二。所以我不知道如何解释或纠正这种行为。

所以,我正在使用 CIFAR-10 数据集。简单地说,我从 CIFAR-10 中获取图像数据,然后将其保存在我的目录中。当我加载保存的图像时,它是不同的。

这是我的代码 -

require 'image'

i1 = testData.data[2] --fetching data from CIFAR-10
image.save("1.png", i) --saving the data as image

i2 = image.load("1.png") --loading the saved image

if(i1 == i2) then --checking if image1(i1) and image2(i2) are different
print("same") 
end

这种行为是预期的吗?我以为 png 应该是无损的。

如果是,如何纠正?

加载CIFAR-10数据集的代码-

-- load dataset
  trainData = {
     data = torch.Tensor(50000, 3072),
     labels = torch.Tensor(50000),
     size = function() return trsize end
  }
  for i = 0,4 do
     local subset = torch.load('cifar-10-batches-t7/data_batch_' .. (i+1) .. '.t7', 'ascii')
     trainData.data[{ {i*10000+1, (i+1)*10000} }] = subset.data:t()
     trainData.labels[{ {i*10000+1, (i+1)*10000} }] = subset.labels
  end
  trainData.labels = trainData.labels + 1

  local subset = torch.load('cifar-10-batches-t7/test_batch.t7', 'ascii')
  testData = {
     data = subset.data:t():double(),
     labels = subset.labels[1]:double(),
     size = function() return tesize end
  }
  testData.labels = testData.labels + 1
  testData.data = testData.data:reshape(10000,3,32,32)

== 运算符比较指向两个张量的指针,而不是内容:

a = torch.Tensor(3, 5):fill(1)
b = torch.Tensor(3, 5):fill(1)
print(a == b)
> false
print(a:eq(b):all())
> true