以å㯠MNISTの例を使って画像識別を試してみた ãã©ã次ã¯ã«ã©ã¼ç»åã«ã¤ãã¦ã®èå¥ã試ãã¦ã¿ãã
ãã¢ã¤ãã«ãªãã¦ã¿ããªåãé¡ã«è¦ãããã£ã¦ æè¿ãè¨ããã¦ãã®ãã©ããç¥ããªããã©ãèªåãã¤ã5å¹´åãããã¾ã§ã¯ããæã£ã¦ããããã§ããã®èå¥ãæ©æ¢°å¦ç¿ã§ãã£ã¦ã¿ãã ã¨ãã試ã¿ã
æè¿ã¯ã»ã¨ãã©ã©ã¤ãã«è¡ããªããªã£ã¦ãã¾ã£ããã©å¤§å¥½ããªããããã¯ãã¼ãã¼Zã¡ãããé¡æã«ãã¦ã¿ããã¨ã«ã
5人ã®ã¡ã³ãã¼ã®é¡ã¯æ©æ¢°å¦ç¿ã«ãã£ã¦ã©ããããåé¡ã§ããããã«ãªãã®ãï¼ï¼
CIFAR-10
CIFAR-10 ã¨ããã32Ã32ãµã¤ãºã®ã«ã©ã¼ç»åã10種é¡ã®ã¯ã©ã¹ã«åé¡ããèå¥èª²é¡ãããããã®ãã¼ã¿ã»ãããå
¬éããã¦ããããããå®éã«TensorFlowã§å¦ç¿ããããã®ç³ã¿è¾¼ã¿ãã¥ã¼ã©ã«ãããã¯ã¼ã¯ã®ã¢ãã«ãé¢æ°ãªã©ãtensorflow.models.image.cifar10
ããã±ã¼ã¸ã«å梱ããã¦ããã®ã§ããããå©ç¨ãã¦å¦ç¿ããã¦ã¿ããã¨ã«ããã
ç»ååé
ã¾ã課é¡ã¨ãªãã®ãè¨ç·´ç¨ã®ãã¼ã¿ã»ããã®ç¨æãæ師ããå¦ç¿ãè¡ãããããé¡ã®ç»åãã¨ããããã©ã®äººç©ã®é¡ã§ããã(ã©ãåé¡ãããã®ãæ£è§£ã)ãã示ãã©ãã«ãã®ã»ãããå¿
è¦ã§ãCIFAR-10ã§ã¯å6000æã®ç»åã¨ã©ãã«ã®ã»ãããç¨æããæä¾ããã¦ãããããã¯ãã®5人ã®é¡èå¥ã«ããã¦ã¯ç¾å®çã«ã©ããããã®éãå¿
è¦ãåãããªããã©ãæä½ã§ãå100ãããã¯ç¨æãããã¨ããã
ããã¯ãã¡ããã¯ãã£ã¨ã¢ã¡ãããç¶ãã¦ãã¦ããã®ã§ãããã«èªæ®ãç»åãªã©ã¯ããç¨åº¦èç©ããã¦ããããããå©ç¨ãããã¨ã«ãã¦ã
- 雑にスクレイピング ãã¦ããã°ã«è¼ã£ã¦ããç»åããã£ããåå¾ãã
- 自作の顔検出器 ã«ããã¦å å·¥ãããã¨ã§é¡é åã ããåãåºããç»åãçæãä¿åã
- ã©ãã«ã管çããåé¡ç»åã¨ã®é¢é£ä»ããç·¨éãã
- ãããã使ã£ã¦æçµçã« CIFAR-10データセットと同じ形式のバイナリデータを生成
ã¨ããã®ãåºæ¥ãwebã¢ããªãã¾ãrailsã§ä½ã£ããç»åå å·¥ã¯RMagickã§ã ãããã§ããã®ã§ä¾¿å©ã
- face-collector
- https://github.com/sugyan/face-collector
ããã¦ããã使ã£ã¦èªåæ½åºãããé¡ç»åãã¡ãç®è¦ã§ç¢ºèªããªããã©ãã«ä»ããããã ãã¯æ®å¿µãªãã人åã§è¡ããããªããéåç¥ãä¸æãå©ç¨ã§ããã°ãã®ã¸ããããç¨åº¦ã¯èªååã§ããã®ãããããªããã©â¦ã
ã¨ãããã5人ã®åã¡ã³ãã¼ã«ã¤ãã¦200ç¹ãã¤ãããã¯ããã«ãã¼ã¿ãä½ããã¨ãã§ã(æå®ããã¯å®å®ã®èªæ®ããå¤ãã¦éãããããçäºããã¯èªæ®ãå°ãªãã¦è¦å´ããâ¦ãã¨é«åããã¯å¤é¡ãå¤ãã¦å¤æã«è¿·ããã¨ãå¤ãã£ãï½)ãã¡ã³ãã¼ä»¥å¤ã®ã¹ã¿ãããå
񑬊
ããã®é¡ç»åãªã©ãå¹¾ã¤ããã£ãã®ã§ãããããããã¯ãã¡ã³ãã¼ã§ã¯ãªããã¨ãã6ã¤ç®ã®ã©ãã«ã¨ãã¦æ··ãã¦ãè¨ç·´ç¨ã¨è©ä¾¡ç¨ã§ãã¼ã¿ã»ãããä½æããã
管çä¸ã¯ã¦ãã¼ã¯ãªãã¼ã¿ã¨ãã¦ãã¦ãåãé¡ã®åã£ãåãåçãè¤æ°ã®ã¡ã³ãã¼ãããã°ã«è¼ãã¦ããããããã®ã§ãå®éã«ã¯å®å
¨ã«ã¦ãã¼ã¯ã§ã¯ãªãæ°çµã»ã¼åããã®ãæ··ãã£ã¦ãããããããããããªãã
å¦ç¿
ãããã使ã£ã¦ã Tutorial ã¨ã»ã¼åæ§ã«å¦ç¿ããã¦ãããCIFAR-10ã¨åå½¢å¼ã§ãã¡ã¤ã«ãç¨æãã¦ããã°ãcifar10.input()
ã®é¢æ°1ã¤ã§ãã¡ã¤ã«ããã®ãã¼ã¿èªã¿è¾¼ã¿ãå å·¥ããã¥ã¼ã¤ã³ã°ã¾ã§ãã¹ã¦æ¸ãã å
¥åãã¼ã¿ãå¾ãããã®ã§ä¾¿å©ã
å®éã«æ¸ããã³ã¼ãã¯ããã ãã§ã
cifar10.IMAGE_SIZE = 32 cifar10.NUM_CLASSES = 6 cifar10.NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN = 1000 cifar10.INITIAL_LEARNING_RATE = 0.08 FLAGS = tf.app.flags.FLAGS tf.app.flags.DEFINE_integer('max_steps', 10000, """Number of batches to run.""") tf.app.flags.DEFINE_string('train_dir', 'train', """Directory where to write event logs """ """and checkpoint.""") def train(): # ops global_step = tf.Variable(0, trainable=False) images, labels = cifar10.distorted_inputs() logits = cifar10.inference(tf.image.resize_images(images, cifar10.IMAGE_SIZE, cifar10.IMAGE_SIZE)) loss = cifar10.loss(logits, labels) train_op = cifar10.train(loss, global_step) summary_op = tf.merge_all_summaries() with tf.Session() as sess: saver = tf.train.Saver(tf.all_variables(), max_to_keep=21) summary_writer = tf.train.SummaryWriter(FLAGS.train_dir) # restore or initialize variables ckpt = tf.train.get_checkpoint_state(FLAGS.train_dir) if ckpt and ckpt.model_checkpoint_path: saver.restore(sess, ckpt.model_checkpoint_path) else: sess.run(tf.initialize_all_variables()) # Start the queue runners. tf.train.start_queue_runners(sess=sess) start = sess.run(global_step) for step in xrange(start, FLAGS.max_steps): start_time = time.time() _, loss_value = sess.run([train_op, loss]) duration = time.time() - start_time assert not np.isnan(loss_value), 'Model diverged with loss = NaN' print '%d: %f (%.3f sec/batch)' % (step, loss_value, duration) if step % 100 == 0: summary_str = sess.run(summary_op) summary_writer.add_summary(summary_str, step) if step % 500 == 0 or (step + 1) == FLAGS.max_steps: checkpoint_path = os.path.join(FLAGS.train_dir, 'model.ckpt') saver.save(sess, checkpoint_path, global_step=step)
cifar10.inference
ã«ãããå
¥åã渡ããã¨ã§ç³ã¿è¾¼ã¿ãã¥ã¼ã©ã«ãããã¯ã¼ã¯ã¢ãã«ã¨ãã®åºåãä½ãããcifar10.loss
ã«ãã®åºåã¨æ£è§£ã©ãã«ã渡ããã¨ã§èª¤å·®ãè¨ç®ããããcifar10.train
ã«æ¸¡ããã¨ã§å¦ç¿ãè¡ããããåãããããã
ããã¤ãã®å®æ°å¤ã¯ä¸æ¸ããã¦å¤æ´ãããã¨ãã§ããããã§ã¯
distorted_inputs
ã§ã¯32x32ãµã¤ãºã®ç»åãããã«ã©ã³ãã ã«24x24ãµã¤ãºã§åãåºãã¦å ¥åã¨ãã¦ããããä»åã¯é¡ç»åé åã«æ¢ã«åãåºããã¦ãããä¸è¦ã¨å¤æã32x32ãã®ã¾ã¾å ¥åã¨ãã- åé¡æ°ã¯ã¡ã³ãã¼5人+ãã以å¤ãã§6種é¡ã«
- ä½åº¦ãå¦ç¿ã試ãã¦ã¿ããéä¸ã§lossãçºæ£ãã¦ãã¾ããã¨ããã£ãã®ã§
INITIAL_LEARNING_RATE
ã0.1
ãã0.08
ã«å°ãä¸ãã
ãªã©ã
å
¥åç»åã®ç¨®é¡ãå°ãªããã¨ããã£ã¦ããæ°åstepã§ããååãªãããã«å¦ç¿ãé²ããVPSä¸ã§Dockerç«ã¡ä¸ãã¦åãã¦ã¿ã¦ãããã©æ°æéã§10000stepã®å¦ç¿ãçµäºããã
ã§ãå¦ç¿ã«ä½¿ã£ã¦ããªãè©ä¾¡ç¨ãã¹ããã¼ã¿ã使ã£ã¦æ£ççãè¨æ¸¬ãã¦ã¿ãã¨ãã
ã®ããã«ãªãã75%ãããã¾ã§å°éããå¾ ãã以ä¸ã¯ããä¸ãããªãããã ã£ãã
å¦ç¿çµæã使ã£ãWebã¢ããª
ãã£ããããã¾ã§ä½ã£ãã®ãªããååã®ããã«å®éã«èª°ã§ã試ããããã«Webã¢ããªã«ãã¦å ¬éãã¦ã¿ãããã¨ã
TensorFlowでのMNIST学習結果を、実際に手書きして試す - すぎゃーんメモ ã®ã¨ãã¨åæ§ã«ãå¦ç¿æ¸ã¿ã®ãã¼ã¿ã使ã£ã¦ç»åãåãåãå¤å®çµæãè¿ãJSON APIãç¨æããããã使ã£ã¦å¤å®çµæãæç»ããã
ä»»æã®ç»åãDrag and Dropã§åãåãã®ã§ãã¾ãã¯ããããå¤å®ããããã®é¡é åã ããåãåºãå¿
è¦ããããèªä½ã®é¡æ¤åºå¨ã§ã¯é
ãããã®ã§ ããã§ã¯LIMITED PREVIEWçã® Cloud Vision API ã使ã£ã¦ã¿ã¦ããã
è²ããªç»åãä¸ãã¦è©¦ãã¦ã¿ã¦ãã ããã
èå¯
åé ã®ç»åã§ã¯çäºãããé«åããã¨èª¤å¤å®ããã¦ãã以å¤ã¯å½ãã£ã¦ããããã¹ããã¼ã¿ã§ã®è©ä¾¡ã¯75%ç¨åº¦ã ãã¾ããããªãã®ãã¨ã
å®éè²ããªç»åã§è©¦ãã¦ã¿ãã¨ãã£ã¨æ®å¿µãªçµæã«ãªããã®ã®æ¹ãå¤ãããããå®ç¨çãªã¬ãã«ã«ã¯ã¾ã ã¾ã éããªãã
- è¨ç·´ç¨ã®ç»å1000æã§ã¯ã¾ã ã¾ã 足ãã¦ããªãã®ããï¼ç»è³ªã®è¯ããªãèªæ®ããå¤é¡ãªãããå¤ãããããã¡ãã£ã¨ããªã¨ã¼ã·ã§ã³ããã£ãæ¹ãè¯ããã
- å
¥å32x32ã§ã¯å°ãããããã¨ããã®ãããï¼ãããã«ãã®ããã縮å°ãããã¨èªåã§ç®è¦ãã¦ãåããã¥ããã£ããããã誤å¤å®ããã¦ãä»æ¹ãªãæ°ã¯ãã
- ãã¨é¡é åã®åãåºãæ¹ã«ãã£ã¦ãçµæ§å¤å®çµæãå¤ããããã ã£ãã®ã§ããã¯ãã©ã³ãã cropã¯ä½¿ã£ãæ¹ãè¯ãã£ãã®ãã
- ãã¥ã¼ã©ã«ãããã¯ã¼ã¯èªä½ãåç´ãããï¼ä»åã®
tensorflow.models.image.cifar10
ããã±ã¼ã¸ã®ãã®ã ã¨2é層ã ãã®ç³ã¿è¾¼ã¿-ãã¼ãªã³ã°ã§ããããå ¨çµåã®ãã®ã¨ãªã£ã¦ãããããã¡ãã£ã¨æ·±ããã®ã ã¨ã¾ã精度ãå¤ãã£ããããã ãããï¼
è²ã
ãããã¦ã¿ããã¨ããã§ã¯ãããä»ã®ã¢ã¤ãã«ããã®ç»åãéãã¦åé¡æ°ãå¢ããã¦ããããã
Repository
- https://github.com/sugyan/face-collector
- é¡ç»ååéãã¦ã©ãã«ä»ããããã¤
- https://github.com/sugyan/tf-classifier
- TensorFlowã§å¦ç¿ãããã¤
- https://github.com/sugyan/face-recognizer
- å®éã«è©¦ãWebã¢ããªã®ãã¤