- Neural Networks with Keras Cookbook
- V Kishore Ayyadevara
- 113字
- 2021-07-02 12:46:35
Problems with traditional NN
Scenario 1: Let's create a new image where the original image is translated by 1 pixel toward the left. In the following code, we are looping through the columns of the image and copying the pixel values of the next column to the current column:
for i in range(pic.shape[0]):
if i<20:
pic[:,i]=pic[:,i+1]
plt.imshow(pic)
The left translated average 1 image looks as follows:

Let’s go ahead and predict the label of the image using the built model:
model.predict(pic.reshape(1,784)/255)
The model's prediction on the translated image is as follows:

We can see a prediction of 1, though with a lower probability than when pixels were not translated.
Scenario 2: A new image is created in which the pixels of the original average 1 image are shifted by 2 pixels to the right:
pic=np.zeros((28,28))
pic2=np.copy(pic)
for i in range(X_train1.shape[0]):
pic2=X_train1[i,:,:]
pic=pic+pic2
pic=(pic/X_train1.shape[0])
pic2=np.copy(pic)
for i in range(pic.shape[0]):
if ((i>6) and (i<26)):
pic[:,i]=pic2[:,(i-1)]
plt.imshow(pic)
The right translated average 1 image looks as follows:

The prediction of this image is as follows:
model.predict(pic.reshape(1,784)/255)
The model's prediction on the translated image is as follows:

We can see that the prediction is incorrect with an output of 3. This is the problem that we will be addressing by using a CNN.
- Mastering Zabbix(Second Edition)
- OpenShift開發指南(原書第2版)
- Vue.js前端開發基礎與項目實戰
- Access 數據庫應用教程
- Python機器學習經典實例
- C語言程序設計同步訓練與上機指導(第三版)
- RSpec Essentials
- C#應用程序設計教程
- 現代C++編程實戰:132個核心技巧示例(原書第2版)
- Elasticsearch Essentials
- R語言實戰(第2版)
- 精通Rust(第2版)
- C++ Windows Programming
- 代碼整潔之道:程序員的職業素養
- Java EE企業級應用開發教程:Spring+Spring MVC+MyBatis(第2版)