CNN卷积神经网络实现图像识别


# coding: utf-8

# In[2]:


import urllib.request
import os
import tarfile
import pickle as p
import numpy as np
import tensorflow as tf


# ## 1、下载数据集

# In[3]:


filepath = 'data/cifar-10-python.tar.gz'
if not os.path.exists("data/cifar-10-batches-py"):
    tfile = tarfile.open("data/cifar-10-python.tar.gz" , 'r:gz')
    result=tfile.extractall("data/")
    print("Extracted to ./data/cifar-10-batches-py/")
else:
    print("Directory already exists.")  


# # 2、导入CIFAR数据集

# In[4]:


def load_CIFAR_batch(filename):
    """ load single batch of cifar """
    with open(filename, 'rb')as f:
    #—个样本由标签和图像数据组成
    #  <3072 x pixel>(3072=32x32x3)
    #..
    # <1 x label> <3072 x pixel>
        data_dict = p.load(f,encoding='bytes')
        images= data_dict[b'data']
        labels = data_dict[b'labels

你可能感兴趣的:(神经网络,深度学习,tensorflow,python)