changeset 340:523e7b87c521

Corrected a few bugs, no new features. Supposedly ready to run on cluster.
author fsavard
date Sun, 18 Apr 2010 11:39:24 -0400
parents ffbf0e41bcee
children bc3faa9ad8b8
files deep/crbm/mnist_config.py.example deep/crbm/mnist_crbm.py
diffstat 2 files changed, 60 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/deep/crbm/mnist_config.py.example	Sat Apr 17 20:29:18 2010 -0400
+++ b/deep/crbm/mnist_config.py.example	Sun Apr 18 11:39:24 2010 -0400
@@ -1,43 +1,44 @@
 # ----------------------------------------------------------------------------
 # BEGIN EXPERIMENT ISOLATION CODE
 
-'''
-This makes sure we use the codebase clone created for this experiment.
-I.e. if you want to make modifications to the codebase but don't want your
-running experiment code to be impacted by those changes, first copy the
-codebase somewhere, and configure this section. It will make sure we import
-from the right place.
+def isolate_experiment():
+    '''
+    This makes sure we use the codebase clone created for this experiment.
+    I.e. if you want to make modifications to the codebase but don't want your
+    running experiment code to be impacted by those changes, first copy the
+    codebase somewhere, and configure this section. It will make sure we import
+    from the right place.
 
