Skip to content

Commit a6701d5

Browse files
committed
2 parents ade32c0 + 9d5c503 commit a6701d5

35 files changed

Lines changed: 233 additions & 85 deletions

setup.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env python
2+
"""
3+
python-dnn uses python (and theano) to implement major Deep Learing Networks.
4+
It currently supports:
5+
CNN
6+
SDA
7+
DBN
8+
A general DNN Finetune kit with maxout and dropout.
9+
"""
10+
11+
from setuptools import setup, find_packages,Command
12+
import subprocess
13+
import os
14+
15+
16+
DOCLINES = __doc__.split("\n")
17+
18+
19+
CLASSIFIERS = """\
20+
Development Status :: 4 - Beta
21+
Intended Audience :: Science/Research
22+
Intended Audience :: Developers
23+
License :: Apache v2.0 License
24+
Programming Language :: C
25+
Programming Language :: Python
26+
Topic :: Software Development
27+
Topic :: Scientific/Engineering
28+
Operating System :: POSIX
29+
30+
"""
31+
32+
MAJOR = 1
33+
MINOR = 0
34+
MICRO = 1
35+
ISRELEASED = True
36+
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
37+
38+
39+
40+
41+
class CleanCommand(Command):
42+
"""Custom clean command to tidy up the project root."""
43+
user_options = []
44+
def initialize_options(self):
45+
pass
46+
def finalize_options(self):
47+
pass
48+
def run(self):
49+
os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info ./src/pythonDnn/version.py ./src/*.egg-info')
50+
51+
52+
# Return the git revision as a string
53+
def git_version():
54+
def _minimal_ext_cmd(cmd):
55+
# construct minimal environment
56+
env = {}
57+
for k in ['SYSTEMROOT', 'PATH']:
58+
v = os.environ.get(k)
59+
if v is not None:
60+
env[k] = v
61+
env['LANGUAGE'] = 'C'
62+
env['LANG'] = 'C'
63+
env['LC_ALL'] = 'C'
64+
out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
65+
return out
66+
67+
try:
68+
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
69+
GIT_REVISION = out.strip().decode('ascii')
70+
except OSError:
71+
GIT_REVISION = "Unknown"
72+
73+
return GIT_REVISION
74+
75+
76+
def get_version_info():
77+
# Adding the git rev number needs to be done inside
78+
# write_version_py(), otherwise the import of scipy.version messes
79+
# up the build under Python 3.
80+
FULLVERSION = VERSION
81+
if os.path.exists('.git'):
82+
GIT_REVISION = git_version()
83+
else:
84+
GIT_REVISION = "Unknown"
85+
86+
if not ISRELEASED:
87+
FULLVERSION += '.dev-' + GIT_REVISION[:7]
88+
89+
return FULLVERSION, GIT_REVISION
90+
91+
92+
def write_version_py(filename='src/pythonDnn/version.py'):
93+
cnt = """
94+
# THIS FILE IS GENERATED FROM SCIPY SETUP.PY
95+
short_version = '%(version)s'
96+
version = '%(version)s'
97+
full_version = '%(full_version)s'
98+
git_revision = '%(git_revision)s'
99+
release = %(isrelease)s
100+
101+
if not release:
102+
version = full_version
103+
"""
104+
FULLVERSION, GIT_REVISION = get_version_info()
105+
106+
a = open(filename, 'w')
107+
try:
108+
a.write(cnt % {'version': VERSION,
109+
'full_version' : FULLVERSION,
110+
'git_revision' : GIT_REVISION,
111+
'isrelease': str(ISRELEASED)})
112+
finally:
113+
a.close()
114+
115+
if __name__ == '__main__':
116+
# Rewrite the version file every time
117+
write_version_py()
118+
119+
try:
120+
import theano
121+
requires=[]
122+
except ImportError:
123+
requires=['theano>=0.7.0']
124+
125+
metadata = dict(
126+
name = 'pythonDnn',
127+
maintainer = "pythonDnn",
128+
maintainer_email = "pythonDnn@ex.org",
129+
description = DOCLINES[0],
130+
long_description = "\n".join(DOCLINES[2:]),
131+
url = "https://github.com/IITM-DONLAB/python-dnn",
132+
download_url = "https://github.com/IITM-DONLAB/python-dnn/zipball/master",
133+
license = 'Apache v2.0 License',
134+
packages = [
135+
'pythonDnn.io_modules', 'pythonDnn.layers', 'pythonDnn.models',
136+
'pythonDnn.run', 'pythonDnn.utils'],
137+
package_dir = {'': 'src'},
138+
install_requires = requires,
139+
zip_safe=False,
140+
cmdclass={'clean': CleanCommand,},
141+
)
142+
FULLVERSION, GIT_REVISION = get_version_info()
143+
metadata['version'] = FULLVERSION
144+
setup(**metadata)

src/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818

1919

20-
from utils.load_conf import load_model
20+
from pythonDnn.utils.load_conf import load_model
2121
import sys
2222

2323
import logging
2424
logger = logging.getLogger(__name__)
25-
from io_modules import setLogger
25+
from pythonDnn.io_modules import setLogger
2626

2727

2828
def setLoggerLevel(modelConfig,name=None):
@@ -49,15 +49,15 @@ def runNet(modelConfig):
4949
nnetType = modelConfig ['nnetType']
5050
logger.info("Loading Other Configuration for %s",nnetType);
5151
if nnetType == 'CNN':
52-
from run.run_CNN import runCNN as runModel
52+
from pythonDnn.run.run_CNN import runCNN as runModel
5353
elif nnetType == 'CNN3D':
54-
from run.run_CNN3d import runCNN3D as runModel
54+
from pythonDnn.run.run_CNN3d import runCNN3D as runModel
5555
elif nnetType == 'RBM':
56-
from run.run_DBN import runRBM as runModel
56+
from pythonDnn.run.run_DBN import runRBM as runModel
5757
elif nnetType == 'SDA':
58-
from run.run_SDA import runSdA as runModel
58+
from pythonDnn.run.run_SDA import runSdA as runModel
5959
elif nnetType == 'DNN':
60-
from run.run_DNN import runDNN as runModel
60+
from pythonDnn.run.run_DNN import runDNN as runModel
6161
else :
6262
logger.error('Unknown nnet Type')
6363
return 1

src/pythonDnn/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import theano
33
import theano.tensor as T
44

5-
from utils.utils import dimshuffle
6-
from io_modules.file_writer import write_dataset
7-
from io_modules.file_reader import read_dataset
8-
from io_modules import create_folder_structure_if_not_exists
5+
from pythonDnn.utils.utils import dimshuffle
6+
from pythonDnn.io_modules.file_writer import write_dataset
7+
from pythonDnn.io_modules.file_reader import read_dataset
8+
from pythonDnn.io_modules import create_folder_structure_if_not_exists
99

1010
import logging
1111
logger = logging.getLogger(__name__)
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json,numpy,sys,os
22
import theano
33
import theano.tensor as T
4-
from utils.utils import dimshuffle
4+
from pythonDnn.utils.utils import dimshuffle
55

66
import logging
77
logger = logging.getLogger(__name__)
@@ -503,6 +503,8 @@ def read_file_info(self):
503503
self.header['featdim'] = self.feat_dim
504504
self.header['classes'] = self.classes
505505

506+
self.childhandles = [None for i in xrange(self.classes)]
507+
506508
logger.debug('T2 Filereader : feat : %d' % self.feat_dim)
507509

508510
#load filehandle for all classes
@@ -521,6 +523,7 @@ def read_file_info(self):
521523
batch_size = self.batch_size
522524
self.setPartitionFrames()
523525

526+
#logger.critical(str(self.last_class_idx))
524527

525528
if self.frames_per_partition < self.classes:
526529
logger.critical('Number of frames per partition must be greater than the number of classes,'
@@ -538,12 +541,12 @@ def read_next_partition_data(self,already_read=0,pad_zeros=False,makeShared=True
538541
while cur_frame_num < self.frames_per_partition and none_cnt < self.classes :
539542
if self.childhandles[self.last_class_idx] is None:
540543
#if the child handle is not initialized
541-
data_file = self.filenames[self.last_class_idx][fileIndex[self.last_class_idx]];
544+
data_file = self.filenames[self.last_class_idx][self.fileIndex[self.last_class_idx]];
542545
##Get Next Filename in last Class.
543546
if data_file != None:
544547
#if Next Filename == NULL;
545548

546-
fileIndex[self.last_class_idx] = fileIndex[self.last_class_idx] + 1;
549+
self.fileIndex[self.last_class_idx] = self.fileIndex[self.last_class_idx] + 1;
547550
child_options = self.options.copy()
548551
child_options['filename']=data_file
549552
child_options['label']= self.last_class_idx
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import json,numpy,os
3-
from io_modules import create_folder_structure_if_not_exists
3+
from pythonDnn.io_modules import create_folder_structure_if_not_exists
44

55
import logging
66
logger = logging.getLogger(__name__)

0 commit comments

Comments
 (0)