Skip to content

Instantly share code, notes, and snippets.

@Hi-king
Last active January 24, 2019 04:14
Show Gist options
  • Save Hi-king/1c7f86e0fa628c41eb3c to your computer and use it in GitHub Desktop.
Save Hi-king/1c7f86e0fa628c41eb3c to your computer and use it in GitHub Desktop.
chainerで画像分類するための補助スクリプト
!/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)
for source_imgpath in os.listdir(args.source_dir):
print source_imgpath
src = cv2.imread(args.source_dir+"/"+source_imgpath)
# mirror image
while src.shape[0] < target_shape[0] or src.shape[1] < target_shape[1]:
print src.shape
src = numpy.concatenate((numpy.fliplr(src), src), axis=1)
src = numpy.concatenate((numpy.flipud(src), src), axis=0)
src = src[:target_shape[0], :target_shape[1]]
print src.shape
cv2.imwrite(args.target_dir+"/"+source_imgpath, src)
import pylab
import argparse
import json
parser = argparse.ArgumentParser()
parser.add_argument("result")
args = parser.parse_args()
xs = []
ys = []
for line in open(args.result):
print line
data = json.loads(line)
xs.append(data["iteration"])
ys.append(data["error"])
pylab.xlabel("iteration")
pylab.ylabel("error")
pylab.plot(xs, ys)
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment