深度学习

5月 192017
 
2017 data science bowl 2nd https://github.com/dhammack/DSB2017/ https://github.com/juliandewit/kaggle_ndsb2017/
增强学习介绍 https://lufficc.com/blog/reinforcement-learning-and-implementation https://github.com/lufficc/dqn
Demystifying Deep Reinforcement Learning https://www.nervanasys.com/demystifying-deep-reinforcement-learning/
Santander Product Recommendation https://github.com/ttvand/Santander-Product-Recommendation
https://github.com/aaron-xichen/pytorch-playground Base pretrained models and datasets in pytorch (MNIST, SVHN, CIFAR10, CIFAR100, STL10, AlexNet, VGG16, VGG19, ResNet, Inception, SqueezeNet)
伯克利增强学习课程 http://rll.berkeley.edu/deeprlcourse/
DQN 从入门到放弃1 DQN与增强学习 https://zhuanlan.zhihu.com/p/21262246
alphago介绍 http://www0.cs.ucl.ac.uk/staff/D.Silver/web/Resources_files/AlphaGo_IJCAI.pdf
geohash https://en.wikipedia.org/wiki/Geohash http://blog.csdn.net/zmx729618/article/details/53068170 http://www.cnblogs.com/dengxinglin/archive/2012/12/14/2817761.html
    com.spatial4j
    spatial4j
    0.5
    ch.hsr
    geohash
    1.3.0
http://blog.csdn.net/ghsau/article/details/50591932
deepmind papers https://deepmind.com/research/publications/
How we built Tagger News: machine learning on a tight schedule http://varianceexplained.org/programming/tagger-news/  https://github.com/dodger487
mnist data csv format https://pjreddie.com/projects/mnist-in-csv/
deep chatbots https://github.com/mckinziebrandon/DeepChatModels

 
 Posted by at 11:36 下午
4月 082017
 

https://github.com/kwotsin/awesome-deep-vision
from https://github.com/m2dsupsdlclass/lectures-labs
LeCun, Y., Bottou, L., Bengio, Y., and Haffner, P. (1998). Gradient-based learning applied to document recognition. LeNet
Simonyan, Karen, and Zisserman. "Very deep convolutional networks for large-scale image recognition." (2014) VGG-16
Simplified version of Krizhevsky, Alex, Sutskever, and Hinton. "Imagenet classification with deep convolutional neural networks." NIPS 2012 AlexNet
He, Kaiming, et al. "Deep residual learning for image recognition." CVPR. 2016. ResNet
Szegedy, et al. "Inception-v4, inception-resnet and the impact of residual connections on learning." (2016)
Canziani, Paszke, and Culurciello. "An Analysis of Deep Neural Network Models for Practical Applications." (May 2016).

classification and localization
Redmon, Joseph, et al. "You only look once: Unified, real-time object detection." CVPR (2016)
Liu, Wei, et al. "SSD: Single shot multibox detector." ECCV 2016
Girshick, Ross, et al. "Fast r-cnn." ICCV 2015
Ren, Shaoqing, et al. "Faster r-cnn: Towards real-time object detection with region proposal networks." NIPS 2015
Redmon, Joseph, et al. "YOLO9000, Faster, Better, Stronger." 2017

segmentation
Long, Jonathan, et al. "Fully convolutional networks for semantic segmentation." CVPR 2015
Noh, Hyeonwoo, et al. "Learning deconvolution network for semantic segmentation." ICCV 2015
Pinheiro, Pedro O., et al. "Learning to segment object candidates" / "Learning to refine object segments", NIPS 2015 / ECCV 2016
Li, Yi, et al. "Fully Convolutional Instance-aware Semantic Segmentation." Winner of COCO challenge 2016.

弱监督学习 Weak supervision
Joulin, Armand, et al. "Learning visual features from large weakly supervised data." ECCV, 2016
Oquab, Maxime, "Is object localization for free? – Weakly-supervised learning with convolutional neural networks", 2015

