畳み込みニューラルネットワークで、エラーが発生します。
(ValueError: Negative dimension size caused by subtracting 3 from 1 for 'conv2d_37/convolution' (op: 'Conv2D') with input shapes: [?,1,784,1], [3,3,1,32].)
conv2dのパラメータの設定が悪いのでしょうか?
どなたか、お詳しい方、ご指導頂ければ助かります。
x_train = x_train.reshape(x_train.shape[0], 28, 28,1) x_test = x_test.reshape(x_test.shape[0], 28, 28,1) input_shape=(28,28,1)))
これを、以下のように修正しただけなのですが、エラーとなります。(上記のコードでは正常に動作)
x_train = x_train.reshape(x_train.shape[0], 1, 784,1) x_test = x_test.reshape(x_test.shape[0], 1, 784,1) input_shape=(1, 784,1)))
以下は、エラーが発生した全コードです。
# データを高速かつ効率的に使えるPandasをインポート import pandas as pd # 数値計算を効率的に行うNumpyをインポート import numpy as np # グラフが簡単に描写できるMatplotlibをインポート import matplotlib import matplotlib.pyplot as plt # 28x28x1のサイズへ変換 #x_train = x_train.reshape(x_train.shape[0], 28, 28,1) x_train = x_train.reshape(x_train.shape[0], 1, 784,1) #x_test = x_test.reshape(x_test.shape[0], 28, 28,1) x_test = x_test.reshape(x_test.shape[0], 1, 784,1) # モデルの宣言 model = Sequential() # 先に作成したmodelへレイヤーを追加 model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(1, 784,1))) #input_shape=(28,28,1))) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(32, activation='relu')) model.add(Dense(10, activation='softmax')) # Learnig Processの設定 model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
以下、エラーメッセージです。
--------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) C:\python\anaconda\pgm\lib\site-packages\tensorflow\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs) 1863 try: -> 1864 c_op = c_api.TF_FinishOperation(op_desc) 1865 except errors.InvalidArgumentError as e: InvalidArgumentError: Negative dimension size caused by subtracting 3 from 1 for 'conv2d_37/convolution' (op: 'Conv2D') with input shapes: [?,1,784,1], [3,3,1,32]. During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) <ipython-input-244-f0598274ae13> in <module> 22 #model.add(Conv2D(32, kernel_size=(3, 3), 23 activation='relu', ---> 24 input_shape=(1, 784,1))) 25 #input_shape=(28,28,1))) 26 model.add(MaxPooling2D(pool_size=(2, 2))) C:\python\anaconda\pgm\lib\site-packages\keras\engine\sequential.py in add(self, layer) 163 # and create the node connecting the current layer 164 # to the input layer we just created. --> 165 layer(x) 166 set_inputs = True 167 else: C:\python\anaconda\pgm\lib\site-packages\keras\engine\base_layer.py in __call__(self, inputs, **kwargs) 455 # Actually call the layer, 456 # collecting output(s), mask(s), and shape(s). --> 457 output = self.call(inputs, **kwargs) 458 output_mask = self.compute_mask(inputs, previous_mask) 459 C:\python\anaconda\pgm\lib\site-packages\keras\layers\convolutional.py in call(self, inputs) 169 padding=self.padding, 170 data_format=self.data_format, --> 171 dilation_rate=self.dilation_rate) 172 if self.rank == 3: 173 outputs = K.conv3d( C:\python\anaconda\pgm\lib\site-packages\keras\backend\tensorflow_backend.py in conv2d(x, kernel, strides, padding, data_format, dilation_rate) 3648 strides=strides, 3649 padding=padding, -> 3650 data_format=tf_data_format) 3651 3652 if data_format == 'channels_first' and tf_data_format == 'NHWC': C:\python\anaconda\pgm\lib\site-packages\tensorflow\python\ops\nn_ops.py in convolution(input, filter, padding, strides, dilation_rate, name, data_format, filters, dilations) 892 data_format=data_format, 893 dilations=dilation_rate, --> 894 name=name) 895 896 C:\python\anaconda\pgm\lib\site-packages\tensorflow\python\ops\nn_ops.py in convolution_internal(input, filters, strides, padding, data_format, dilations, name) 969 data_format=data_format, 970 dilations=dilations, --> 971 name=name) 972 else: 973 if channel_index == 1: C:\python\anaconda\pgm\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py in conv2d(input, filter, strides, padding, use_cudnn_on_gpu, explicit_paddings, data_format, dilations, name) 1159 padding=padding, use_cudnn_on_gpu=use_cudnn_on_gpu, 1160 explicit_paddings=explicit_paddings, -> 1161 data_format=data_format, dilations=dilations, name=name) 1162 _result = _op.outputs[:] 1163 _inputs_flat = _op.inputs C:\python\anaconda\pgm\lib\site-packages\tensorflow\python\framework\op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords) 786 op = g.create_op(op_type_name, inputs, dtypes=None, name=scope, 787 input_types=input_types, attrs=attr_protos, --> 788 op_def=op_def) 789 return output_structure, op_def.is_stateful, op 790 C:\python\anaconda\pgm\lib\site-packages\tensorflow\python\util\deprecation.py in new_func(*args, **kwargs) 505 'in a future version' if date is None else ('after %s' % date), 506 instructions) --> 507 return func(*args, **kwargs) 508 509 doc = _add_deprecated_arg_notice_to_docstring( C:\python\anaconda\pgm\lib\site-packages\tensorflow\python\framework\ops.py in create_op(***failed resolving arguments***) 3614 input_types=input_types, 3615 original_op=self._default_original_op, -> 3616 op_def=op_def) 3617 self._create_op_helper(ret, compute_device=compute_device) 3618 return ret C:\python\anaconda\pgm\lib\site-packages\tensorflow\python\framework\ops.py in __init__(self, node_def, g, inputs, output_types, control_inputs, input_types, original_op, op_def) 2025 op_def, inputs, node_def.attr) 2026 self._c_op = _create_c_op(self._graph, node_def, grouped_inputs, -> 2027 control_input_ops) 2028 2029 # Initialize self._outputs. C:\python\anaconda\pgm\lib\site-packages\tensorflow\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs) 1865 except errors.InvalidArgumentError as e: 1866 # Convert to ValueError for backwards compatibility. -> 1867 raise ValueError(str(e)) 1868 1869 return c_op ValueError: Negative dimension size caused by subtracting 3 from 1 for 'conv2d_37/convolution' (op: 'Conv2D') with input shapes: [?,1,784,1], [3,3,1,32].
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/11/20 08:35
2019/11/20 09:06 編集
2019/11/20 08:58
2019/11/20 08:59
2019/11/20 09:11 編集
2019/11/20 09:11
2019/11/20 09:23
2019/11/20 09:33
2019/11/21 03:17