#!/usr/bin/env python 

import cPickle as pickle
from sklearn.datasets import dump_svmlight_file
import sys

from glimpse.experiment import *

def Main(input_file, train_file, test_file):
  with open(input_file) as fh:
    exp = pickle.load(fh)
  ftrs = ExtractFeatures(Layer.C2, exp.extractor.activation)
  trng = GetTrainingSet(exp)
  dump_svmlight_file(ftrs[trng], exp.corpus.labels[trng] + 1, train_file, zero_based=False)
  dump_svmlight_file(ftrs[~trng], exp.corpus.labels[~trng] + 1, test_file, zero_based=False)
  print "Categories"
  print "----------"
  print "\n".join("%d - %s" % (index+1,name) for (index,name) in enumerate(exp.corpus.class_names))

if __name__ == '__main__':
  if len(sys.argv) < 4:
    sys.exit("usage: %s EXP.pkl TRAIN.svm TEST.svm" % sys.argv[0])
  Main(*sys.argv[1:4])

@@ -14,17 +14,16 @@
 v python
- 
 %0A%0Aimport
@@ -139,20 +139,35 @@
  *%0A%0Adef 
-Main
+glimpse_to_svmlight
 (input_f
@@ -674,34 +674,67 @@
 ))%0A%0A
-if __name__ == '__main__':
+def Main(argv=None):%0A  if argv is None:%0A    argv = sys.argv
 %0A  i
@@ -739,20 +739,16 @@
  if len(
-sys.
 argv) %3C 
@@ -823,25 +823,73 @@
 )%0A  
-Main(*sys.argv%5B1:4%5D
+glimpse_to_svmlight(*argv%5B1:4%5D)%0A%0Aif __name__ == '__main__':%0A  Main(
 )%0A

fix glimpse_to_svmlight entrypoint