Skip to content

Commit

Permalink
Fixed recently-introduced crashing bug on save. Added ability to unsh…
Browse files Browse the repository at this point in the history
…are convolutional units.

git-svn-id: http://cuda-convnet.googlecode.com/svn/trunk@391 bc73d74b-de6f-cad7-86a4-6ddd3d5d919c
  • Loading branch information
akrizhevsky committed Oct 15, 2011
1 parent fbaa0d7 commit c54fce3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
15 changes: 11 additions & 4 deletions convnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from gpumodel import *
import sys
import math as m
from layer import LayerParser, LayerParsingError
import layer as lay
from convdata import *
from os import linesep as NL

Expand All @@ -47,14 +47,20 @@ def init_model_lib(self):
def init_model_state(self):
ms = self.model_state
if self.load_file:
ms['layers'] = LayerParser.parse_layers(self.layer_def, self.layer_params, self, ms['layers'])
ms['layers'] = lay.LayerParser.parse_layers(self.layer_def, self.layer_params, self, ms['layers'])
else:
ms['layers'] = LayerParser.parse_layers(self.layer_def, self.layer_params, self)
ms['layers'] = lay.LayerParser.parse_layers(self.layer_def, self.layer_params, self)

logreg_name = self.op.get_value('logreg_name')
if logreg_name:
self.logreg_idx = self.get_layer_idx(logreg_name, check_type='cost.logreg')


# Convert convolutional layers to local
if self.op.get_value('unshare_conv'):
for layer in ms['layers']:
if layer['type'] == 'conv':
lay.LocalLayerParser.conv_to_local(layer)

def get_layer_idx(self, layer_name, check_type=None):
try:
layer_idx = [l['name'] for l in self.model_state['layers']].index(layer_name)
Expand Down Expand Up @@ -145,6 +151,7 @@ def get_options_parser(cls):
op.add_option("multiview-test", "multiview_test", BooleanOptionParser, "Cropped DP: test on multiple patches?", default=0, requires=['logreg_name'])
op.add_option("crop-border", "crop_border", IntegerOptionParser, "Cropped DP: crop border size", default=4, set_once=True)
op.add_option("logreg-name", "logreg_name", StringOptionParser, "Cropped DP: logreg layer name", default="")
op.add_option("unshare-conv", "unshare_conv", BooleanOptionParser, "Convert all convolutional layers to unshared locally-connected?", default=False)

op.delete_option('max_test_err')
op.options["max_filesize_mb"].default = 0
Expand Down
2 changes: 1 addition & 1 deletion include/common/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class Matrix {
* Use transpose() if you want to get the transpose of this matrix.
*/
inline void setTrans(bool trans) {
assert(!isView());
assert(isTrans() == trans || !isView());
_trans = trans ? CblasTrans : CblasNoTrans;
}

Expand Down
10 changes: 10 additions & 0 deletions layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ class LocalLayerParser(LayerWithInputParser):
def __init__(self):
LayerWithInputParser.__init__(self, num_inputs=1)

@staticmethod
def conv_to_local(layer):
for w in ('weights', 'weightsInc'):
layer[w] = n.require(n.reshape(n.tile(n.reshape(layer[w], (1, n.prod(layer[w].shape))), (layer['modules'], 1)), (layer['modules'] * layer['channels'] * layer['filterPixels'], layer['filters'])), requirements='C')
if layer['sharedBiases']:
for b in ('biases', 'biasesInc'):
layer[b] = n.require(n.tile(layer[b], (layer['modules'], 1)), requirements='C')
layer['type'] = 'local'
return layer

def requires_params(self):
return True

Expand Down
3 changes: 2 additions & 1 deletion shownet.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def plot_cost(self):
test_errors = numpy.row_stack(test_errors)
test_errors = numpy.tile(test_errors, (1, self.testing_freq))
test_errors = list(test_errors.flatten())
test_errors += [test_errors[-1]] * (len(train_errors) - len(test_errors))
test_errors += [test_errors[-1]] * max(0,len(train_errors) - len(test_errors))
test_errors = test_errors[:len(train_errors)]

numepochs = len(train_errors) / float(numbatches)
pl.figure(1)
Expand Down

0 comments on commit c54fce3

Please sign in to comment.