LoginSignup
0
0

More than 1 year has passed since last update.

[Docker / Ubuntu20.04 / caffe] protobuf2.6.1をインストール

Last updated at Posted at 2022-09-02

概要

caffeの実行に必要なprotobufのバージョンの問題で、caffeが実行できなかった。

かつてcaffeの実行のために有効だったprotobufのインストール方法を踏襲すると、現在の最新のprotobufがインストールされてしまうが、これは新しすぎてcaffeから使うことができない。

そこで、古いprotobufをインストールしようというのがこの記事。

問題

当初のソースコード

Dockerfile
FROM ubuntu:20.04

RUN apt-get update && apt-get upgrade -y \
    && apt-get install -y tzdata

RUN apt-get install -y --no-install-recommends \
    # caffe用のライブラリ: この方法だと 3.6.1 がインストールされてしまう
    libprotobuf-dev \
    protobuf-compiler \
    #  ...その他色々

# 以下略...
# 色々インストールしてるけど、今回は関係ないので省略
# この後でcaffeのbuildを行っている

上記のようなDockerfileだと、もしcaffeのbuildが成功したとしても、実行時(pythonからcaffeを呼び出した際)にエラーが発生する。

Error

caffe_pb2.py TypeError: __init__() got an unexpected keyword argument 'syntax

対策

libprotocのインストール方法を以下のように改める。

Dockerfile
FROM ubuntu:20.04

RUN apt-get update && apt-get upgrade -y \
    && apt-get install -y tzdata

RUN apt-get install -y --no-install-recommends \
    # caffe用のライブラリ: この方法だと 3.6.1 がインストールされてしまう
    # が、 2.6.1 が欲しいのでコメントアウト
    # libprotobuf-dev \
    # protobuf-compiler \
    # ...その他色々

# HACK: "protobuf-2.6.1" is necessary for avoiding an error on initializing caffe.
#     You will get that error if you use "protobuf-3.6.1".
#     https://blog.csdn.net/e01528/article/details/81282343
RUN curl -sL https://github.com/protocolbuffers/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz -o protobuf-2.6.1.tar.gz \
    && tar -zxvf protobuf-2.6.1.tar.gz \
    && cd protobuf-2.6.1 \
    && ./configure \
    && make -j8 \
    && make check -j8 \
    && make install -j8 \
    && ldconfig

これで 2.6.1 をインストールできる。

$ protoc --version
libprotoc 2.6.1

libprotocのバージョンを2.6.1にしたところ、caffe_pb2.py TypeError: __init__() got an unexpected keyword argument 'syntaxは発生しなくなった。

参考にした記事

  • 2.6.1のインストール方法が書かれている記事(中国語)

  • ldconfigが必要だということはこの記事でわかった

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