PratyushTripathy / Landsat-Classification-Using-Neural-Network

All the files mentioned in the article on Towards Data Science Neural Network for Landsat Classification Using Tensorflow in Python | A step-by-step guide.
https://medium.com/@pratyush_51648/a13bcf38f3e1
MIT License
73 stars 40 forks source link

Prediction issue while training on my custom dataset #3

Open rrsc1234 opened 3 years ago

rrsc1234 commented 3 years ago

Hi Pratyush Tripathy. By using your code as reference I am trying to do citrus crop mapping. In the following link I have attached my input files along with the predicted output.

"https://drive.google.com/file/d/1C0TCQkK-aqebJrhF_AO9jSSgmKI3fiMX/view?usp=sharing"

After running your complete code, I got following as output before going to "model.predict("Validation Image.tif")".

2021-05-15 14:34:11.825573: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-05-15 14:34:11.828208: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-05-15 14:34:44.084186: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
51819/51819 [==============================] - 56s 1ms/step - loss: 0.0214 - accuracy: 0.9970
Epoch 2/2
51819/51819 [==============================] - 48s 923us/step - loss: 0.0138 - accuracy: 0.9974
Confusion matrix: for 14 nodes
 [[1102562       0]
 [   2894       0]]

P-Score: 0.000, R-Score: 0.000

As you can see all the pixels in the predicted image is classified as true positives and false negatives. Even though in the training class image there are no. of pixels with both classes viz. 0 & 1. Can you let me know what is the issue.

jotafmr commented 2 years ago

I got the same issue.... Did u get any solution for that?

PratyushTripathy commented 2 years ago

@rrsc1234 @jotafmr This can happen when your classes are highly imbalanced. In this case, one of the classes has only about 0.2% samples of the other class, which the model will fail to learn. Try balancing the classes, see example in this article. You may need to downsample majority class and upsample (by duplicating) minority class. Let me know here how it goes.