2016-04-03 70 views
0

我注意到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 dataset-

-- 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) 

回答

1

==運算符比較指針2張量,而不是內容:

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