4
votes

who can give me some notice when casue this error ? I am use VGG16-net to do face recongnition.

ERROR (theano.gof.opt): Optimization failure due to:

LocalOptGroup(local_abstractconv_gemm,local_abstractconv_gradinputs_gemm,local_abstractconv_gradweight_gemm,local_conv2d_cpu,local_conv2d_gradinputs_cpu,local_conv2d_gradweight_cpu)

ERROR (theano.gof.opt): node: AbstractConv2d{border_mode='valid', subsample=(1, 1), filter_flip=True, imshp=(None, None, None, None), kshp=(512, 512, 3, 3)}(IncSubtensor{Set;::, ::, int64:int64:, int64:int64:}.0, convolution2d_26_W) ERROR (theano.gof.opt):

TRACEBACK: ERROR (theano.gof.opt): Traceback (most recent call last): File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 1772, in process_node replacements = lopt.transform(node) File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 1223, in transform repl = opt.transform(node) File "D:\Anaconda2\lib\site-packages\theano\tensor\nnet\opt.py", line 153, in local_conv2d_cpu subsample=node.op.subsample) File "D:\Anaconda2\lib\site-packages\theano\tensor\nnet\conv.py", line 132, in conv2d assert image_shape[1] == filter_shape[1] AssertionError

image [None, None, None, None] filters [512, 512, 3, 3] Traceback (most recent call last):

File "", line 1, in runfile('E:/Deep Learning/vgg.py', wdir='E:/Deep Learning')

File "D:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile execfile(filename, namespace)

File "D:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc)

File "E:/Deep Learning/vgg.py", line 110, in model.fit(data,label,batch_size=100,nb_epoch=10,shuffle=True,verbose=1,show_accuracy=True,validation_split=0.2)

File "D:\Anaconda2\lib\site-packages\keras\models.py", line 402, in fit sample_weight=sample_weight)

File "D:\Anaconda2\lib\site-packages\keras\engine\training.py", line 999, in fit self._make_test_function()

File "D:\Anaconda2\lib\site-packages\keras\engine\training.py", line 666, in _make_test_function **self._function_kwargs)

File "D:\Anaconda2\lib\site-packages\keras\backend\theano_backend.py", line 503, in function return Function(inputs, outputs, updates=updates, **kwargs)

File "D:\Anaconda2\lib\site-packages\keras\backend\theano_backend.py", line 489, in init **kwargs)

File "D:\Anaconda2\lib\site-packages\theano\compile\function.py", line 320, in function output_keys=output_keys)

File "D:\Anaconda2\lib\site-packages\theano\compile\pfunc.py", line 479, in pfunc output_keys=output_keys)

File "D:\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 1776, in orig_function output_keys=output_keys).create(

File "D:\Anaconda2\lib\site-packages\theano\compile\function_module.py", line 1456, in init optimizer_profile = optimizer(fgraph)

File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 101, in call return self.optimize(fgraph)

File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 89, in optimize ret = self.apply(fgraph, *args, **kwargs)

File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 230, in apply sub_prof = optimizer.optimize(fgraph)

File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 89, in optimize ret = self.apply(fgraph, *args, **kwargs)

File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 2196, in apply lopt_change = self.process_node(fgraph, node, lopt)

File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 1777, in process_node lopt, node)

File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 1673, in warn_inplace return NavigatorOptimizer.warn(exc, nav, repl_pairs, local_opt, node)

File "D:\Anaconda2\lib\site-packages\theano\gof\opt.py", line 1659, in warn raise exc

AssertionError

this is my code

def VGG_16(weights_path=None):
    model = Sequential()
    model.add(ZeroPadding2D((1,1),input_shape=(3,64,64)))
    model.add(Convolution2D(64, 3, 3, activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(64, 3, 3, activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(128, 3, 3, activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(128, 3, 3, activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(256, 3, 3, activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(256, 3, 3, activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(256, 3, 3, activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(512, 3, 3, activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(512, 3, 3, activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(512, 3, 3, activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(512, 3, 3, activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(512, 3, 3, activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Convolution2D(512, 3, 3, activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2)))
    return model

    if weights_path:
        import h5py
        f = h5py.File(weights_path)
        for k in range(f.attrs['nb_layers']):
            if k >= len(model.layers):
                # we don't look at the last (fully-connected) layers in the savefile
                break
            g = f['layer_{}'.format(k)]
            weights = [g['param_{}'.format(p)] for p in range(g.attrs['nb_params'])]
            model.layers[k].set_weights(weights)
        f.close()
        print('Model loaded.')

if __name__ == "__main__":

    train_data = np.empty((5800,3,64,64),dtype='float32')
    train_label = np.empty((5800,),dtype="uint8")
    data,label = load_data(r'E:\test\face_64_64\target\train.csv',train_data,train_label)
    # Test pretrained model
    label = np_utils.to_categorical(label,58)

    model = VGG_16()
    model.add(Flatten())
    model.add(Dense(4096, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(4096, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(58, activation='softmax'))
    sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
    model.compile(optimizer=sgd, loss='categorical_crossentropy',class_mode="categorical")
    model.fit(data,label,batch_size=100,nb_epoch=10,shuffle=True,verbose=1,show_accuracy=True,validation_split=0.2)
1
Something seems wrong with your data shape: in conv2d assert image_shape[1] == filter_shape[1] AssertionError image [None, None, None, None] filters [512, 512, 3, 3]Mikael Rousson
my data shape is (3,64,64) you means it doesn't match my net?sky

1 Answers

2
votes

I’ve faced the same issue with keras/theano. Error was solved by upgrade theano to version 0.8.2. Please check that your theano version >= 0.8.2 and try to upgrade theano to version 0.8.2 in the opposite case . For example, with using pip install:

pip install theano==0.8.2