logger.info('Starting %d-fold Cross-Validation in %d processes.' % (folds, workerPool._processes)) result = workerPool.map_async(runFold, foldRunnables).get() workerPool.close() workerPool.join() cm = ConfusionMatrix() for r in result: cm.combine(r.confmat) elapsedTimeMP = time.time() - startTime cm.toFile(os.path.join(expdir, 'conf_matrix.cm')) # create the pdf table and move it into the log directory # this is a dirty hack since pdflatex apparently # does not support arbitrary output paths pdfname = 'conf_matrix' logger.info('creating pdf if confusion matrix...') cm.toPDF(pdfname) os.rename('%s.pdf' % pdfname, os.path.join(expdir, '%s.pdf' % pdfname)) except (KeyboardInterrupt, SystemExit, SystemError): logger.critical("Caught KeyboardInterrupt, terminating workers") workerPool.terminate() workerPool.join() exit(1) except: logger.error('\n' + ''.join(traceback.format_exception(*sys.exc_info()))) exit(1) # startTime = time.time() else: logger.info('Starting %d-fold Cross-Validation in 1 process.' % (folds))
workerPool = Pool() logger.info('Starting %d-fold Cross-Validation in %d processes.' % (folds, workerPool._processes)) result = workerPool.map_async(runFold, foldRunnables).get() workerPool.close() workerPool.join() cm = ConfusionMatrix() for r in result: cm.combine(r.confmat) elapsedTimeMP = time.time() - startTime cm.toFile(os.path.join(expdir, 'conf_matrix.cm')) # create the pdf table and move it into the log directory # this is a dirty hack since pdflatex apparently # does not support arbitrary output paths pdfname = 'conf_matrix' logger.info('creating pdf if confusion matrix...') cm.toPDF(pdfname) os.rename('%s.pdf' % pdfname, os.path.join(expdir, '%s.pdf' % pdfname)) except (KeyboardInterrupt, SystemExit, SystemError): logger.critical("Caught KeyboardInterrupt, terminating workers") workerPool.terminate() workerPool.join() exit(1) except: logger.error('\n' + ''.join(traceback.format_exception(*sys.exc_info()))) exit(1) # startTime = time.time() else: logger.info('Starting %d-fold Cross-Validation in 1 process.' % (folds)) cm = ConfusionMatrix() for fold in foldRunnables: cm.combine(runFold(fold).confmat)