エラーについて(Failed `shape_weights.size() == 2 + spatial_dims`: Weights must be a tensor more than 3D.)

60 views
Skip to first unread message

Igarashi Sota

unread,
Mar 22, 2024, 3:55:37 AM3/22/24
to Neural Network Console Users (JP)
お世話になります。
添付(network.png)をPythonコードでエクスポートし、
Python上で推論させてみたのですが、表題のエラーが現れます。
対処方法についてご教示いただきたいです。

〇エラー内容
    h = PF.convolution(h, outmaps=3, kernel=(7,7), pad=(0,0), name='Convolution')
  File "<string>", line 8, in convolution
  File "C:\Users\lib\site-packages\nnabla\parametric_functions.py", line 636, in convolution
    return F.convolution(inp, w, b, base_axis, pad, stride, dilation, group, channel_last)
  File "<convolution>", line 3, in convolution
  File "C:\Users\lib\site-packages\nnabla\function_bases.py", line 342, in convolution
    return F.Convolution(ctx, base_axis, pad, stride, dilation, group, channel_last)(*inputs, n_outputs=n_outputs, auto_forward=get_auto_forward(), outputs=outputs)
  File "function.pyx", line 337, in nnabla.function.Function.__call__
  File "function.pyx", line 315, in nnabla.function.Function._cg_call
RuntimeError: value error in nbla::Convolution<float>::setup_impl
C:\gl\builds\gCcnn6sA\0\nnabla\builders\all\nnabla\src\nbla\function\./generic/convolution.cpp:56
Failed `shape_weights.size() == 2 + spatial_dims`: Weights must be a tensor more than 3D.

〇エクスポートしたPythonコード
# NNCにより出力されたコード
def network(x, test=False):
    # Input:x -> 3,30,30
    # RandomShift
    if not test:
        h = F.random_shift(x, shifts=(4,4))
    else:
        h = x
    # RandomFlip
    if not test:
        h = F.random_flip(h, axes=(3,))
    # ImageAugmentation
    h = F.image_augmentation(h, shape=(3,30,30), min_scale=0.9, max_scale=1.1, angle=0.3, aspect_ratio=1.3, distortion=0.1, brightness=0.5, brightness_each=True, contrast=1.5, contrast_each=True, noise=0.1, seed=0)
    # Convolution -> 3,24,24
    h = PF.convolution(h, outmaps=3, kernel=(7,7), pad=(0,0), name='Convolution')
    # ReLU
    h = F.relu(h, inplace=True)
    # MaxPooling -> 3,12,12
    h = F.max_pooling(h, kernel=(2,2), stride=(2,2))
    # Convolution_2 -> 3,10,10
    h = PF.convolution(h, outmaps=3, kernel=(7,7), pad=(0,0), name='Convolution_2')
    # MaxPooling_2 -> 3,5,5
    h = F.max_pooling(h, kernel=(2,2), stride=(2,2))
    # Tanh_2
    h = F.tanh(h)
    # Affine -> 5
    h = PF.affine(h, n_outmaps=(5,), name='Affine')
    # ReLU_2
    h = F.relu(h, inplace=True)
    # Affine_2 -> 1
    h = PF.affine(h, n_outmaps=(1,), name='Affine_2')
    # Sigmoid
    h = F.sigmoid(h)
    return h

どうぞよろしくお願いいたします。
network.png

Tomonobu Tsujikawa

unread,
Apr 29, 2024, 8:29:13 PM4/29/24
to Neural Network Console Users (JP)
Neural Network Consoleは最新版でしょうか?
Windows v3.1で同様のグラフ構造を作って試してみましたが推論時にエラーは出ませんでした。
python codeにexportした時に以下のshapeが違っていたのでここに差分があるのかもしれません。

# Convolution_2 -> 3,10,10 ではなくて 3,6,6 でした

h = PF.convolution(h, outmaps=3, kernel=(7,7), pad=(0,0), name='Convolution_2')
# MaxPooling_2 -> 3,5,5 ではなくて 3,3,3  でした

h = F.max_pooling(h, kernel=(2,2), stride=(2,2))

Neural Network Consoleからコマンドラインを立ち上げて、
NNCで学習したnnpを使って次のような感じでinferenceしています。

import sys
import nnabla as nn
import nnabla.utils.load as load
from nnabla.utils.data_source_loader import load_image
from nnabla.utils.cli.forward import infer

graph = load.load('result.nnp', prepare_data_iterator=False, batch_size=1)
inputs = [load_image(sys.argv[1], (3, 30, 30))]
result, outputs = infer(graph, inputs)
print(outputs[0])


2024年3月22日金曜日 16:55:37 UTC+9 Igarashi Sota:
Reply all
Reply to author
Forward
0 new messages