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/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。