-MUST BE DONE BEFORE IMPORTING ANYTHING ELSE
-(Leave this comment there so others will understand what's going on)
-'''
+    MUST BE DONE BEFORE IMPORTING ANYTHING ELSE
+    (Leave this comment there so others will understand what's going on)
+    '''
 
-# Place where you copied modules that should be frozen for this experiment
-codebase_clone_path = "/u/savardf/ift6266/experiment_clones/ift6266_mnistcrbm_exp1"
+    # Place where you copied modules that should be frozen for this experiment
+    codebase_clone_path = "/u/savardf/ift6266/experiment_clones/ift6266_mnistcrbm_exp1"
 
-# Places where there might be conflicting modules from your $PYTHONPATH
-remove_these_from_pythonpath = ["/u/savardf/ift6266/dev_code"]
+    # Places where there might be conflicting modules from your $PYTHONPATH
+    remove_these_from_pythonpath = ["/u/savardf/ift6266/dev_code"]
 
-import sys
-sys.path[0:0] = [codebase_clone_path]
+    import sys
+    sys.path[0:0] = [codebase_clone_path]
 
-# remove paths we specifically don't want in $PYTHONPATH
-for bad_path in remove_these_from_pythonpath:
-    sys.path[:] = [el for el in sys.path if not el in (bad_path, bad_path+"/")]
+    # remove paths we specifically don't want in $PYTHONPATH
+    for bad_path in remove_these_from_pythonpath:
+        sys.path[:] = [el for el in sys.path if not el in (bad_path, bad_path+"/")]
 
-# Make the imports
-import ift6266
+    # Make the imports
+    import ift6266
 
-# Just making sure we're importing from the right place
-modules_to_check = [ift6266]
-for module in modules_to_check:
-    if not codebase_clone_path in module.__path__[0]:
-        raise RuntimeError("Module loaded from incorrect path "+module.__path__[0])
+    # Just making sure we're importing from the right place
+    modules_to_check = [ift6266]
+    for module in modules_to_check:
+        if not codebase_clone_path in module.__path__[0]:
+            raise RuntimeError("Module loaded from incorrect path "+module.__path__[0])
 
-# Path to pass to jobman sqlschedule. IMPORTANT TO CHANGE TO REFLECT YOUR CLONE.
-# Make sure this is accessible from the default $PYTHONPATH (in your .bashrc)
-# (and make sure every subdirectory has its __init__.py file)
-EXPERIMENT_PATH = "ift6266_mnistcrbm_exp1.ift6266.deep.crbm.mnist_crbm.jobman_entrypoint"
+    # Path to pass to jobman sqlschedule. IMPORTANT TO CHANGE TO REFLECT YOUR CLONE.
+    # Make sure this is accessible from the default $PYTHONPATH (in your .bashrc)
+    # (and make sure every subdirectory has its __init__.py file)
+    EXPERIMENT_PATH = "ift6266_mnistcrbm_exp1.ift6266.deep.crbm.mnist_crbm.jobman_entrypoint"
 
 # END EXPERIMENT ISOLATION CODE
 # ----------------------------------------------------------------------------
@@ -53,7 +54,7 @@
 '''
 
 # change "sandbox" when you're ready
-JOBDB = 'postgres://ift6266h10@gershwin/ift6266h10_db/fsavard_mnistcrbm_exp1'
+JOBDB = 'postgres://ift6266h10@gershwin/ift6266h10_sandbox_db/yourtablenamehere'
 
 # Set this to True when you want to run cluster tests, ie. you want
 # to run on the cluster, many jobs, but want to reduce the training
@@ -76,6 +77,10 @@
 VISUALIZE_EVERY = 20000
 GIBBS_STEPS_IN_VIZ_CHAIN = 1000
 
+if TEST_CONFIG:
+    REDUCE_EVERY = 10
+    VISUALIZE_EVERY = 20
+
 # This is to configure insertion of jobs on the cluster.
 # Possible values the hyperparameters can take. These are then
 # combined with produit_cartesien_jobs so we get a list of all
@@ -86,7 +91,8 @@
         'sparsity_p': [0.3,0.05],
         'num_filters': [40,15],
         'filter_size': [12,7],
-        'minibatch_size': [20]}
+        'minibatch_size': [20],
+        'num_epochs': [20]}
 
 # Just useful for tests... minimal number of epochs
 # Useful when launching a single local job
@@ -95,7 +101,8 @@
         'sparsity_p': 0.05,
         'num_filters': 40,
         'filter_size': 12,
-        'minibatch_size': 10})
+        'minibatch_size': 10,
+        'num_epochs': 20})
 
 # To reinsert duplicate of jobs that crashed
 REINSERT_COLS = ['learning_rate','sparsity_lambda','sparsity_p','num_filters','filter_size','minibatch_size','dupe']
--- a/deep/crbm/mnist_crbm.py	Sat Apr 17 20:29:18 2010 -0400
+++ b/deep/crbm/mnist_crbm.py	Sun Apr 18 11:39:24 2010 -0400
@@ -1,9 +1,15 @@
 #!/usr/bin/python
 
-# do this first
+import sys
+
+# do this before importing custom modules
 from mnist_config import *
 
-import sys
+if not (len(sys.argv) > 1 and sys.argv[1] in \
+            ('test_jobman_entrypoint', 'run_local')):
+    # in those cases don't use isolated code, use dev code
+    isolate_code()
+
 import os, os.path
 
 import numpy as N
@@ -13,6 +19,7 @@
 
 from crbm import CRBM, ConvolutionParams
 
+import pylearn, pylearn.version
 from pylearn.datasets import MNIST
 from pylearn.io.image_tiling import tile_raster_images
 
@@ -21,8 +28,16 @@
 from pylearn.io.seriestables import *
 import tables
 
+import ift6266
+
 import utils
 
+if not os.path.exists(IMAGE_OUTPUT_DIR):
+    os.mkdir(IMAGE_OUTPUT_DIR)
+elif os.path.isfile(IMAGE_OUTPUT_DIR):
+    print "IMAGE_OUTPUT_DIR is not a directory!"
+    sys.exit(1)
+
 #def filename_from_time(suffix):
 #    import datetime
 #    return str(datetime.datetime.now()) + suffix + ".png"
@@ -42,7 +57,11 @@
         self.state = state
 
         if TEST_CONFIG:
+            self.mnist = MNIST.first_1k()
+            print "Test config, so loaded MNIST first 1000"
+        else:
             self.mnist = MNIST.full()#first_10k()
+            print "Loaded MNIST full"
 
         self.cp = ConvolutionParams( \
                     num_filters=state.num_filters,