taneemishere
commited on
Commit
·
31c555d
1
Parent(s):
dd5e80c
sss
Browse files- .DS_Store +0 -0
- __pycache__/main_program.cpython-38.pyc +0 -0
- classes/__pycache__/Utils.cpython-38.pyc +0 -0
- classes/model/.DS_Store +0 -0
- classes/model/pix2code2.py +0 -70
- main_program.py +1 -1
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
__pycache__/main_program.cpython-38.pyc
ADDED
Binary file (2.69 kB). View file
|
|
classes/__pycache__/Utils.cpython-38.pyc
CHANGED
Binary files a/classes/__pycache__/Utils.cpython-38.pyc and b/classes/__pycache__/Utils.cpython-38.pyc differ
|
|
classes/model/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
classes/model/pix2code2.py
DELETED
@@ -1,70 +0,0 @@
|
|
1 |
-
__author__ = 'Ferdiand John Briones, attempt at pix2code2 through pretrained autoencoders'
|
2 |
-
|
3 |
-
!pip install tensorflow
|
4 |
-
import tensorflow
|
5 |
-
from tensorflow import keras
|
6 |
-
from keras.layers import Input, Dense, Dropout, RepeatVector, LSTM, concatenate, Flatten
|
7 |
-
from keras.models import Sequential, Model
|
8 |
-
from tensorflow.keras.optimizers import RMSprop
|
9 |
-
from keras import *
|
10 |
-
from .Config import *
|
11 |
-
from .AModel import *
|
12 |
-
from .autoencoder_image import *
|
13 |
-
|
14 |
-
class pix2code2(AModel):
|
15 |
-
def __init__(self, input_shape, output_size, output_path):
|
16 |
-
AModel.__init__(self, input_shape, output_size, output_path)
|
17 |
-
self.name = "pix2code2"
|
18 |
-
|
19 |
-
visual_input = Input(shape=input_shape)
|
20 |
-
|
21 |
-
#Load the pre-trained autoencoder model
|
22 |
-
autoencoder_model = autoencoder_image(input_shape, input_shape, output_path)
|
23 |
-
autoencoder_model.load('autoencoder')
|
24 |
-
autoencoder_model.model.load_weights('../bin/autoencoder.h5')
|
25 |
-
|
26 |
-
#Get only the model up to the encoded part
|
27 |
-
hidden_layer_model_freeze = Model(inputs=autoencoder_model.model.input, outputs=autoencoder_model.model.get_layer('encoded_layer').output)
|
28 |
-
hidden_layer_input = hidden_layer_model_freeze(visual_input)
|
29 |
-
|
30 |
-
#Additional layers before concatenation
|
31 |
-
hidden_layer_model = Flatten()(hidden_layer_input)
|
32 |
-
hidden_layer_model = Dense(1024, activation='relu')(hidden_layer_model)
|
33 |
-
hidden_layer_model = Dropout(0.3)(hidden_layer_model)
|
34 |
-
hidden_layer_model = Dense(1024, activation='relu')(hidden_layer_model)
|
35 |
-
hidden_layer_model = Dropout(0.3)(hidden_layer_model)
|
36 |
-
hidden_layer_result = RepeatVector(CONTEXT_LENGTH)(hidden_layer_model)
|
37 |
-
|
38 |
-
#Make sure the loaded hidden_layer_model_freeze will no longer be updated
|
39 |
-
for layer in hidden_layer_model_freeze.layers:
|
40 |
-
layer.trainable = False
|
41 |
-
|
42 |
-
#The same language model that of pix2code by Tony Beltramelli
|
43 |
-
language_model = Sequential()
|
44 |
-
language_model.add(LSTM(128, return_sequences=True, input_shape=(CONTEXT_LENGTH, output_size)))
|
45 |
-
language_model.add(LSTM(128, return_sequences=True))
|
46 |
-
|
47 |
-
textual_input = Input(shape=(CONTEXT_LENGTH, output_size))
|
48 |
-
encoded_text = language_model(textual_input)
|
49 |
-
|
50 |
-
decoder = concatenate([hidden_layer_result, encoded_text])
|
51 |
-
|
52 |
-
decoder = LSTM(512, return_sequences=True)(decoder)
|
53 |
-
decoder = LSTM(512, return_sequences=False)(decoder)
|
54 |
-
decoder = Dense(output_size, activation='softmax')(decoder)
|
55 |
-
|
56 |
-
self.model = Model(inputs=[visual_input, textual_input], outputs=decoder)
|
57 |
-
|
58 |
-
optimizer = RMSprop(lr=0.0001, clipvalue=1.0)
|
59 |
-
self.model.compile(loss='categorical_crossentropy', optimizer=optimizer)
|
60 |
-
|
61 |
-
def fit_generator(self, generator, steps_per_epoch):
|
62 |
-
self.model.summary()
|
63 |
-
self.model.fit_generator(generator, steps_per_epoch=steps_per_epoch, epochs=EPOCHS, verbose=1)
|
64 |
-
self.save()
|
65 |
-
|
66 |
-
def predict(self, image, partial_caption):
|
67 |
-
return self.model.predict([image, partial_caption], verbose=0)[0]
|
68 |
-
|
69 |
-
def predict_batch(self, images, partial_captions):
|
70 |
-
return self.model.predict([images, partial_captions], verbose=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main_program.py
CHANGED
@@ -5,7 +5,7 @@ import os.path
|
|
5 |
from os.path import basename
|
6 |
|
7 |
from classes.Sampler import *
|
8 |
-
from classes.model.pix2code2 import *
|
9 |
|
10 |
|
11 |
def code_gen(path_to_input_image):
|
|
|
5 |
from os.path import basename
|
6 |
|
7 |
from classes.Sampler import *
|
8 |
+
#from classes.model.pix2code2 import *
|
9 |
|
10 |
|
11 |
def code_gen(path_to_input_image):
|