GithubHelp home page GithubHelp logo

makaishi2 / pytorch_book_info Goto Github PK

View Code? Open in Web Editor NEW
197.0 197.0 61.0 10.31 MB

書籍「最短コースでわかるPyTorch深層学習プログラミング」用サポートサイト

License: Apache License 2.0

Jupyter Notebook 100.00%

pytorch_book_info's People

Contributors

cafedomancer avatar kazumaandoh avatar makaishi2 avatar schwalbe10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytorch_book_info's Issues

p.254-255のoutputsについて

1版1刷のp.254-255のoutputsについて、(PyTorchの実装がそうなっているんだと思いますが)行内のすべての列が同じ値になっており、maxを取っても実質的には意味がないように見えます。
(indicesもすべて0になっています)

【第五章】Google Colaboratoryで動かすとエラーが出る

第5章のなのですが、自宅のCPUのマシンではエラーが出ないのですが、Google ColaboratoryをGPUを用いて使うと以下の箇所でエラーがでます。

損失値計算用にlabels変数を(N,1)次元の行列に変換する

labels1 = labels.view((-1, 1))

次元数確認

print(labels1.shape)

予測計算

outputs = net(inputs)
(以下エラー)

RuntimeError Traceback (most recent call last)
in
1 # 予測計算
2
----> 3 outputs = net(inputs)

3 frames
/usr/local/lib/python3.8/dist-packages/torch/nn/modules/linear.py in forward(self, input)
112
113 def forward(self, input: Tensor) -> Tensor:
--> 114 return F.linear(input, self.weight, self.bias)
115
116 def extra_repr(self) -> str:

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument mat1 in method wrapper_addmm)

これが何が悪いのかがわかりませんでした。
お手数をおかけしますが、ご教示いただけますでしょうか。
何卒、よろしくお願い申し上げます。

listの中に特定の数字が含まれないとcuda errorになる

n_output = len(set(list(labels.data.numpy())))
上記コードの実行結果が9になることがある。
このとき、以下のようなcudaエラーが発生する。
RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE
数十回に一度なので、原因を見つけるのが苦労しましたorz

誤植?

とても楽しく読ませてもらっています。
本の5章、2次元の回帰の説明のところ(手元ではkindle版でp.193)で


from torchsummary import summary
Notebook
from torchinfo import summary

となっておりました。ご存知かもしれないですが、一応ご報告です。

第5章の重回帰が動かなくなりました

以前は動いていたのですが、pytorchのバージョンを変えたからか、第5章以降のプログラムが同じエラーメッセージで動かなくなりました。
pytorchのバージョンは1.12.1 Pythonのバージョンは3.8.15です。
該当のコード
`

予測計算

outputs = net(inputs)

`
エラーメッセージは次の通りです。
RuntimeError Traceback (most recent call last)
セル41 を c:\Users\akira\Documents\Python\PyTorch深層学習プログラミング\pytorch_book_info-main\notebooks\ch05_regression.ipynb in <cell line: 3>()
1 # 予測計算
----> 3 outputs = net(inputs)

File c:\Anaconda3\envs\venv\lib\site-packages\torch\nn\modules\module.py:1130, in Module._call_impl(self, *input, **kwargs)
1126 # If we don't have any hooks, we want to skip the rest of the logic in
1127 # this function, and just call forward.
1128 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1129 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1130 return forward_call(*input, **kwargs)
1131 # Do not call functions when jit is used
1132 full_backward_hooks, non_full_backward_hooks = [], []

セル41 を c:\Users\akira\Documents\Python\PyTorch深層学習プログラミング\pytorch_book_info-main\notebooks\ch05_regression.ipynb in Net.forward(self, x)
17 def forward(self, x):
---> 18 x1 = self.l1(x) # 線形回帰
19 return x1

File c:\Anaconda3\envs\venv\lib\site-packages\torch\nn\modules\module.py:1130, in Module._call_impl(self, *input, **kwargs)
1126 # If we don't have any hooks, we want to skip the rest of the logic in
1127 # this function, and just call forward.
1128 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1129 or _global_forward_hooks or _global_forward_pre_hooks):
...
File c:\Anaconda3\envs\venv\lib\site-packages\torch\nn\modules\linear.py:114, in Linear.forward(self, input)
113 def forward(self, input: Tensor) -> Tensor:
--> 114 return F.linear(input, self.weight, self.bias)

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument mat1 in method wrapper_addmm)

何が原因か種々ググったのですが、わからず、何が原因か、ご教示いただくことは可能でしょうか。

線形関数の図におけるweightの行数と列数について

@makaishi2

はじめまして。