Self-supervised learning
Doersch, Carl, Abhinav Gupta, and Alexei A. Efros. "Unsupervised visual representation learning by context prediction." ICCV 2015.


dnn优化
Ren, Mengye, et al. "Normalizing the Normalizers: Comparing and Extending Network Normalization Schemes." 2017
Salimans, Tim, and Diederik P. Kingma. "Weight normalization: A simple reparameterization to accelerate training of deep neural networks." NIPS 2016.
Ba, Jimmy Lei, Jamie Ryan Kiros, and Geoffrey E. Hinton. "Layer normalization." 2016.
Ioffe, Sergey, and Christian Szegedy. "Batch normalization: Accelerating deep network training by reducing internal covariate shift." ICML 2015
Generalization
Understanding deep learning requires rethinking generalization, C. Zhang et al., 2016.
On Large-Batch Training for Deep Learning: Generalization Gap and Sharp Minima, N. S. Keskar et al., 2016
1. A strong optimizer is not necessarily a strong learner.
2. DL optimization is non-convex but bad local minima and saddle structures are rarely a problem (on common DL tasks).
3. Neural Networks are over-parametrized but can still generalize.
4. Stochastic Gradient is a strong implicit regularizer.
5. Variance in gradient can help with generalization but can hurt final convergence.
6. We need more theory to guide the design of architectures and optimizers that make learning faster with fewer labels.
7. Overparametrize deep architectures
8. Design architectures to limit conditioning issues:
(1)Use skip / residual connections
(2)Internal normalization layers
(3)Use stochastic optimizers that are robust to bad conditioning
9. Use small minibatches (at least at the beginning of optimization)
10. Use validation set to anneal learning rate and do early stopping
11. Is it very often possible to trade more compute for less overfitting with data augmentation and stochastic regularizers (e.g. dropout).
12. Collecting more labelled data is the best way to avoid overfitting.


 
 Posted by at 4:04 下午
2月 272017
 
RNN预测股票价格小实验

RNN示例

基于basic rnn构建时间序列预测模型,预测股票价格趋势。本实例仅仅作为RNN学习实验。

代码


# -*- coding: utf-8 -*-
# @DATE    : 2017/2/14 17:50
# @Author  : 
# @File    : stock_predict.py

import os
import sys
import datetime

import tensorflow as tf
import pandas as pd
import numpy as np
from yahoo_finance import Share
import matplotlib.pyplot as plt

from utils import get_n_day_before, date_2_str


