Skip to content

Commit

Permalink
batch-represent: Remove unused functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Amos committed Jan 12, 2016
1 parent 7a3b472 commit 44bd270
Showing 1 changed file with 0 additions and 123 deletions.
123 changes: 0 additions & 123 deletions batch-represent/dataset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -365,129 +365,6 @@ local function tableToOutput(self, dataTable, scalarTable)
return data, scalarLabels, labels
end

-- sampler, samples from the training set.
function dataset:sample(quantity)
if self.split == 0 then
error('No training mode when split is set to 0')
end
quantity = quantity or 1
local dataTable = {}
local scalarTable = {}
for _=1,quantity do
local class = torch.random(1, #self.classes)
local out = self:getByClass(class)
table.insert(dataTable, out)
table.insert(scalarTable, class)
end
local data, scalarLabels, labels = tableToOutput(self, dataTable, scalarTable)
return data, scalarLabels, labels
end

-- TODO: Triplet selection.
-- This naively randomly samples for triplets.
function dataset:sampleTriplet(quantity)
if self.split == 0 then
error('No training mode when split is set to 0')
end
quantity = quantity or 1
local dataTable = {}
local scalarTable = {}

-- Anchors
for _=1,quantity do
local anchorClass = torch.random(1, #self.classes)
table.insert(dataTable, self:getByClass(anchorClass))
table.insert(scalarTable, anchorClass)
end

-- Positives
for i=1,quantity do
local posClass = scalarTable[i]
table.insert(dataTable, self:getByClass(posClass))
table.insert(scalarTable, posClass)
end

-- Negatives
for i=1,quantity do
local posClass = scalarTable[i]
local negClass = posClass
while negClass == posClass do
negClass = torch.random(1, #self.classes)
end
table.insert(dataTable, self:getByClass(negClass))
table.insert(scalarTable, negClass)
end
local data, scalarLabels, labels = tableToOutput(self, dataTable, scalarTable)
return data, scalarLabels, labels
end


function dataset:samplePeople(peoplePerBatch, imagesPerPerson)
if self.split == 0 then
error('No training mode when split is set to 0')
end

local classes = torch.randperm(#trainLoader.classes)[{{1,peoplePerBatch}}]:int()
local numPerClass = torch.Tensor(peoplePerBatch)
for i=1,peoplePerBatch do
local n = math.min(self.classListSample[classes[i]]:nElement(), imagesPerPerson)
numPerClass[i] = n
end

local data = torch.Tensor(numPerClass:sum(),
self.sampleSize[1], self.sampleSize[2], self.sampleSize[3])

local dataIdx = 1
for i=1,peoplePerBatch do
local cls = classes[i]
local n = numPerClass[i]
local shuffle = torch.randperm(n)
for j=1,n do
imgNum = self.classListSample[cls][shuffle[j]]
imgPath = ffi.string(torch.data(self.imagePath[imgNum]))
data[dataIdx] = self:sampleHookTrain(imgPath)
dataIdx = dataIdx + 1
end
end
assert(dataIdx - 1 == numPerClass:sum())

return data, numPerClass
end

function dataset:sampleAllOfClass(quantity, posClass)
if self.split == 0 then
error('No training mode when split is set to 0')
end
quantity = quantity or 1

local n = math.min(self.classListSample[posClass]:nElement(), quantity)
local data = torch.Tensor(n, self.sampleSize[1],
self.sampleSize[2], self.sampleSize[3])
for i=1,n do
imgpath = ffi.string(torch.data(self.imagePath[self.classListSample[posClass][i]]))
data[i] = self:sampleHookTrain(imgpath)
end

return data
end

function dataset:sampleNoneOfClass(quantity, posClass)
if self.split == 0 then
error('No training mode when split is set to 0')
end
quantity = quantity or 1
local data = torch.Tensor(quantity, self.sampleSize[1],
self.sampleSize[2], self.sampleSize[3])
for i=1,quantity do
local negClass = posClass
while negClass == posClass do
negClass = torch.random(1, #self.classes)
end
data[i] = self:getByClass(negClass)
end
return data
end

function dataset:get(i1, i2)
local indices, quantity
if type(i1) == 'number' then
Expand Down

0 comments on commit 44bd270

Please sign in to comment.