この度、こちらの書籍を楽しく読ませて頂きました。高評価のレビューを読んでの購入でしたが、
実際に大変わかりやすく、本当に素晴らしい入門書だと感じました。

さて、表題の件ですが、書籍の図の中で、線形関数のweightの行数と列数の表記が、
全体として整合性が取れていないのではないかと思いましたので、ご報告いたしました。

具体的には、入力ベクトルのサイズ値に、weightの「行数」が対応する図(図4-3など)が
ある一方で、「列数」が対応する図(図7-1など)もございました。

(こちら、後者は線形関数のインスタンス変数としての形状を反映したものでしょうか。
Linearクラスのドキュメントを見ますと、線形関数は、保持している行列の「転置」を
入力に対して右から掛けるとの記載があり、紛らわしいと思いました。)

以上、ご確認いただけますと幸いです。

誤植:P394-3行目

@makaishi2

P.349の3行目ですが、「検証精度」が「損失精度」となっていましたので、ご報告いたします。

ご確認いただけますと幸いです。

誤植:P.439 コード11-8 summary関数の引数と出力結果

@makaishi2

P.439 コード11-8のsummary関数の引数ですが、入力サイズの箇所にバッチサイズの値が
ございませんでしたので、ご報告いたします。

こちら、書籍のまま入力したところエラーとなり、torchinfoのページを見て、バッチサイズも
必要なことを確認いたしました。この場合、出力も書籍と異なると考えております。
(コードは修正されていることをその後確認いたしました。)

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

誤植:第1版第1刷P.85

@makaishi2
第1版第1刷P.85の10行目と11行目の「指数関数」ですが、正しくは「べき関数」ではないでしょうか。

・指数関数(exponential function)は指数が変数
・べき関数(power function)は底が変数

ご確認いただけますと幸いです。

多値分類のコードの書き方について

お世話になります。現在、本書を参考に機械学習を勉強しています。
12章を元に6クラスの分類を試みているのですが、画像を表示する際、学習する際に、
UnidentifiedImageError: cannot identify image file
と表示されます。
2値分類と多値分類で変えるべき部分、画像を用意する際に気を付ける事についてご教授いただけますでしょうか。

p.545のtotalについて

1版1刷のp.545のtotalがlen(n21)になっていますが、len(yt)かlen(yp)の間違いではないでしょうか?

ボストン・データセットを使用しようとすると、倫理的な問題があると警告が出る

PyTorchを基礎から学んでおります。PyTorchの公式チュートリアルは読んでも理解できない部分が多かったのですが、本書では題名通り「最短コース」で学べていると感じています。

問題点
Chapter5で、load_boston()を呼ぶと以下の警告が出ます。将来的に、scikit learnから当該関数が削除されてしまうと、本書の実習が進められなくなってしまいます。次回改訂時に、別のデータセットを使用する形にしていただけないでしょうか?

その他の情報
私が持っているのは電子書籍版で、巻末には「電子書籍版データ作成日 2021年9月7日 第1版」と書かれています。

既に、改訂済みや執筆中、対応を検討中でしたら、お手数ですが本イシューはクローズしてください。
よろしくお願いします。

元データ (506, 13) (506,)
項目名:  ['CRIM' 'ZN' 'INDUS' 'CHAS' 'NOX' 'RM' 'AGE' 'DIS' 'RAD' 'TAX' 'PTRATIO'
 'B' 'LSTAT']
/usr/local/lib/python3.7/dist-packages/sklearn/utils/deprecation.py:87: FutureWarning: Function load_boston is deprecated; `load_boston` is deprecated in 1.0 and will be removed in 1.2.

    The Boston housing prices dataset has an ethical problem. You can refer to
    the documentation of this function for further details.

    The scikit-learn maintainers therefore strongly discourage the use of this
    dataset unless the purpose of the code is to study and educate about
    ethical issues in data science and machine learning.

    In this special case, you can fetch the dataset from the original
    source::

        import pandas as pd
        import numpy as np


        data_url = "http://lib.stat.cmu.edu/datasets/boston"
        raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None)
        data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])
        target = raw_df.values[1::2, 2]

    Alternative datasets include the California housing dataset (i.e.
    :func:`~sklearn.datasets.fetch_california_housing`) and the Ames housing
    dataset. You can load the datasets as follows::

        from sklearn.datasets import fetch_california_housing
        housing = fetch_california_housing()

    for the California housing dataset and::

        from sklearn.datasets import fetch_openml
        housing = fetch_openml(name="house_prices", as_frame=True)

    for the Ames housing dataset.
    
  warnings.warn(msg, category=FutureWarning)

P129 line 6

plt.show()l -> plt.show()
かと思われます。(誤植)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.