Exemple #1
0
    def __init__( self, parent = None ):
        super(Window, self).__init__( parent )
        self.setWindowTitle( 'Interactive Distortion Evolver' )

        ### Experiment Configuration
        # ATW: TODO: When we start getting reasonable distortions, there
        # needs to be a method to reload an old population. For now we'll
        # always make a new one.

        self.experiment_data_dir  = "../external/HyperNEAT/NE/HyperNEAT/out/data"
        self.date_specifier = datetime.now().strftime("%y%m%d_%H%M%S")
        self.image_storage = []

        # Initialize HyperNEAT.
        neat.initialize()

        # See if there is an output directory.
        if not os.path.exists(os.getcwd() + "/output"):
            os.mkdir(os.getcwd() + "/output")

        # Load the image experiment.
        self.experiment = neat.setupExperiment(
            "%s/ImageExperiment.dat" % self.experiment_data_dir,
            "output/imageExp_out_%s.xml" % self.date_specifier )

        # Grab the global parameters.
        self.globals = neat.getGlobalParameters()
        population_size = int(self.globals.getParameterValue('PopulationSize'))

        ### GUI Configuration

        # Set default window size.
        self.setFixedSize( 670, 700 )

        # Initialize the list view for the distorted images.
        lv = QListView( )
        lv.setViewMode( QListView.IconMode )
        lv.setUniformItemSizes( True )
        lv.setSelectionRectVisible( True )
        lv.setMovement( QListView.Static )
        lv.setSelectionMode( QListView.MultiSelection )
        lv.setEditTriggers( QListView.CurrentChanged )
        lv.setResizeMode( QListView.Adjust )
        lv.setIconSize( QSize(120, 120) )
        lv.setMinimumSize( 500, 385 )
        lv.setSpacing( 5 )
        lv.setEnabled( False )
        self.population_list = lv

        # Context menu.
        lv.setContextMenuPolicy( Qt.CustomContextMenu )
        lv.connect( lv, SIGNAL('customContextMenuRequested (const QPoint&)'), self.handle_context_menu )

        # Create the population model.
        pm = PopulationModel( population_size )
        self.population_model = pm
        lv.setModel( pm )
        for i in xrange(population_size):
            self.population_model.update_item( i, DummyNetwork( i % 4 + 1 ) )

        # Monitor population list selection changes.
        self.connect(
            lv.selectionModel(),
            SIGNAL('selectionChanged(const QItemSelection &, const QItemSelection &)'),
            self.handle_listview_change )

        # Initialize widgets for displaying the graphic and for choosing
        # a new base image.
        btn_select_image = QPushButton( "Load Image" )
        self.connect( btn_select_image, SIGNAL('released()'), self.select_image )
        lbl_image = QLabel( "Nothing loaded" )
        lbl_image.setFixedSize( 120, 120 )
        self.original_image_label = lbl_image
        image_layout = QVBoxLayout()
        image_layout.addWidget( btn_select_image )
        image_layout.addWidget( lbl_image )

        # Initialize a horizontal layout for the parameters.
        gb = QGroupBox( "Evolution Parameters" )
        gb.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding )

        tw = QTableWidget( 1, 2 )
        tw.setHorizontalHeaderLabels(QString("Parameter;Value").split(';'))
        tw.setColumnWidth( 0, 350 )
        tw.horizontalHeader().setStretchLastSection( True )
        self.connect( tw, SIGNAL('itemChanged(QTableWidgetItem *)'), self.handle_parameter_change )
        self.parameter_table = tw

        tw_layout = QVBoxLayout()
        tw_layout.addWidget( tw )
        gb.setLayout( tw_layout )

        param_layout = QHBoxLayout()
        param_layout.addLayout( image_layout )
        param_layout.addWidget( gb )

        # Grab the global parameters.
        parameter_count = self.globals.getParameterCount()
        tw.setRowCount( parameter_count )
        for p in xrange(parameter_count):
            parameter_name = self.globals.getParameterName( p )
            tw.model().setData( tw.model().index( p, 0 ), parameter_name )
            tw.model().setData( tw.model().index( p, 1 ), self.globals.getParameterValue( parameter_name ) )
            index = tw.item( p, 0 )
            index.setFlags( index.flags() ^ Qt.ItemIsEditable )

        # Initialize a horizontal layout for the evolve button.
        btn_evolve = QPushButton( "Shuffle" )
        self.connect( btn_evolve, SIGNAL('released()'), self.evolve_image )
        btn_evolve.setEnabled( False )
        self.btn_evolve = btn_evolve
        self.btn_evolve.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred )

        self.spin_evolve_iterations = QSpinBox()
        self.spin_evolve_iterations.setRange( 1, 100 )
        self.spin_evolve_iterations.setValue( 1 )

        self.cb_cross_correlate = QCheckBox( "X-Corr" )
        self.cb_cross_correlate.setChecked( True )

        control_layout = QHBoxLayout()
        control_layout.addWidget( btn_evolve )
        control_layout.addWidget( self.spin_evolve_iterations )
        control_layout.addWidget( self.cb_cross_correlate )

        # Initialize vertical central layout.
        central_layout = QVBoxLayout()
        central_layout.addLayout( param_layout )
        central_layout.addWidget( lv )
        central_layout.addLayout( control_layout )
        central_widget = QFrame()
        central_widget.setLayout( central_layout )

        self.setCentralWidget( central_widget )

        # Create a menu
        self.image_menu = QMenu("Menu", self)
        self.image_menu_save_image = self.image_menu.addAction("Save Selected Images")
        self.image_menu_save_network = self.image_menu.addAction("Save Selected Neural Network")

        ### Initialization

        # Handle command line parameters.
        if len(sys.argv) >= 2:
            self.select_image(sys.argv[1])

        # Create progress dialog.
        self.progress_dialog = QProgressDialog( self );
        self.progress_dialog.setLabelText( "Evolving population..." )
        self.progress_dialog.setWindowModality( Qt.WindowModal );
        self.progress_dialog.setVisible( False )
        self.progress_dialog.setCancelButton( None )

        # Start evolver thread.
        self.evolve_thread = EvolveThread( self )
        self.evolve_thread.finished_job.connect( self.finish_evolution )
        self.evolve_thread.update_progress.connect( self.update_evolution_progress )
        self.evolve_thread.start()

        # Generate first population.
        self.population = self.experiment.pythonEvaluationSet()
        self.evolve_image()
