Last active
December 12, 2017 23:48
-
-
Save knok/99315276e15c4708189c664280b759ab to your computer and use it in GitHub Desktop.
フレンズ画像を生成させてみたい-画像収集編+DCGAN ref: https://qiita.com/knok/items/3f3c1d3eef4b435ed37e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from bs4 import BeautifulSoup | |
import urllib.request | |
import urllib.parse | |
import time | |
import os | |
wait_sec = 5 | |
start_url = 'https://kemono-friends.gamerch.com/%E3%82%AD%E3%83%A3%E3%83%A9%E4%B8%80%E8%A6%A7' | |
base_url = 'https://kemono-friends.gamerch.com' | |
output_dir = 'save' | |
html = urllib.request.urlopen(start_url) | |
soup = BeautifulSoup(html, 'lxml') | |
elems = soup.select('a[href^="/"]') | |
vals = [] | |
for e in elems: | |
p = e.parent | |
if p.name == 'td': | |
vals.append(e) | |
#import pdb; pdb.set_trace() | |
time.sleep(wait_sec) | |
for v in vals: | |
c = v['href'] | |
page_url = base_url + urllib.parse.quote(c) | |
html = urllib.request.urlopen(page_url) | |
soup = BeautifulSoup(html, 'lxml') | |
imgs = soup.select('a[href$=".jpg"]') | |
for i in imgs: | |
jpg_url = i['href'] | |
fname = os.path.basename(jpg_url) | |
fname = os.path.join(output_dir, fname) | |
if os.path.exists(fname): | |
#import pdb; pdb.set_trace() | |
print("skip %s" % fname) | |
continue | |
with open(fname, "wb") as f: | |
raw_img = urllib.request.urlopen(jpg_url).read() | |
f.write(raw_img) | |
# | |
print("%s saved" % fname) | |
time.sleep(wait_sec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ for i in $(seq 1 82); do \ | |
wget https://umabi.jp/kemono-friends/shindan/asset/img/result/character/$i.png; \ | |
sleep 5; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
INDIR=$1 | |
OUTDIR=$2 | |
SIZE=32x32 | |
mkdir -p $OUTDIR | |
FILES=$(cd $INDIR; ls *) | |
for fname in $FILES | |
do | |
convert $INDIR/$fname -resize $SIZE \ | |
\( +clone -alpha opaque -fill white -colorize 100% \) +swap \ | |
-geometry +0+0 -compose Over -composite -alpha off \ | |
-gravity center -extent $SIZE \ | |
$OUTDIR/$fname | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python dataset/cifar10like.py --data-dir /path/to/32x32img image.npz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python c10like-train.py -g 0 \ # c10like-train.py: 任意の32x32カラー画像を訓練するスクリプト | |
--image-npz image.npz -o result-c10like-dcgan \ # result-c10like-dcgan に出力 | |
--algorithm dcgan --adam_alpha 0.0001 --adam_beta1 0.5 \ | |
--adam_beta2 0.9 --snapshot-iter 2000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat result-c10like-dcgan/log | |
[ | |
{ | |
"loss_dis": 0.039919644594192505, | |
"loss_gen": 9.003257751464844, | |
"epoch": 78, | |
"iteration": 100, | |
"elapsed_time": 56.77760434150696 | |
}, | |
{ | |
"loss_dis": 0.0010271351784467697, | |
"loss_gen": 9.35523509979248, | |
"epoch": 156, | |
"iteration": 200, | |
"elapsed_time": 87.36827898025513 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment