Skip to content

Commit

Permalink
Merge pull request #363 from sukkritsharmaofficial/master
Browse files Browse the repository at this point in the history
Added plots in convolutional_query!
  • Loading branch information
Palashio authored Sep 22, 2020
2 parents cc2a60b + 199ddde commit e4c8138
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,5 @@ venv.bak/
dmypy.json

# Pyre type checker
.pyre/
.pyre/
.DS_Store
2 changes: 1 addition & 1 deletion libra/plotting/generate_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def generate_regression_plots(history, data, label):
return plots, plot_names


def generate_classification_plots(history, data, label, model, X_test, y_test):
def generate_classification_plots(history):
'''
plotting function that generates classification plots
Expand Down
6 changes: 4 additions & 2 deletions libra/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,8 @@ def convolutional_query(self,
width=None,
show_feature_map=False,
save_as_tfjs=None,
save_as_tflite=None):
save_as_tflite=None,
generate_plots=None):
'''
Calls the body of the convolutional neural network query which is located in the feedforward.py file
:param instruction: The objective that you want to model (str).
Expand Down Expand Up @@ -798,7 +799,8 @@ def convolutional_query(self,
height=height,
width=width,
save_as_tfjs=save_as_tfjs,
save_as_tflite=save_as_tflite)
save_as_tflite=save_as_tflite,
generate_plots=generate_plots)

if show_feature_map:
model = self.models["convolutional_NN"]["model"]
Expand Down
26 changes: 24 additions & 2 deletions libra/query/feedforward_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def classification_ann(instruction,
plots = {}
if generate_plots:
plots = generate_classification_plots(
models[len(models) - 1], data, y, model, X_test, y_test)
models[len(models) - 1])

if save_model:
save(final_model, save_model, save_path)
Expand Down Expand Up @@ -508,7 +508,8 @@ def convolutional(instruction=None,
height=None,
width=None,
save_as_tfjs=None,
save_as_tflite=None):
save_as_tflite=None,
generate_plots=True):
'''
Body of the convolutional function used that is called in the neural network query
if the data is presented in images.
Expand Down Expand Up @@ -787,6 +788,26 @@ def convolutional(instruction=None,
epochs=epochs,
verbose=verbose)

models = []
losses = []
accuracies = []
model_data = []

model_data.append(model)
models.append(history)

losses.append(history.history["val_loss"]
[len(history.history["val_loss"]) - 1])
accuracies.append(history.history['val_accuracy']
[len(history.history['val_accuracy']) - 1])

# final_model = model_data[accuracies.index(max(accuracies))]
# final_hist = models[accuracies.index(max(accuracies))]

plots = {}
if generate_plots:
plots = generate_classification_plots(models[len(models) - 1])

logger('->',
'Final training accuracy: {}'.format(history.history['accuracy'][len(history.history['accuracy']) - 1]))
logger('->', 'Final validation accuracy: {}'.format(
Expand Down Expand Up @@ -816,6 +837,7 @@ def convolutional(instruction=None,
'data': {'train': X_train, 'test': X_test},
'shape': input_shape,
"model": model,
"plots": plots,
'losses': {
'training_loss': history.history['loss'],
'val_loss': history.history['val_loss']},
Expand Down
3 changes: 1 addition & 2 deletions libra/query/nlp_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ def text_classification_query(self, instruction, drop=None,
# generates appropriate classification plots by feeding all
# information
logger("Generating plots")
plots = generate_classification_plots(
history, X, Y, model, X_test, y_test)
plots = generate_classification_plots(history)

if save_model:
save(model, save_model, save_path=save_path)
Expand Down
3 changes: 1 addition & 2 deletions libra/query/supplementaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ def tune_helper(
logger("->", 'Best Hyperparameters Found: {}'.format(returned_pms.values))
if generate_plots:
logger("Generating updated plots")
plots = generate_classification_plots(
history, data, target_column, returned_model, X_test, y_test)
plots = generate_classification_plots(history)


logger("Re-stored model under 'classification_ANN' key")
Expand Down

0 comments on commit e4c8138

Please sign in to comment.