Python - AI - MAX78000 - mat1 and mat2 shapes cannot be multiplied

クラウディア 
1. 概要
2. 現象
3. 対処

1. 概要

 サンプルを利用しつつ、あるものを学習させようとしているのですが、エラーだらけでちっとも進まない。  あれこれのトラブルをメモにしていきます。  実は、データを読み込ませるためにも、めちゃくちゃ時間がかかったのですが、そこはメモをとることもできなかった。  やっと、メモをとりつつ進められそうなところまできた(?)ような気がするので、メモを残していきます。  本ページは、下記のサイトを参考にさせていただきました。
【PyTorchエラー解消】RuntimeError: mat1 and mat2 shapes cannot be multiplied

2. 現象

 プログラムがこけたのは。

ai8x-training/ai8x.py
 の。

    def _conv_forward(self, x, weight, bias):  # pylint: disable=method-hidden
        return nn.functional.linear(x, weight, bias)
 下記のようなエラーになります。

RuntimeError: mat1 and mat2 shapes cannot be multiplied (2160x16 and 3x3)
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> パス\ai8x-training\ai8x.py(1337)_conv_forward()
-> return nn.functional.linear(x, weight, bias)

3. 対処

 参考サイトによれば、  ここで、掛け算しようとしている行列同士のサイズがあってないちゅうことらしい。  2160x16 の行列と 3x3 の行列をかけ合わせているちゅうことなのですな。  これをどこで生成しているかちゅうことで悩みましたが、わからないままに自作しているモジュールにありました。  起動時のスクリプトに。

--model xxx
 てな記述をしておりまして、この「model」ちゅうのを。

ai8x-training/models/xxx.py
 ちゅうコードで定義しております。  この中に。

from torch import nn
import ai8x

class xxx(nn.Module):
  def __init__(
        self,
        num_classes=None,  # pylint: disable=unused-argument
        num_channels=4,
        dimensions=(16, 2),  # pylint: disable=unused-argument
        bias=False,
        **kwargs):  # pylint: disable=unused-argument

    super().__init__()

	self.l1 = ai8x.Linear(3, 3)
	・・・ 略  ・・・

  def forward(self, x):

    x = self.l1(x)
		・・・ 略  ・・・

    return x

models = [
	{
		'name': 'xxx',
		'min_input': 1,
		'dim': 2,
	},
]
 ちゅう、記述をしちょります。  とりあえずここでは。

self.l1 = ai8x.Linear(3, 3)
 の記述を 2160x16 に合わせて(?)。

self.l1 = ai8x.Linear(16, 2)
 てな記述をすることで、先に進みました。  これは、正解ではないかもしれないが、先へ進めることが先決なので。
AbemaTV 無料体験