lisa-lab/pylearn2

[bug] print_monitor_cv.py model not iterable

Closed this issue · 2 comments

TNick commented

I've tried print_monitor_cv.py model.pkl but I've got

Traceback (most recent call last):
  File "~/pylearn2/pylearn2/scripts/print_monitor_cv.py", line 84, in <module>
    main(**vars(args))
  File "~/pylearn2/pylearn2/scripts/print_monitor_cv.py", line 38, in main
    for model in list(this_models):
TypeError: 'MLP' object is not iterable

so I changed this part:

        this_models = serial.load(filename)
        for model in list(this_models):
            # ...

to

        # ....
        this_models = serial.load(filename)

        try:
            this_models = list(this_models)
        except TypeError:
            this_models = [this_models]

        for model in this_models:
            # ...

PR?

At first, I was not sure why you would use print_monitor_cv.py on a pkl file with only one model inside, but it makes sense if you specify more than one pkl, and there is already a special case when there is only one model at all.
Then, I think such a PR would be a good idea. Instead of relying on TypeError to check if this_models is iterable or not, maybe you can use something like:

if not isinstance(this_models, collections.Iterable):
    this_models = [this_models]
for model in this_models:
    ...
TNick commented

Ask forgiveness not permission? :)
Ok, I'll do that.