0
任何人都可以給一個乾淨的代碼加載CIFAR-10張量?如何閱讀Tensorflow中的CIFAR-10數據集?
我已經檢查的tensorflow的GitHub庫給出的例子。但我不想將圖像大小調整爲24x24。基本上,我正在尋找更簡單,更簡單的代碼。
任何人都可以給一個乾淨的代碼加載CIFAR-10張量?如何閱讀Tensorflow中的CIFAR-10數據集?
我已經檢查的tensorflow的GitHub庫給出的例子。但我不想將圖像大小調整爲24x24。基本上,我正在尋找更簡單,更簡單的代碼。
請看看下面github頁面,在這裏我已經做到了這一點。如果上述鏈接失敗,請按照kgeorge.github.io的指示行事,並查看筆記本tf_cifar.ipynb。我試圖使用嬰兒步驟加載cifar-10數據。請查找函數load_and_preprocess_input
該代碼中的以下函數接受數據爲(nsamples,32x32x3)float32的np數組,並標記爲nsamples int32的np數組,並預處理要由tensorflow消耗的數據訓練。
image_depth=3
image_height=32
image_width=32
#data = (nsamples, 32x32x3) float32
#labels = (nsamples) int32
def prepare_input(data=None, labels=None):
global image_height, image_width, image_depth
assert(data.shape[1] == image_height * image_width * image_depth)
assert(data.shape[0] == labels.shape[0])
#do mean normaization across all samples
mu = np.mean(data, axis=0)
mu = mu.reshape(1,-1)
sigma = np.std(data, axis=0)
sigma = sigma.reshape(1, -1)
data = data - mu
data = data/sigma
is_nan = np.isnan(data)
is_inf = np.isinf(data)
if np.any(is_nan) or np.any(is_inf):
print('data is not well-formed : is_nan {n}, is_inf: {i}'.format(n= np.any(is_nan), i=np.any(is_inf)))
#data is transformed from (no_of_samples, 3072) to (no_of_samples , image_height, image_width, image_depth)
#make sure the type of the data is no.float32
data = data.reshape([-1,image_depth, image_height, image_width])
data = data.transpose([0, 2, 3, 1])
data = data.astype(np.float32)
return data, labels
謝謝!這幫助我設計了一個使用張量流的小實例。顯然,我已經給你信貸。 –
我收到一個錯誤 ImportError:沒有名爲'_future_'的模塊 嘗試使用pip進行安裝。但沒有工作。 – user2728024
看到這個,http://stackoverflow.com/questions/40479160/no-module-named-future –