diff --git a/cnn_classification_service/classifier_cache.py b/cnn_classification_service/classifier_cache.py index 887af21..f36f764 100644 --- a/cnn_classification_service/classifier_cache.py +++ b/cnn_classification_service/classifier_cache.py @@ -64,7 +64,8 @@ class ClassifierCache: self._downloaded_files.append(weights_file_path) # magic happens here - self._current_classifier = Classifier(model_file_path, weights_file_path) + with opentracing.tracer.start_active_span('classifier.loadNewClassifier'): + self._current_classifier = Classifier(model_file_path, weights_file_path) def get_default_classifier(self) -> Tuple[dict, Classifier]: diff --git a/cnn_classification_service/cnn_classifier.py b/cnn_classification_service/cnn_classifier.py index 4ced69c..041b7ad 100644 --- a/cnn_classification_service/cnn_classifier.py +++ b/cnn_classification_service/cnn_classifier.py @@ -18,14 +18,21 @@ from keras_preprocessing.image import ImageDataGenerator class Classifier(object): def __init__(self, model_filename: str, weights_filename: str): - with open(model_filename, 'r') as f: - self.loaded_model = model_from_json(f.read()) + with opentracing.tracer.start_active_span('classifier.loadModel'): + with open(model_filename, 'r') as f: + self.loaded_model = model_from_json(f.read()) - self.loaded_model.load_weights(weights_filename) - self.datagen = ImageDataGenerator(rescale=1. / 255., validation_split=0.25) - self.loaded_model.compile(optimizers.RMSprop(lr=0.0005, decay=1e-6), loss="categorical_crossentropy", - metrics=["accuracy"]) - self.loaded_model.summary() + with opentracing.tracer.start_active_span('classifier.loadWeights'): + self.loaded_model.load_weights(weights_filename) + + with opentracing.tracer.start_active_span('classifier.loadDatagen'): + self.datagen = ImageDataGenerator(rescale=1. / 255., validation_split=0.25) + + with opentracing.tracer.start_active_span('classifier.compile'): + self.loaded_model.compile(optimizers.RMSprop(lr=0.0005, decay=1e-6), loss="categorical_crossentropy", + metrics=["accuracy"]) + + self.loaded_model.summary() # prints to stdout?? @staticmethod def create_spectrogram(wav_filename: str) -> Tuple[str, str]: