makaishi2 / pytorch_book_info Goto Github PK
View Code? Open in Web Editor NEW書籍「最短コースでわかるPyTorch深層学習プログラミング」用サポートサイト
License: Apache License 2.0
書籍「最短コースでわかるPyTorch深層学習プログラミング」用サポートサイト
License: Apache License 2.0
plt.ylabel("petal_length") -> plt.ylabel("petal_width") でその下の図のy軸もpetal_widthでは?
1版1刷のp.254-255のoutputsについて、(PyTorchの実装がそうなっているんだと思いますが)行内のすべての列が同じ値になっており、maxを取っても実質的には意味がないように見えます。
(indicesもすべて0になっています)
第5章のなのですが、自宅のCPUのマシンではエラーが出ないのですが、Google ColaboratoryをGPUを用いて使うと以下の箇所でエラーがでます。
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)
これが何が悪いのかがわかりませんでした。
お手数をおかけしますが、ご教示いただけますでしょうか。
何卒、よろしくお願い申し上げます。
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
となっておりました。ご存知かもしれないですが、一応ご報告です。
以前は動いていたのですが、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の行数と列数の表記が、
全体として整合性が取れていないのではないかと思いましたので、ご報告いたしました。
具体的には、入力ベクトルのサイズ値に、weightの「行数」が対応する図(図4-3など)が
ある一方で、「列数」が対応する図(図7-1など)もございました。
(こちら、後者は線形関数のインスタンス変数としての形状を反映したものでしょうか。
Linearクラスのドキュメントを見ますと、線形関数は、保持している行列の「転置」を
入力に対して右から掛けるとの記載があり、紛らわしいと思いました。)
以上、ご確認いただけますと幸いです。
P.439 コード11-8のsummary関数の引数ですが、入力サイズの箇所にバッチサイズの値が
ございませんでしたので、ご報告いたします。
こちら、書籍のまま入力したところエラーとなり、torchinfoのページを見て、バッチサイズも
必要なことを確認いたしました。この場合、出力も書籍と異なると考えております。
(コードは修正されていることをその後確認いたしました。)
どうぞよろしくお願いいたします。
@makaishi2 様
第1版第1刷P.85の10行目と11行目の「指数関数」ですが、正しくは「べき関数」ではないでしょうか。
・指数関数(exponential function)は指数が変数
・べき関数(power function)は底が変数
ご確認いただけますと幸いです。
plt.xlabel('sepal_length') -> plt.xlabel('petal_length')
plt.ylabel('sepal_length') -> plt.ylabel('petal_length')
p215の図のx, yラベルも上記かと思われます
お世話になります。現在、本書を参考に機械学習を勉強しています。
12章を元に6クラスの分類を試みているのですが、画像を表示する際、学習する際に、
UnidentifiedImageError: cannot identify image file
と表示されます。
2値分類と多値分類で変えるべき部分、画像を用意する際に気を付ける事についてご教授いただけますでしょうか。
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)
plt.show()l -> plt.show()
かと思われます。(誤植)
(確認していないが9章で起きた事象からそうなるはず)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.