Caffe2-installation

提供:Dev Guides
移動先:案内検索

Caffe2-インストール

これで、Caffe2の機能について十分な洞察を得たので、今度は自分でCaffe2を実験してみましょう。 事前に訓練されたモデルを使用するか、独自のPythonコードでモデルを開発するには、まずマシンにCaffe2をインストールする必要があります。

リンクhttps://caffe2.ai/docs/getting-startedl?platform=mac&configuration=prebuilt[https://caffe2.ai/docs/getting-startedl]にあるCaffe2サイトのインストールページで、プラットフォームとインストールタイプを選択するには、次のようにします。

インストールページ

上記のスクリーンショットでわかるように、 Caffe2 は、モバイルプラットフォームを含むいくつかの一般的なプラットフォームをサポートしています。

ここで、このチュートリアルのすべてのプロジェクトがテストされる* MacOSインストール*の手順を理解します。

MacOSのインストール

インストールは以下に示すように4つのタイプにすることができます-

  • 事前に作成されたバイナリ
  • ソースからビルド
  • Dockerイメージ

好みに応じて、インストールタイプとして上記のいずれかを選択します。 ここに記載されている手順は、*ビルド済みバイナリ*用のCaffe2インストールサイトによるものです。 * Jupyter環境*にはAnacondaを使用します。 コンソールプロンプトで次のコマンドを実行します

pip install torch_nightly -f
https://download.pytorch.org/whl/nightly/cpu/torch_nightlyl

上記に加えて、次のコマンドを使用してインストールされるいくつかのサードパーティのライブラリが必要になります-

conda install -c anaconda setuptools
conda install -c conda-forge graphviz
conda install -c conda-forge hypothesis
conda install -c conda-forge ipython
conda install -c conda-forge jupyter
conda install -c conda-forge matplotlib
conda install -c anaconda notebook
conda install -c anaconda pydot
conda install -c conda-forge python-nvd3
conda install -c anaconda pyyaml
conda install -c anaconda requests
conda install -c anaconda scikit-image
conda install -c anaconda scipy

Caffe2 Webサイトのチュートリアルの一部では、次のコマンドを使用してインストールされる zeromq のインストールも必要です-

conda install -c anaconda zeromq

Windows/Linuxのインストール

コンソールプロンプトで次のコマンドを実行します-

conda install -c pytorch pytorch-nightly-cpu

お気づきのように、上記のインストールを使用するにはAnacondaが必要です。 * MacOSインストール*で指定されている追加パッケージをインストールする必要があります。

インストールのテスト

インストールをテストするために、小さなPythonスクリプトを以下に示します。これをJuypterプロジェクトでカットアンドペーストして実行できます。

from caffe2.python import workspace
import numpy as np
print ("Creating random data")
data = np.random.rand(3, 2)
print(data)
print ("Adding data to workspace ...")
workspace.FeedBlob("mydata", data)
print ("Retrieving data from workspace")
mydata = workspace.FetchBlob("mydata")
print(mydata)

上記のコードを実行すると、次の出力が表示されるはずです-

Creating random data
[[Adding data to workspace ...
Retrieving data from workspace
[[The screenshot of the installation test page is shown here for your quick reference −

image:/caffe2/testing_installation.jpg[Testing Installation]

Now, that you have installed Caffe2 on your machine, proceed to install the tutorial applications.

=== Tutorial Installation

Download the tutorials source using the following command on your console −

[source,result,notranslate]

git clone --recursive https://github.com/caffe2/tutorials caffe2_tutorials

After the download is completed, you will find several Python projects in the *caffe2_tutorials *folder in your installation directory. The screenshot of this folder is given for your quick perusal.

[source,result,notranslate]

/Users/yourusername/caffe2_tutorials

image:/caffe2/tutorial_installation.jpg[Tutorial Installation]

You can open some of these tutorials to see what the* Caffe2 code* looks like. The next two projects described in this tutorial are largely based on the samples shown above.

It is now time to do some Python coding of our own. Let us understand, how to use a pre-trained model from Caffe2. Later, you will learn to create your own trivial neural network for training on your own dataset.