class StockRNN(object):
    def __init__(self, seq_size=12, input_dims=1, hidden_layer_size=12, stock_id="BABA", days=365, log_dir="stock_model/"):
        self.seq_size = seq_size
        self.input_dims = input_dims
        self.hidden_layer_size = hidden_layer_size
        self.stock_id = stock_id
        self.days = days
        self.data = self._read_stock_data()["Adj_Close"].astype(float).values
        self.log_dir = log_dir

    def _read_stock_data(self):
        stock = Share(self.stock_id)
        end_date = date_2_str(datetime.date.today())
        start_date = get_n_day_before(200)
        # print(start_date, end_date)

        his_data = stock.get_historical(start_date=start_date, end_date=end_date)
        stock_pd = pd.DataFrame(his_data)
        stock_pd["Adj_Close"] = stock_pd["Adj_Close"].astype(float)
        stock_pd.sort_values(["Date"], inplace=True, ascending=True)
        stock_pd.reset_index(inplace=True)
        return stock_pd[["Date", "Adj_Close"]]

    def _create_placeholders(self):
        with tf.name_scope(name="data"):
            self.X = tf.placeholder(tf.float32, [None, self.seq_size, self.input_dims], name="x_input")
            self.Y = tf.placeholder(tf.float32, [None, self.seq_size], name="y_input")

    def init_network(self, log_dir):
        print("Init RNN network")
        self.log_dir = log_dir
        self.sess = tf.Session()
        self.summary_op = tf.summary.merge_all()
        self.saver = tf.train.Saver()
        self.summary_writer = tf.summary.FileWriter(self.log_dir, self.sess.graph)
        self.sess.run(tf.global_variables_initializer())
        ckpt = tf.train.get_checkpoint_state(self.log_dir)
        if ckpt and ckpt.model_checkpoint_path:
            self.saver.restore(self.sess, ckpt.model_checkpoint_path)
            print("Model restore")

        self.coord = tf.train.Coordinator()
        self.threads = tf.train.start_queue_runners(self.sess, self.coord)

    def _create_rnn(self):
        W = tf.Variable(tf.random_normal([self.hidden_layer_size, 1], name="W"))
        b = tf.Variable(tf.random_normal([1], name="b"))
        with tf.variable_scope("cell_d"):
            cell = tf.contrib.rnn.BasicLSTMCell(self.hidden_layer_size)
        with tf.variable_scope("rnn_d"):
            outputs, states = tf.nn.dynamic_rnn(cell, self.X, dtype=tf.float32)

        W_repeated = tf.tile(tf.expand_dims(W, 0), [tf.shape(self.X)[0], 1, 1])
        out = tf.matmul(outputs, W_repeated) + b
        out = tf.squeeze(out)
        return out

    def _data_prepare(self):
        self.train_x = []
        self.train_y = []
        # data
        data = np.log1p(self.data)
        for i in xrange(len(data) - self.seq_size - 1):
            self.train_x.append(np.expand_dims(data[i: i + self.seq_size], axis=1).tolist())
            self.train_y.append(data[i + 1: i + self.seq_size + 1].tolist())

    def train_pred_rnn(self):

        self._create_placeholders()

        y_hat = self._create_rnn()
        self._data_prepare()
        loss = tf.reduce_mean(tf.square(y_hat - self.Y))
        train_optim = tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss)
        feed_dict = {self.X: self.train_x, self.Y: self.train_y}

        saver = tf.train.Saver(tf.global_variables())
        with tf.Session() as sess:
            sess.run(tf.global_variables_initializer())
            for step in xrange(1, 20001):
                _, loss_ = sess.run([train_optim, loss], feed_dict=feed_dict)
                if step % 100 == 0:
                    print("{} {}".format(step, loss_))
            saver.save(sess, self.log_dir + "model.ckpt")

            # prediction
            prev_seq = self.train_x[-1]
            predict = []
            for i in range(5):
                next_seq = sess.run(y_hat, feed_dict={self.X: [prev_seq]})
                predict.append(next_seq[-1])
                prev_seq = np.vstack((prev_seq[1:], next_seq[-1]))
            predict = np.exp(predict) - 1
            print(predict)
            self.pred = predict

    def visualize(self):
        pred = self.pred
        plt.figure()
        plt.legend(prop={'family': 'SimHei', 'size': 15})
        plt.plot(list(range(len(self.data))), self.data, color='b')
        plt.plot(list(range(len(self.data), len(self.data) + len(pred))), pred, color='r')
        plt.title(u"{}股价预测".format(self.stock_id), fontproperties="SimHei")
        plt.xlabel(u"日期", fontproperties="SimHei")
        plt.ylabel(u"股价", fontproperties="SimHei")
        plt.savefig("stock.png")
        plt.show()


if __name__ == "__main__":
    stock = StockRNN()
    # print(stock.read_stock_data())
    log_dir = "stock_model"
    stock.train_pred_rnn()
    stock.visualize()

运行结果,预测BABA未来5天股价2017.2.27


[ 104.23436737  103.82189941  103.59770966  103.43360138  103.29838562]

部分数据2017-02-08,103.57 2017-02-09,103.339996 2017-02-10,102.360001 2017-02-13,103.099998 2017-02-14,101.589996 2017-02-15,101.550003 2017-02-16,100.82 2017-02-17,100.519997 2017-02-21,102.120003 2017-02-22,104.199997 2017-02-23,102.459999 2017-02-24,102.949997



 
 Posted by at 10:04 下午