def progress(self, current, total): # Create the progress logger once we know the total number of steps if self.logger is None: self.logger = ProgressLogger(total) # Display progress output to the user self.logger.progress(current, 'Performing inference...', sameLine = True)
class SegmentationProgress(object): def __init__(self): self.logger = None def progress(self, current, total): # Create the progress logger once we know the total number of steps if self.logger is None: self.logger = ProgressLogger(total) # Display progress output to the user self.logger.progress(current, 'Performing inference...', sameLine = True)
# so we remove it from our list to ensure all data is completely unseen originalImages = sorted(originalImages)[1:] # Load the network from the last saved checkpoint and compute our overall validation accuracy model, metadata = SegmentationNetwork.load() accuracy = ValidationUtils.computeValidationAccuracy(model, validationData) # Progress output numImages = len(originalImages) print( 'Generating validation report for the segmentation network ({} images)...'. format(numImages)) # Keep track of processing progress and timing timer = TimeLogger(numImages, 'image') progress = ProgressLogger(numImages) # Process each input file tableRows = [] for filenum, infile in enumerate(originalImages): # Progress output progress.progress(filenum, 'Processing validation image "{}"...'.format(infile)) # Split the ground-truth binary mask from the other image channels raster = cv2.imread(infile, cv2.IMREAD_UNCHANGED) channels, groundTruth = maskutils.splitAlphaMask(raster) # Perform inference on the image data probabilities = SegmentationNetwork.infer(model, metadata, channels)
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, 'Preprocessing input file "{}"...'.format(infile)) # Create a temporary directory to hold our intermediate files with tempfile.TemporaryDirectory() as tempDir: # Create the filenames for our intermediate files and output file channelsFile = os.path.join(tempDir, 'channels.tif') maskFile = os.path.join(tempDir, 'mask.tif') outfile = os.path.join(
#!/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()))