天天看點

Cat and Dog Image Classifier How to solve ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`?

https://www.freecodecamp.org/learn/machine-learning-with-python/machine-learning-with-python-projects/cat-and-dog-image-classifier

For this challenge, you will use TensorFlow 2.0 and Keras to create a convolutional neural network that correctly classifies images of cats and dogs with at least 63% accuracy. You can access the full project instructions and starter code on Google Colaboratory.

https://colab.research.google.com/drive/1mszXu-aNyHhEbJ9oi-52V3ZtNfwVq_vY#scrollTo=A9TMZH_oSULo

To avoid overfitting and create a larger dataset from a smaller one we can use a technique called data augmentation. This is simply performing random transofrmations on our images so that our model can generalize better. These transformations can be things like compressions, rotations, stretches and even color changes. Fortunately, keras can help us do this. Look at the code below to an example of data augmentation.

https://keras.io/zh/preprocessing/image/

通過實時資料增強生成張量圖像資料批次。資料将不斷循環(按批次)。

随機變換,增加樣本多樣性,避免過拟合。

對于海量圖檔,使用flow_from_directory 批量從磁盤上讀取圖檔,節省記憶體空間。

如果不需要進行随機變換,可以使用這個方法讀取圖檔。

https://www.tensorflow.org/tutorials/images/classification#create_a_dataset

使用這種方法,可以在模型層,做圖檔預處理,包括随機變換。

https://www.tensorflow.org/tutorials/images/classification#data_augmentation

類似一個pipeline結構,可以設計不同的模型中的層,來處理不同的工作。

https://keras.io/api/layers/

The base Layer class Layer activations Layer weight initializers Layer weight regularizers Layer weight constraints Core layers Convolution layers Pooling layers Recurrent layers Preprocessing layers Normalization layers Regularization layers Attention layers Reshaping layers Merging layers Locally-connected layers Activation layers

例如圖檔預處理

https://keras.io/api/layers/preprocessing_layers/image_preprocessing/

Resizing layer Rescaling layer CenterCrop layer RandomCrop layer RandomFlip layer RandomTranslation layer RandomRotation layer RandomZoom layer RandomHeight layer RandomWidth layer

https://www.tensorflow.org/tutorials/images/classification#predict_on_new_data

https://gist.github.com/NiharG15/cd8272c9639941cf8f481a7c4478d525

https://stackoverflow.com/questions/63006475/how-to-solve-importerror-keras-requires-tensorflow-2-2-or-higher-install-tenso

https://www.zhihu.com/question/36023110

這個文章裡講的東西對我比較有用,分享出來。 My Neural Network isn't working! What should I do? 裡面總結了11條可能出現的錯誤。簡單翻譯如下: 沒有對資料做歸一化。 沒有檢查過你的結果。這裡的結果包括預處理結果和最終的訓練測試結果。 忘了做資料預處理。 忘了使用正則化。 Batch Size設的太大。 學習率設的不對。 最後一層的激活函數用的不對。 網絡存在壞梯度。比如Relu對負值的梯度為0,反向傳播時,0梯度就是不傳播。 參數初始化錯誤。 網絡太深。 隐藏層神經元數量錯誤。

出處:http://www.cnblogs.com/lightsong/

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接。

繼續閱讀