Skip to content

Commit 9d5cb74

Browse files
authored
Merge pull request #3 from christiandimaio/v1
Defined V1
2 parents b964aad + 9d4ef27 commit 9d5cb74

File tree

21 files changed

+1266
-838
lines changed

21 files changed

+1266
-838
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,4 @@ dmypy.json
119119
dataset/*
120120
.saved/*
121121
*.Identifier
122+
*.zip

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Usare IntelliSense per informazioni sui possibili attributi.
3+
// Al passaggio del mouse vengono visualizzate le descrizioni degli attributi esistenti.
4+
// Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: File corrente",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "/home/christian/Documenti/GitHub/Image-Captioning/v1/NeuralNet.py",
12+
"console": "integratedTerminal"
13+
}
14+
]
15+
}

light_version/Dataset.py renamed to bck_old/Dataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def pack_minibatch_evaluation(self, data):
117117
images = torch.stack(images, 0)
118118

119119
caption_lengths = [len(caption) for caption in captions]
120+
captions
120121
captions = nn.utils.rnn.pad_sequence(captions, padding_value=0, batch_first=True)
121122
return images,captions.type(torch.LongTensor),caption_lengths
122123

light_version/NeuralNet.py renamed to bck_old/NeuralNet.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,37 @@
99

1010
device = "cuda:0"
1111
class EncoderCNN(nn.Module):
12-
def __init__(self, embed_size):
12+
def __init__(self, embedding_size):
1313
super(EncoderCNN, self).__init__()
1414
resnet = models.resnet50(pretrained=True)
1515
for param in resnet.parameters():
1616
param.requires_grad_(False)
1717

1818
modules = list(resnet.children())[:-1] # remove last fc layer
1919
self.resnet = nn.Sequential(*modules)
20-
self.linear = nn.Linear(resnet.fc.in_features, 50)
20+
self.linear = nn.Linear(resnet.fc.in_features, embedding_size)
2121

2222
def forward(self, images):
23-
2423
features = self.resnet(images)
25-
features = features.reshape(features.size(0), -1)
24+
features = features.reshape(features.size(0), -1) # (Batch Size, Embedding Dim.)
2625
features = self.linear(features)
2726
return features
2827

2928
class DecoderRNN(nn.Module):
30-
def __init__(self, hidden_size, padding_index, vocab_size, embeddings ):
29+
def __init__(self, hidden_size, padding_index, vocab_size, embeddings, embedding_size):
3130
"""Set the hyper-parameters and build the layers."""
3231
super(DecoderRNN, self).__init__()
33-
# Keep track of hidden_size for initialization of hidden state
34-
self.hidden_size = hidden_size
3532

3633
# Embedding layer that turns words into a vector of a specified size
37-
self.word_embeddings = nn.Embedding.from_pretrained(embeddings, freeze=True, padding_idx = 0)
34+
self.word_embeddings = nn.Embedding(vocab_size, embedding_size, padding_idx=padding_index)
3835

3936
# The LSTM takes embedded word vectors (of a specified size) as input
4037
# and outputs hidden states of size hidden_dim
41-
self.lstm = nn.LSTM(input_size=50, \
42-
hidden_size=1024, # LSTM hidden units
43-
num_layers=1, # number of LSTM layer
44-
batch_first=True, # input & output will have batch size as 1st dimension
45-
dropout=0, # Not applying dropout
46-
bidirectional=False, # unidirectional LSTM
47-
)
38+
self.lstm_unit = torch.nn.LSTMCell(embedding_size, hidden_size)
4839

4940
# The linear layer that maps the hidden state output dimension
5041
# to the number of words we want as output, vocab_size
51-
self.linear_1 = nn.Linear(1024, vocab_size)
42+
self.linear_1 = nn.Linear(hidden_size, vocab_size)
5243

5344
def init_hidden_state(self, encoder_out):
5445
"""
File renamed without changes.

heavy_version/Models/Dataset.py

Lines changed: 0 additions & 134 deletions
This file was deleted.

heavy_version/Models/Interface/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)