Example #1
0
    def restore(self):
        """Restore user's catalogs to the Preferences file."""
        self._clear()

        cfg = Configuration(True)
        versions = cfg.options('Versions') \
            if cfg.has_section('Versions') else []
        for label in versions:
            path = cfg.get('Versions', label)
            self._addItem(label, path)
 def __init__(self):
     conf = Configuration.get_datamodel_storage_path()
     self.model_path = conf["Plate_SVM_RBF"]
     
     if not os.path.isfile(self.model_path):
         self.train_model()
     self.model = joblib.load(self.model_path)
					<th>Ground Truth</th>
					<th>Prediction</th>
					<th>Identified Particles</th>
					<th>Particle Details</th>
				</tr>
			</thead>
			<tbody>
				$$__ROWS__$$
			</tbody>
		</table>
	</body>
</html>
'''

# Retrieve the path to the report output directory and ensure it is empty
outputDir = Configuration.path('segmentation_reports')
for file in glob.glob(os.path.join(outputDir, '*.png')) + glob.glob(
        os.path.join(outputDir, '*.html')):
    os.unlink(file)

# Retrieve the list of pre-windowed validation images for the segmentation neural network
validationData = SegmentationNetwork.getValidationData()
preWindowed = validationData.images

# Strip the window-related suffixes to determine the original (non-windowed) image filenames
stripRegex = re.compile('\\-[0-9]+\\-window[0-9]+')
origDir = Configuration.path('segmentation_data_preprocessed')
originalImages = set([
    os.path.join(origDir, stripRegex.sub('', os.path.basename(p)))
    for p in preWindowed
])
#!/usr/bin/env python3
from common import Configuration
from natsort import natsorted
import glob, math, os, shutil, sys
import numpy as np

# The approximate batch size that we will group the sliced images into
BATCH_SIZE = 100

# Retrieve the list of image files
imageDir = Configuration.path('segmentation_data_sliced')
images = natsorted(glob.glob(os.path.join(imageDir, '*.png')))

# Split the list of images into batches
numDirs = math.ceil(len(images) / BATCH_SIZE)
batches = np.array_split(images, numDirs)

# Move each batch into a subdirectory
for index, batch in enumerate(batches):

    # Create the subdirectory for the batch
    subdir = os.path.join(imageDir, str(index))
    if os.path.exists(subdir) == False:
        os.makedirs(subdir)

    # Move each of the files into the subdirectory
    for file in batch.tolist():

        # Progress output
        print('Moving {} to {}...'.format(file, subdir))
        sys.stdout.flush()
 def __init__(self):
     self.conf = Configuration.get_datamodel_storage_path()
     self.train_path = [self.conf['Train_data1_dir'],self.conf['Train_data2_dir']]
#!/usr/bin/env python3
from common import Configuration, Logger, TimeLogger, ProgressLogger, SegmentationNetwork
import cv2, glob, mergetiff, os, subprocess, tempfile, time
from natsort import natsorted
import numpy as np

# The layer numbers for the RGB channel data and the binary mask
# (The defaults specified here are correct for the TIFF files Emma prepared in Photoshop)
CHANNELS_LAYER = 1
MASK_LAYER = 0

# Retrieve the list of input files
inputDir = Configuration.path('segmentation_data_raw')
outputDir = Configuration.path('segmentation_data_preprocessed')
inputFiles = natsorted(glob.glob(os.path.join(inputDir, '**', '*.tif')))

# Progress output
print(
    'Preprocessing raw data for the segmentation network ({} files)...'.format(
        len(inputFiles)))

# Keep track of processing progress and timing
numFiles = len(inputFiles)
timer = TimeLogger(numFiles, 'file')
progress = ProgressLogger(numFiles)

# Process each input file
for filenum, infile in enumerate(inputFiles):

    # Progress output
    progress.progress(filenum,
Example #7
0
from modules.process import main_process
from modules.report import main_report
from common import Configuration

if __name__ == '__main__':
    config = Configuration()
    main_process(config)
    main_report(config)
#!/usr/bin/env python3
from common import Configuration, Logger, TimeLogger, ProgressLogger, SegmentationNetwork
from natsort import natsorted
import glob, os

# Retrieve the list of input files
inputDir = Configuration.path('segmentation_data_sliced')
outputDir = Configuration.path('segmentation_data_windowed')
inputFiles = natsorted(glob.glob(os.path.join(inputDir, '*.png')))

# Progress output
print('Windowing sliced data for the segmentation network ({} files)...'.format(len(inputFiles)))

# Keep track of processing progress and timing
numFiles = len(inputFiles)
timer = TimeLogger(numFiles, 'file')
progress = ProgressLogger(numFiles)

# Process each input file
for filenum, infile in enumerate(inputFiles):
	
	# Progress output
	progress.progress(filenum, 'Windowing input file "{}"...'.format(infile))
	
	# Slice the file
	SegmentationNetwork.windowToDir(infile, outputDir, warnOnOverwrite=True)

# Progress output
timer.end()
Logger.success('windowing complete ({}).'.format(timer.report()))
				<tr>
					<th>Input Image</th>
					<th>Ground Truth</th>
					<th>Prediction</th>
				</tr>
			</thead>
			<tbody>
				$$__ROWS__$$
			</tbody>
		</table>
	</body>
</html>
'''

# Retrieve the path to the report output directory and ensure it is empty
outputDir = Configuration.path('classification_reports')
for file in glob.glob(os.path.join(outputDir, '*.png')) + glob.glob(
        os.path.join(outputDir, '*.html')):
    os.unlink(file)

# Retrieve the list of validation images for the morphotype classification neural network
validationData = ClassificationNetwork.getValidationData()
validationImages = sorted([
    os.path.join(validationData.directory, p) for p in validationData.filenames
])

# Load the network from the last saved checkpoint and compute our overall validation accuracy
model, metadata = ClassificationNetwork.load()
accuracy = ValidationUtils.computeValidationAccuracy(model, validationData)

# Compute our overall validation accuracy
Example #10
0
 def setUpClass(cls):
     cls.am=ManagerManagePage.AddManagerPage()
     cls.driver=cls.am.get_driver()
     cls.loginmanager=LoginAction()
     cls.loginmanager.login_manager(cls.driver)                            
     cls.url=cc.baseUrl()+cls.am.url1
Example #11
0
 def store(self):
     """Store user's catalogs to the Preferences file."""
     items = self._items()
     cfg = Configuration(True)
     old_versions = cfg.options('Versions') \
         if cfg.has_section('Versions') else []
     new_versions = [i[0] for i in items]
     for label in old_versions:
         if label not in new_versions:
             cfg.remove_option('Versions', label)
             if CFG.has_option('Versions', label):
                 CFG.remove_option('Versions', label)
     for label, path in items:
         if not cfg.has_section('Versions'):
             cfg.add_section('Versions')
         cfg.set('Versions', label, path)
         CFG.set('Versions', label, path)
     with open(cfg.userrc, 'w') as pref:
         cfg.write(pref)