Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated README, requirements, and code. #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Both the source code and the datasets are provided to foster future research in
## Setup
### Prerequisites

- Python 2 or 3
- Python 3.11.x
- pip

### Install dependencies
Expand Down
4 changes: 4 additions & 0 deletions model/build_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
evaluation_samples_number = len(paths) / (distribution + 1)
training_samples_number = evaluation_samples_number * distribution

evaluation_samples_number = int(evaluation_samples_number+0.5)
training_samples_number = int(training_samples_number+0.5)


assert training_samples_number + evaluation_samples_number == len(paths)

print("Splitting datasets, training samples: {}, evaluation samples: {}".format(training_samples_number, evaluation_samples_number))
Expand Down
2 changes: 1 addition & 1 deletion model/classes/dataset/Dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ def sparsify_labels(next_words, voc):
return temp

def save_metadata(self, path):
np.save("{}/meta_dataset".format(path), np.array([self.input_shape, self.output_size, self.size]))
np.save("{}/meta_dataset".format(path), np.array([self.input_shape, self.output_size, self.size], dtype=object))
2 changes: 1 addition & 1 deletion model/classes/dataset/Generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def data_generator(voc, gui_paths, img_paths, batch_size, generate_binary_sequen

if verbose:
print("Yield batch")
yield ([batch_input_images, batch_partial_sequences], batch_next_words)
yield ((batch_input_images, batch_partial_sequences), batch_next_words)

batch_input_images = []
batch_partial_sequences = []
Expand Down
4 changes: 2 additions & 2 deletions model/classes/model/pix2code.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ def __init__(self, input_shape, output_size, output_path):

self.model = Model(inputs=[visual_input, textual_input], outputs=decoder)

optimizer = RMSprop(lr=0.0001, clipvalue=1.0)
optimizer = RMSprop(learning_rate=0.0001, clipvalue=1.0)
self.model.compile(loss='categorical_crossentropy', optimizer=optimizer)

def fit(self, images, partial_captions, next_words):
self.model.fit([images, partial_captions], next_words, shuffle=False, epochs=EPOCHS, batch_size=BATCH_SIZE, verbose=1)
self.save()

def fit_generator(self, generator, steps_per_epoch):
self.model.fit_generator(generator, steps_per_epoch=steps_per_epoch, epochs=EPOCHS, verbose=1)
self.model.fit(generator, steps_per_epoch=steps_per_epoch, epochs=EPOCHS, verbose=1)
self.save()

def predict(self, image, partial_caption):
Expand Down
4 changes: 2 additions & 2 deletions model/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__author__ = 'Tony Beltramelli - www.tonybeltramelli.com'

import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))

import sys

Expand Down Expand Up @@ -33,7 +33,7 @@ def run(input_path, output_path, is_memory_intensive=False, pretrained_model=Non

input_shape = dataset.input_shape
output_size = dataset.output_size
steps_per_epoch = dataset.size / BATCH_SIZE
steps_per_epoch = int(dataset.size / BATCH_SIZE)

voc = Vocabulary()
voc.retrieve(output_path)
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Keras==2.1.2
numpy==1.13.3
opencv-python==3.3.0.10
h5py==2.7.1
tensorflow==1.4.0
Keras==3.0.0
numpy==1.23.5
opencv-python==4.9.0.80
h5py==3.10.0
tensorflow==2.16.1