LoginSignup
1
0

More than 3 years have passed since last update.

Chainerメモ その3

Last updated at Posted at 2018-05-29

5. 学習用データ作成(画像パスとクラスがセットされたテキストファイル)

python3 chainer_imagenet_tools/make_train_data.py 101_ObjectCategories

6. 学習用データ作成(画像リサイズ 用スクリプトを修正)

vim chainer_imagenet_tools/crop.py

#!/usr/bin/python
# -*- coding: utf-8 -*-
import cv2
import argparse
import os
import numpy

parser = argparse.ArgumentParser()
parser.add_argument("source_dir")
parser.add_argument("target_dir")
args = parser.parse_args()

target_shape = (256, 256)
output_side_length=256

for source_imgpath in os.listdir(args.source_dir):
  print(source_imgpath)
  img = cv2.imread(args.source_dir+os.sep+source_imgpath)
  height, width, depth = img.shape
  new_height = output_side_length
  new_width = output_side_length
  if height > width:
    new_height = int(output_side_length * height / width)
  else:
    new_width = int(output_side_length * width / height)
  resized_img = cv2.resize(img, (new_width, new_height))
  height_offset = int((new_height - output_side_length) / 2)
  width_offset = int((new_width - output_side_length) / 2)
  cropped_img = resized_img[height_offset:height_offset + output_side_length,
width_offset:width_offset + output_side_length]
  cv2.imwrite(args.target_dir+os.sep+source_imgpath, cropped_img)
1
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
1
0