Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Allows to clear backends model
Browse files Browse the repository at this point in the history
  • Loading branch information
vessemer committed Feb 1, 2018
1 parent 32e002d commit 34494f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Expand Up @@ -117,3 +117,10 @@ def predict(self, candidates, model_path=None):
'p_concerning': float}}
"""
pass

@abc.abstractmethod
def clear(self):
"""
Clear all signs of backend models.
"""
pass
9 changes: 8 additions & 1 deletion prediction/src/algorithms/classify/src/lr3dcnn/model.py
Expand Up @@ -2,9 +2,10 @@
import numpy as np
import os
from collections import defaultdict
from keras import backend as K
from src.algorithms.classify.src.classification_model import ClassificationModel
from src.preprocess import preprocess_ct, load_ct, crop_patches, generators

from src.algorithms.classify.src.classification_model import ClassificationModel
from .architecture import net


Expand Down Expand Up @@ -307,3 +308,9 @@ def predict(self, candidates, model_path=None):
iter += 1

return candidates

def clear(self):
del self.model
self.pull_ct.clear()
self.pull_patches.clear()
K.clear_session()
6 changes: 5 additions & 1 deletion prediction/src/tests/test_classification_3dlrcnn.py
@@ -1,6 +1,7 @@
from ..algorithms.classify.src.lr3dcnn.model import Model
import os

from ..algorithms.classify.src.lr3dcnn.model import Model


def test_classify_init_load(models_dir_path):
model = Model(init_model=True, pull_size=10, batch_size=32, data_format=None)
Expand All @@ -12,6 +13,7 @@ def test_classify_init_load(models_dir_path):
data_format=None
)
assert model is not None
model.clear()


def test_classify_predict(dicom_paths, nodule_locations, models_dir_path):
Expand All @@ -24,6 +26,7 @@ def test_classify_predict(dicom_paths, nodule_locations, models_dir_path):
candidates = [{'file_path': dicom_paths[0], 'centroids': [nl for nl in nodule_locations]}]
predicted = model.predict(candidates)
assert 0 <= predicted[0]['centroids'][0]['p_concerning'] <= 1
model.clear()


def test_classify_real_nodule_full_dicom(dicom_paths, models_dir_path):
Expand All @@ -37,3 +40,4 @@ def test_classify_real_nodule_full_dicom(dicom_paths, models_dir_path):
predicted = model.predict(candidates)
print(predicted)
assert .3 <= predicted[0]['centroids'][0]['p_concerning'] <= 1
model.clear()

0 comments on commit 34494f6

Please sign in to comment.