{"metadata": {"kernelspec": {"language": "python", "name": "python3", "display_name": "Python 3"}, "language_info": {"pygments_lexer": "ipython3", "name": "python", "mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "3.6.0", "file_extension": ".py", "codemirror_mode": {"version": 3, "name": "ipython"}}}, "nbformat_minor": 1, "cells": [{"metadata": {}, "cell_type": "markdown", "source": ["\u6df1\u5ea6\u5b66\u4e60\u533a\u5206\u732b\u72d7\u56fe\u7247\u7a0b\u5e8f"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["import cv2 # \u673a\u5668\u89c6\u89c9\u5e93\uff0c\u5b89\u88c5\u8bf7\u7528pip3 install opencv-python\n", "import numpy as np # \u6570\u503c\u8ba1\u7b97\u5e93\n", "import os # \u7cfb\u7edf\u5e93\n", "from random import shuffle # \u968f\u673a\u6570\u636e\u5e93 \n", "from tqdm import tqdm # \u8f93\u51fa\u8fdb\u5ea6\u5e93\n", "import matplotlib.pyplot as plt # \u5e38\u7528\u753b\u56fe\u5e93"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["train_dir = '../input/train/'\n", "test_dir = '../input/test/'\n", "img_size = 50\n", "lr = 1e-3"]}, {"metadata": {}, "cell_type": "markdown", "source": ["\u5c06label\u53d8\u6210\u6bcf\u4e2a\u7c7b\u522b\u7684\u6982\u7387\uff08\u7c7b\u4f3c\u4e8e\u54d1\u53d8\u91cf\uff09"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": []}, {"metadata": {}, "cell_type": "markdown", "source": ["\u5904\u7406\u8bad\u7ec3\u6570\u636e\uff0c\u5927\u7ea6\u9700\u898130\u79d2"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": []}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["train_data = create_train_data()"]}, {"metadata": {}, "cell_type": "markdown", "source": ["\u5904\u7406\u6d4b\u8bd5\u6570\u636e\uff0c\u6ce8\u610f\u6ca1\u6709label\u4fe1\u606f"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["def process_test_data():\n", "    testing_data = []\n", "    for img in tqdm(os.listdir(test_dir)):\n", "        if (not img.endswith('.jpg')):\n", "            continue\n", "        path = os.path.join(test_dir,img)\n", "        img_num = img.split('.')[0]\n", "        img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)\n", "        img = cv2.resize(img, (img_size, img_size))\n", "        testing_data.append([np.array(img), img_num])\n", "        \n", "    shuffle(testing_data)\n", "    return testing_data"]}, {"metadata": {}, "cell_type": "markdown", "source": ["\u5bfc\u5165\u57fa\u4e8eTensorflow\u7684\u9ad8\u7ea7\u6df1\u5ea6\u5b66\u4e60\u5e93tflearn"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": []}, {"metadata": {}, "cell_type": "markdown", "source": ["\u8f93\u5165\u5c42"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["convnet = input_data(shape = [None, img_size, img_size, 1], name = 'input')"]}, {"metadata": {}, "cell_type": "markdown", "source": ["5\u4e2aCNN\u53camax pooling\u5c42"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": []}, {"metadata": {}, "cell_type": "markdown", "source": ["\u4e24\u4e2a\u5168\u8fde\u63a5\u5c42\u4e0e\u9884\u6d4b\u5c42"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": []}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["model = tflearn.DNN(convnet, tensorboard_dir='log')"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["train = train_data[:-500]"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["test = train_data[-500:]"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["X = np.array([i[0] for i in train]).reshape(-1, img_size, img_size, 1)\n", "y = [i[1] for i in train]\n", "Xtest = np.array([i[0] for i in test]).reshape(-1, img_size, img_size, 1)\n", "ytest = [i[1] for i in test]"]}, {"metadata": {}, "cell_type": "markdown", "source": ["\u5728\u8bad\u7ec3\u96c6\u4e0a\u8bad\u7ec3\uff0c\u65e0GPU\u5927\u7ea6\u9700\u89812\u5206\u949f"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": []}, {"metadata": {}, "cell_type": "markdown", "source": ["\u8bfb\u5165\u6d4b\u8bd5\u6570\u636e\uff0c\u5927\u7ea6\u9700\u898130\u79d2"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": ["test_data = process_test_data()"]}, {"metadata": {"collapsed": true}, "cell_type": "markdown", "source": ["\u8f93\u51fa\u6d4b\u8bd5\u6570\u636e\u4e0a\u4e00\u4e9b\u4f8b\u5b50\u7684\u9884\u6d4b"]}, {"outputs": [], "metadata": {"collapsed": true}, "cell_type": "code", "execution_count": null, "source": []}], "nbformat": 4}