错误(theano.gof.opt):由于以下原因导致优化失败:
LocalOptGroup(local_abstractconv_gemm,local_abstractconv_gradinputs_gemm,local_abstractconv_gradweight_gemm,local_conv2d_cpu,local_conv2d_gradinputs_cpu,local_conv2d_gradweight_cpu)
错误(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)错误(theano.gof.opt):
TRACEBACK:ERROR(theano.gof.opt):Traceback(最近一次调用最后一次): 文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第1772行, process_node replacements = lopt.transform(node)文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第1223行,in 转变 repl = opt.transform(node)文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ tensor \ nnet \ opt.py”,第153行, 在local_conv2d_cpu中 subsample = node.op.subsample)文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ tensor \ nnet \ conv.py”,第132行, 在conv2d 断言image_shape [1] == filter_shape [1] AssertionError
图像[无,无,无,无]过滤器[512,512,3,3]回溯 (最近一次电话会议):
文件“”,第1行,in runfile('E:/ Deep Learning / vgg.py',wdir ='E:/ Deep Learning')
文件 “d:\ Anaconda2 \ LIB \站点包\ spyderlib \部件\ externalshell \ sitecustomize.py” 第699行,在runfile中 execfile(filename,namespace)
文件 “d:\ Anaconda2 \ LIB \站点包\ spyderlib \部件\ externalshell \ sitecustomize.py” 第74行,在execfile中 exec(compile(scripttext,filename,'exec'),glob,loc)
文件“E:/ Deep Learning / vgg.py”,第110行,in model.fit(数据,标签,的batch_size = 100,nb_epoch = 10,随机播放=真,冗长= 1,show_accuracy =真,validation_split = 0.2)
文件“D:\ Anaconda2 \ lib \ site-packages \ keras \ models.py”,第402行, 适合 sample_weight = sample_weight)
文件“D:\ Anaconda2 \ lib \ site-packages \ keras \ engine \ training.py”,行 999,合适 self._make_test_function()
文件“D:\ Anaconda2 \ lib \ site-packages \ keras \ engine \ training.py”,行 666,在_make_test_function中 ** self._function_kwargs)
文件 “D:\ Anaconda2 \ lib \ site-packages \ keras \ backend \ theano_backend.py”,行 503,在功能上 return函数(输入,输出,更新=更新,** kwargs)
文件 “D:\ Anaconda2 \ lib \ site-packages \ keras \ backend \ theano_backend.py”,行 489,在 init 中 ** kwargs)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ compile \ function.py”, 第320行,在功能上 output_keys = output_keys)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ compile \ pfunc.py”,行 479,在pfunc output_keys = output_keys)
文件 “d:\ Anaconda2 \ LIB \站点包\ theano \编译\ function_module.py” 第1776行,orig_function output_keys = output_keys).create(
文件 “d:\ Anaconda2 \ LIB \站点包\ theano \编译\ function_module.py” 第1456行, init optimizer_profile = optimizer(fgraph)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第101行, 在通话 return self.optimize(fgraph)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第89行, 优化 ret = self.apply(fgraph,* args,** kwargs)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第230行, 申请 sub_prof = optimizer.optimize(fgraph)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第89行, 优化 ret = self.apply(fgraph,* args,** kwargs)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第2196行, 申请 lopt_change = self.process_node(fgraph,node,lopt)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第1777行, 在process_node中 lopt,node)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第1673行, 在warn_inplace 返回NavigatorOptimizer.warn(exc,nav,repl_pairs,local_opt,node)
文件“D:\ Anaconda2 \ lib \ site-packages \ theano \ gof \ opt.py”,第1659行, 在警告 提出意见
的AssertionError
这是我的代码
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)
答案 0 :(得分:2)
我遇到了与keras / theano相同的问题。通过将theano升级到版本0.8.2解决了错误。请检查您的theano版本> = 0.8.2并尝试将theano升级到版本0.8.2,相反的情况。例如,使用pip install:
pip install theano==0.8.2