0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

初心者がTensorFlowを使ってみる〜TensorFlowのインストール〜(1日目)

Posted at

はじめに

現状の知識

TensorFlow面白いよと言われたけど、機械学習できるの?機械学習って結局なんなん?っていうくらいわかってない。

pythonはスクレイピングで使う程度で、使いこなせてないよ。(PHPは仕事で使ってるのでプログラミング初心者というわけではないけど)

勉強の進め方

Qiitaにメモしつつ、ゆっくり進めていくので、多分果てしない時間がかかる。
あと暇なタイミングで少しずつ進めるので、進みは遅いはずです。詰まったところはしっかり調べていく。

目標

とりあえずなんか作る!そんでなにができるものなのか把握しとく(今は何ができるのかわからない)


勉強スタート


TensorFlowのインストールとエラー対応

とりあえず機械学習できるやつなんでしょ?っていうのはわかったので、まずインストールしてくよ。
[公式]https://www.tensorflow.org/install/pip?hl=ja
これのページに書いてある下記コマンドを実行

インストール

pip install --upgrade tensorflow

インストール確認

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

エラー出ました(Could not import the lzma module.)

 UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.
  warnings.warn(msg)

原因

Could not import the lzma module.

lzmaがないよっていうことらしい。

対応方法

lzmaを入れて、pythonのアンインストール+再インストールをしなくちゃいけないとのこと。
下記のようにbrewで入るらしいので、一旦入れてみる

brew install xz

このあとpyenvでアンインストールと、再インストールを行うとのこと。

アンインストール
pyenv uninstall 3.7.5
再インストール
pyenv install 3.7.5

またpipで入れたライブラリが消えてしまった。。辛い。

もう一回インストールと確認

インストール
pip install --upgrade tensorflow

確認

確認
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

2021-02-20 00:00:12.799993: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
tf.Tensor(-796.5173, shape=(), dtype=float32)

AVX2 FMA使いたかったら再構築しろよ!みたいなことが書いてあるけど、どうやらスルーしておkなやつらしい。
速度がちょっと遅いとかそれくらい。
なのでこれで環境構築終了!!

最後に

なんかpythonでGUI使う時もだけどしょっちゅう再インストールして、pipでパッケージを入れ直してって繰り返してる気がする・・。
site-packageのディレクトリにpipで入れたパッケージファイルまとまってるんだけどこれバックアップして上書きすればいいんだろか?

もう少しやりたかったけど、AWS障害であわあわして疲れちゃったので今日(1日目)は勉強おわり。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?