0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MinerU API サービスをローカル構築する方法(CPU推論対応版)

Posted at

はじめに

この記事では、MinerU API サービスをローカル環境にDockerを使用して構築する手順について説明します。GPUを使用しない環境(CPU推論のみ)での構築方法についても触れています。

前提条件

  • Docker および Docker Compose がインストールされている
  • インターネット接続が利用可能
  • Ubuntu 24.04 環境(本記事の例)

構築手順

1. Dockerfileのダウンロードと編集

まず、MinerUの公式Dockerfileをダウンロードしてカスタマイズします:

カスタマイズ後のファイルをこちらからダウンロードできます。

wget https://raw.githubusercontent.com/engchina/MinerU/refs/heads/main/Dockerfile
wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/global/Dockerfile

Dockerfileを編集します:

vi Dockerfile

以下の部分を修正する必要があります:

修正前:

# Download models and update the configuration file
RUN /bin/bash -c "mineru-models-download -s huggingface -m all"

修正後:

# Download models and update the configuration file
RUN f=/usr/local/lib/python3.10/dist-packages/mineru/cli/models_download.py && \
    /usr/bin/sed -i '/ModelPath\.slanet_plus/s/$/,/' "$f" && \
    /usr/bin/sed -i '/ModelPath\.slanet_plus/a\
    ModelPath.unet_structure,\
    ModelPath.paddle_table_cls,\
    ModelPath.paddle_orientation_classification' "$f" && \
    /bin/bash -c "mineru-models-download -s huggingface -m all"

この修正により、必要なモデルパスが適切に追加されます。

2. Dockerイメージのビルド

修正したDockerfileを使用してイメージをビルドします:

docker build -t mineru-sglang:latest -f Dockerfile .

3. Docker Compose設定ファイルのダウンロードと編集

compose.yamlファイルをダウンロードして編集します:

編集後のファイルをこちらからダウンロードできます。

wget https://raw.githubusercontent.com/engchina/MinerU/refs/heads/main/compose.yaml
wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/compose.yaml

compose.yamlを編集します:

vi compose.yaml

GPUが利用できない環境の場合、mineru-apiサービスから以下のGPU設定部分を削除します:

deploy:
  resources:
    reservations:
      devices:
        - driver: nvidia
          device_ids: [ "0" ]
          capabilities: [ gpu ]

この設定を削除することで、CPU推論での動作が可能になります。

4. サービスの起動

Docker Composeを使用してサービスを起動します:

docker compose -f compose.yaml --profile api up -d

5. ファイアウォール設定(Ubuntu 24.04の場合)

APIサービスにアクセスできるよう、ポート8000を開放します:

iptables -I INPUT 5 -m state --state NEW -p tcp --dport 8000 -j ACCEPT
netfilter-persistent save

注意点

  • GPUが利用できない環境では推論速度が遅くなる可能性があります
  • セキュリティを考慮し、本番環境では適切なファイアウォール設定を行ってください

まとめ

以上の手順により、MinerU API サービスをローカル環境に構築することができます。CPU環境でも動作するため、GPUリソースが限られた環境でもMinerUの機能を試すことが可能です。

参考リンク

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?