driver.py 1.75 KB
Newer Older
Laurent EL SHAFEY's avatar
Laurent EL SHAFEY committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# @author: Laurent El Shafey <Laurent.El-Shafey@idiap.ch>
# @date: Wed May 8 19:15:47 CEST 2013
#
# Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Commands the MNIST database can respond to.
"""

import os
import sys
Manuel Günther's avatar
Manuel Günther committed
25
from bob.db.base.driver import Interface as BaseInterface
Laurent EL SHAFEY's avatar
Laurent EL SHAFEY committed
26

27
28
29
30
31
32
33
34
35
36

def download_mnist(self):
  # Hack that will download the mnist database

  import pkg_resources
  import bob.db.mnist
  db_folder = pkg_resources.resource_filename(__name__, '') # Defining a folder for download
  db = bob.db.mnist.Database(data_dir=db_folder) # Downloading
  del db

Laurent EL SHAFEY's avatar
Laurent EL SHAFEY committed
37
38
39
40
41
42
43
class Interface(BaseInterface):

  def name(self):
    return 'mnist'

  def version(self):
    import pkg_resources  # part of setuptools
Manuel Günther's avatar
Manuel Günther committed
44
    return pkg_resources.require('bob.db.%s' % self.name())[0].version
Laurent EL SHAFEY's avatar
Laurent EL SHAFEY committed
45
46
47
48
49

  def files(self):
    return ()

  def type(self):
50
    return 'binary'
Laurent EL SHAFEY's avatar
Laurent EL SHAFEY committed
51

Laurent EL SHAFEY's avatar
Laurent EL SHAFEY committed
52
53
54
  def add_commands(self, parser):

    from . import __doc__ as docs
55
    from bob.db.base.driver import download_command
Laurent EL SHAFEY's avatar
Laurent EL SHAFEY committed
56
    subparsers = self.setup_parser(parser, "MNIST database", docs)
57
58
59
60
61

    parser = download_command(subparsers)
    parser.set_defaults(func=download_mnist)