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?

RealESRGANを使うとNo module named 'torchvision.transforms.functional_tensor'とエラーが出る件について

Posted at

この記事にたどり着いたお前はそもそもRealESRGANの実装方法を間違えてる。
https://github.com/xinntao/Real-ESRGAN/tree/master

# Install basicsr - https://github.com/xinntao/BasicSR
# We use BasicSR for both training and inference
pip install basicsr
# facexlib and gfpgan are for face enhancement
pip install facexlib
pip install gfpgan
pip install -r requirements.txt
python setup.py develop

やり方

上記のgitをどこでもいいのでクローンします。
次に上記のコマンドを打ちます。

終わり

おまけ

pythonで動かし方を教えます。

import cv2
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet

# Real-ESRGANの設定
model_path = 'Real-ESRGAN/weights/realesr-general-x4v3.pth'  # ダウンロードしたモデルのパス
scale = 4  # 拡大倍率

# デバイスの設定(GPUが使用可能な場合はGPUを使用)
device = 'cuda' if cv2.cuda.getCudaEnabledDeviceCount() > 0 else 'cpu'
print(f"デバイス: {device}")

# モデルの定義
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64,
               num_block=23, num_grow_ch=32, scale=scale)

# RealESRGANerの初期化
upsampler = RealESRGANer(
    scale=scale,
    model_path=model_path,
    model=model,
    tile=0,
    tile_pad=10,
    pre_pad=0,
    half=True if device == 'cuda' else False,
    device=device
)

# 画像の読み込み
input_image_path = 'input_folder/input_image.jpg'
output_image_path = 'output_folder/output_image.png'

img = cv2.imread(input_image_path, cv2.IMREAD_COLOR)
if img is None:
    raise ValueError(f"画像 '{input_image_path}' の読み込みに失敗しました。")

# 超解像処理
output, _ = upsampler.enhance(img, outscale=scale)

# 画像の保存
cv2.imwrite(output_image_path, output)
print(f"超解像された画像が '{output_image_path}' に保存されました。")

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?