target_net.eval()

if torch.cuda.is_available():
    policy_net = policy_net.cuda()
    target_net = target_net.cuda()

torch.backends.cudnn.enabled = True

optimizer = optim.RMSprop(policy_net.parameters(), lr=1e-7)
memory = utilsRL.ReplayMemory(10000)
episodeDurations = []
steps_done = 0

seqRootRGB = dirPath + 'dataset/iLIDS-VID/i-LIDS-VID/sequences/'
personIdxDict, personFramesDict = prepareDataset.prepareDS(seqRootRGB)
trainTriplets, testTriplets = prepareDataset.generateTriplets(
    len(personFramesDict), testTrainSplit)
personNoDict = dict([v, k] for k, v in personIdxDict.items())
utilsRL.saveTestTriplet(testTriplets)
#os.remove("loss20pdata20epochs.txt")


def optimizeModel():

    # print("Optimizing Model Begin")
    if len(memory) < BATCH_SIZE:
        # print("Optimizing Model End because of not sufficient training examples in replay memory")
        return

    transitions = memory.sample(BATCH_SIZE)
    batch = Transition(*zip(*transitions))
    # print batch
示例#2
0
input_size = 128
hidden_size = 32
num_layers = 2
learning_rate = 0.001
momentum = 0.9
alpha = torch.FloatTensor([0.3])
if torch.cuda.is_available():
    alpha = alpha.cuda()
alpha = Variable(alpha)
num_epochs = 200
testTrainSplit = 1

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print device

trainTriplets, testTriplets = prepareDataset.generateTriplets(
    300, testTrainSplit)
features_dir = '/data/home/prateeka/ilids_features/'

if os.path.isfile("lossRGB.txt"):
    os.remove("lossRGB.txt")
if os.path.isfile("lossRGBv.txt"):
    os.remove("lossRGBv.txt")


class RNN(nn.Module):
    def __init__(self, input_size, hidden_size, num_layers):
        super(RNN, self).__init__()
        self.hidden_size = hidden_size
        self.num_layers = num_layers
        self.lstm = nn.LSTM(input_size,
                            hidden_size,
hidden_size = 128
num_layers = 2
learning_rate = 0.001
momentum = 0
alpha = torch.FloatTensor([0.4])
if torch.cuda.is_available():
    alpha = alpha.cuda()
alpha = Variable(alpha)
num_epochs = 2
batch_size = 1
testTrainSplit = 0.8

seqRootRGB = '/Users/prateek/8thSem/dataset/iLIDS-VID/i-LIDS-VID/sequences/'
personIdxDict, personFramesDict = prepareDataset.prepareDS(seqRootRGB)
nTotalPersons = len(personFramesDict)
trainTriplets, testTriplets = prepareDataset.generateTriplets(
    nTotalPersons, testTrainSplit)


class RNN(nn.Module):
    def __init__(self, input_size, hidden_size, num_layers):
        super(RNN, self).__init__()
        self.hidden_size = hidden_size
        self.num_layers = num_layers
        self.lstm = nn.LSTM(input_size,
                            hidden_size,
                            num_layers,
                            batch_first=True)

    def forward(self, x):
        h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size)
        c0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size)