Exemple #2
0
    print "Proper usage: ./run distort.py <network> <input_image> <output_image>"
    exit(0)

# Imports.
import PyHyperNEAT as neat
from PyQt5.QtGui import QApplication, QImage, QPixmap

import gui.PopulationModel

print "-------------------------------------------------------------------"
print "DISTORTING IMAGE"

# Load the file and generate the network.
print "-------------------------------------------------------------------"
print "Loading network..."
neat.initialize()
population = neat.load(argv[1])
individual = population.getIndividual(0, population.getGenerationCount() - 1)
network = individual.spawnFastPhenotypeStack()

# Open the input image.
print "-------------------------------------------------------------------"
print "Distorting image..."
distortion = gui.PopulationModel.PopulationItem()

application = QApplication(argv)
image_map = QPixmap(argv[2])
distorted_image_map = distortion.distort(image_map, network)
distorted_image = QImage(distorted_image_map)
distorted_image.save(argv[3])
Exemple #3
0
    def __init__( self, parent = None ):
        super(Window, self).__init__( parent )
        self.setWindowTitle( 'Interactive Distortion Evolver' )

        ### Experiment Configuration
        # ATW: TODO: When we start getting reasonable distortions, there
        # needs to be a method to reload an old population. For now we'll
        # always make a new one.

        self.experiment_data_dir  = "../external/HyperNEAT/NE/HyperNEAT/out/data"
        self.date_specifier = datetime.now().strftime("%y%m%d_%H%M%S")
        self.image_storage = []

        # Initialize HyperNEAT.
        neat.initialize()

        # See if there is an output directory.
        if not os.path.exists(os.getcwd() + "/output"):
            os.mkdir(os.getcwd() + "/output")

        # Load the image experiment.
        self.experiment = neat.setupExperiment(
            "%s/ImageExperiment.dat" % self.experiment_data_dir,
            "output/imageExp_out_%s.xml" % self.date_specifier )

        # Grab the global parameters.
        self.globals = neat.getGlobalParameters()
        population_size = int(self.globals.getParameterValue('PopulationSize'))

        ### GUI Configuration

        # Set default window size.
        self.setFixedSize( 670, 700 )

        # Initialize the list view for the distorted images.
        lv = QListView( )
        lv.setViewMode( QListView.IconMode )
        lv.setUniformItemSizes( True )
        lv.setSelectionRectVisible( True )
        lv.setMovement( QListView.Static )
        lv.setSelectionMode( QListView.MultiSelection )
        lv.setEditTriggers( QListView.CurrentChanged )
        lv.setResizeMode( QListView.Adjust )
        lv.setIconSize( QSize(120, 120) )
        lv.setMinimumSize( 500, 385 )
        lv.setSpacing( 5 )
        lv.setEnabled( False )
        self.population_list = lv

        # Context menu.
        lv.setContextMenuPolicy( Qt.CustomContextMenu )
        lv.customContextMenuRequested.connect(self.handle_context_menu)

        # Create the population model.
        pm = PopulationModel( population_size )
        self.population_model = pm
        lv.setModel( pm )
        for i in xrange(population_size):
            self.population_model.update_item( i, DummyNetwork( i % 4 + 1 ) )

        # Monitor population list selection changes.
        lv.selectionModel().selectionChanged.connect(self.handle_listview_change )

        # Initialize widgets for displaying the graphic and for choosing
        # a new base image.
        btn_select_image = QPushButton( "Load Image" )
        btn_select_image.released.connect(self.select_image)
        lbl_image = QLabel( "Nothing loaded" )
        lbl_image.setFixedSize( 120, 120 )
        self.original_image_label = lbl_image
        image_layout = QVBoxLayout()
        image_layout.addWidget( btn_select_image )
        image_layout.addWidget( lbl_image )

        # Initialize a horizontal layout for the parameters.
        gb = QGroupBox( "Evolution Parameters" )
        gb.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding )

        tw = QTableWidget( 1, 2 )
        tw.setHorizontalHeaderLabels("Parameter;Value".split(';'))
        tw.setColumnWidth( 0, 350 )
        tw.horizontalHeader().setStretchLastSection( True )
        tw.itemChanged.connect(self.handle_parameter_change)
        self.parameter_table = tw

        tw_layout = QVBoxLayout()
        tw_layout.addWidget( tw )
        gb.setLayout( tw_layout )

        param_layout = QHBoxLayout()
        param_layout.addLayout( image_layout )
        param_layout.addWidget( gb )

        # Grab the global parameters.
        parameter_count = self.globals.getParameterCount()
        tw.setRowCount( parameter_count )
        for p in xrange(parameter_count):
            parameter_name = self.globals.getParameterName( p )
            tw.model().setData( tw.model().index( p, 0 ), parameter_name )
            tw.model().setData( tw.model().index( p, 1 ), self.globals.getParameterValue( parameter_name ) )
            index = tw.item( p, 0 )
            index.setFlags( index.flags() ^ Qt.ItemIsEditable )

        # Initialize a horizontal layout for the evolve button.
        btn_evolve = QPushButton( "Shuffle" )
        btn_evolve.released.connect(self.evolve_image)
        btn_evolve.setEnabled( False )
        self.btn_evolve = btn_evolve
        self.btn_evolve.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred )

        self.spin_evolve_iterations = QSpinBox()
        self.spin_evolve_iterations.setRange( 1, 100 )
        self.spin_evolve_iterations.setValue( 1 )

        self.cb_cross_correlate = QCheckBox( "X-Corr" )
        self.cb_cross_correlate.setChecked( True )

        control_layout = QHBoxLayout()
        control_layout.addWidget( btn_evolve )
        control_layout.addWidget( self.spin_evolve_iterations )
        control_layout.addWidget( self.cb_cross_correlate )

        # Initialize vertical central layout.
        central_layout = QVBoxLayout()
        central_layout.addLayout( param_layout )
        central_layout.addWidget( lv )
        central_layout.addLayout( control_layout )
        central_widget = QFrame()
        central_widget.setLayout( central_layout )

        self.setCentralWidget( central_widget )

        # Create a menu
        self.image_menu = QMenu("Menu", self)
        self.image_menu_save_image = self.image_menu.addAction("Save Selected Images")
        self.image_menu_save_network = self.image_menu.addAction("Save Selected Neural Network")

        ### Initialization

        # Handle command line parameters.
        if len(sys.argv) >= 2:
            self.select_image(sys.argv[1])

        # Create progress dialog.
        self.progress_dialog = QProgressDialog( self );
        self.progress_dialog.setLabelText( "Evolving population..." )
        self.progress_dialog.setWindowModality( Qt.WindowModal );
        self.progress_dialog.setVisible( False )
        self.progress_dialog.setCancelButton( None )

        # Start evolver thread.
        self.evolve_thread = EvolveThread( self )
        self.evolve_thread.finished_job.connect( self.finish_evolution )
        self.evolve_thread.update_progress.connect( self.update_evolution_progress )
        self.evolve_thread.start()

        # Generate first population.
        self.population = self.experiment.pythonEvaluationSet()
        self.evolve_image()
Exemple #4
0
    print "Proper usage: ./run distort.py <network> <input_image> <output_image>"
    exit( 0 )

# Imports.
import PyHyperNEAT as neat
from PyQt5.QtGui import QApplication, QImage, QPixmap

import gui.PopulationModel

print "-------------------------------------------------------------------"
print "DISTORTING IMAGE"

# Load the file and generate the network.
print "-------------------------------------------------------------------"
print "Loading network..."
neat.initialize()
population = neat.load( argv[1] )
individual = population.getIndividual( 0, population.getGenerationCount() - 1 )
network = individual.spawnFastPhenotypeStack()

# Open the input image.
print "-------------------------------------------------------------------"
print "Distorting image..."
distortion = gui.PopulationModel.PopulationItem()

application = QApplication( argv )
image_map = QPixmap( argv[2] )
distorted_image_map = distortion.distort( image_map, network )
distorted_image = QImage( distorted_image_map )
distorted_image.save( argv[3] )