Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def createXdot(dotdata,prog='dot'):
# The following code is from the pydot module written by Ero Carrera
progs = pydot.find_graphviz()
#prog = 'dot'
if progs is None:
return None
if not progs.has_key(prog):
log.warning('Invalid prog=%s',prog)
# Program not found ?!?!
return None
tmp_fd, tmp_name = tempfile.mkstemp()
os.close(tmp_fd)
f = open(tmp_name,'w')
f.write(dotdata)
f.close()
format = 'xdot'
cmd = progs[prog]+' -T'+format+' '+tmp_name
'''Using an already trained model, run predictions on unknown images.'''
import json
import tqdm
import numpy as np
import matplotlib.pyplot as plt
import os
from train import DataClassifier
import pydot
pydot.find_graphviz = lambda: True
from keras.models import load_model
def get_model_predictions(model, data_classifier):
test_character_name_to_npz_path = {
**data_classifier.partition_to_character_name_to_npz_paths['test'],
**data_classifier.partition_to_character_name_to_npz_paths['validation']
}
character_to_predictions = {}
flattened = [(character_name, npz_path) for character_name, npz_paths in test_character_name_to_npz_path.items() for npz_path in npz_paths]
for character_name, npz_path in tqdm.tqdm(flattened):
npz_name = os.path.basename(npz_path)
pixels = np.load(npz_path)['pixels']
predicted_labels = model.predict(np.array([pixels]), batch_size=1)
def _programs_default(self):
""" Trait initaliser.
"""
progs = find_graphviz()
if progs is None:
logger.warning("GraphViz's executables not found")
return {}
else:
return progs
def __check_graphviz():
import pydot
if pydot.find_graphviz() is None:
return False
return True
model_base = Model(input, output)
output = BatchNormalization()(output)
output = Dropout(0.5)(output)
output = Dense(128, activation='relu')(output)
output = BatchNormalization()(output)
output = Dropout(0.5)(output)
output = Dense(len(all_character_names), activation='softmax')(output)
model = Model(model_base.input, output)
for layer in model_base.layers:
layer.trainable = False
model.summary(line_length=200)
# Generate a plot of a model
import pydot
pydot.find_graphviz = lambda: True
from keras.utils import plot_model
plot_model(model, show_shapes=True, to_file='../model_pdfs/{}.pdf'.format(pretrained_model))
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
return model