Created
September 27, 2017 16:42
-
-
Save michaelschwier/893125cbec9bcb4c6ce43bbf9fa411d9 to your computer and use it in GitHub Desktop.
Code to reproduce Memory Error in PyRadiomics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Short script to reproduce memory errors in PyRadiomics. | |
# There are two types of error: | |
# 1. Trying to extract features from a rather large mask | |
# 2. Trying to extract features from small masks for many images in a loop | |
# In both cases we get a memory error. In the first case the root is in | |
# SimpleITK failing to allocate memory. In the second case the root is | |
# in numpy. (Un)comment one of the lines defining the testMask to reproduce | |
# either error type. For the second error it takes a while until the | |
# Exception happens (about 210 iterations for me, but could be more or less | |
# depending on your system). | |
import radiomics | |
testImage = "PyRadiomicsBugTest_img.nrrd" | |
#testMask = "PyRadiomicsBugTest_large_mask.nrrd" | |
testMask = "PyRadiomicsBugTest_small_mask.nrrd" | |
settings = {} | |
settings['binWidth'] = 25 | |
settings['resampledPixelSpacing'] = None | |
settings['interpolator'] = 'sitkBSpline' | |
settings['verbose'] = True | |
extractor = radiomics.featureextractor.RadiomicsFeaturesExtractor(**settings) | |
extractor.disableAllFeatures() | |
extractor.enableFeaturesByName(firstorder=["Mean", "Median", "Minimum", "Maximum"]) | |
extractor.enableFeaturesByName(shape=["Volume"]) | |
print(extractor.enabledFeatures) | |
features = [] | |
print("Extracting features: ") | |
idx = 0 | |
while True: | |
idx += 1 | |
print("iteration: ", idx) | |
featureVector = extractor.execute(testImage, testMask, label = 1) | |
featureVector["index"] = idx | |
features.append(featureVector) | |
print("------------ DONE (never) ------------") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The test image files needed to run this script (as well as the script itself again) can be found here