sinadabiri / Transport-Mode-GPS-CNN

Inferring transportation modes from GPS trajectories using a Convolutional Neural Network
MIT License
45 stars 18 forks source link

CNN-Ensemble-keras.py failed: ZeroDivisionError: float division by zero #7

Open arilwan opened 4 years ago

arilwan commented 4 years ago

@sinadabiri Step 6: Running the file CNN-Ensemble-Keras.py failed at some point (after some hours training model). I attempted this more than 10-times, but run into ZeroDivisionError problem as below:

 .....
.....
.....
Epoch 95/100
25956/25956 [==============================] - 18s 703us/step - loss: 0.3272 - acc: 0.9729
Epoch 96/100
25956/25956 [==============================] - 18s 699us/step - loss: 0.3191 - acc: 0.9745
Epoch 97/100
25956/25956 [==============================] - 18s 698us/step - loss: 0.3171 - acc: 0.9758
Epoch 98/100
25956/25956 [==============================] - 18s 698us/step - loss: 0.3339 - acc: 0.9728
Epoch 99/100
25956/25956 [==============================] - 18s 697us/step - loss: 0.3387 - acc: 0.9721
Epoch 100/100
25956/25956 [==============================] - 18s 698us/step - loss: 0.3116 - acc: 0.9749
6489/6489 [==============================] - 1s 84us/step
Traceback (most recent call last):
  File "CNN-Ensemble-keras.py", line 111, in <module>
    Precision.append(len(TruePositive[i]) * 1./len(PredictedPositive[i]))
ZeroDivisionError: float division by zero
(venv) akil@IT-PC:~/Desktop/tempo/Transport-Mode-GPS-CNN$

Since Step 5 CNN-Keras.py file input is not found (i.e file Revised_KerasData_Smoothing.pickle ) I assumed (similar to what's reported by @poteman in #1 ) it actually refers to the output file of Step 4 Keras_Data_Creation.py which is actually Revised_KerasData_NoSmoothing.pickle. This way, Step 5 runs successfully.

But Step 6, which take the same file input as Step 5 keeps failing with the above error.

How do I fix this please?

arilwan commented 4 years ago

Here's the result I get after commenting out the lines causing the said error:

Epoch 99/100
25956/25956 [==============================] - 18s 699us/step - loss: 0.2265 - acc: 0.9793
Epoch 100/100
25956/25956 [==============================] - 18s 708us/step - loss: 0.2197 - acc: 0.9812
6489/6489 [==============================] - 1s 85us/step
[[11.251003384718747, 0.0752041916987124], [12.70107099994854, 0.06241331483016563], [12.136834799921886, 0.0659577746853051], [11.947656822968822, 0.06395438435421572], [11.907114852538442, 0.0673447372373162], [11.88471240030266, 0.06318384958128291], [11.869897016741898, 0.06148867313226946]]
Ensemble Accuracy:  0.059639389736477116
Confusion Matrix:  [[ 192 1916    0    0    0]
 [ 969  195    0    0    0]
 [1242  123    0    0    0]
 [ 843   58    0    0    0]
 [ 872   79    0    0    0]]

Lines causing the error:

#for i in range(NoClass):
#    Precision.append(len(TruePositive[i]) * 1./len(PredictedPositive[i]))
#    Recall.append(len(TruePositive[i]) * 1./len(ActualPositive[i]))

I doubt the accuracy I get (Ensemble Accuracy: 0.059639389736477116), so I suspect I'm missing something. What the problem here please?

arilwan commented 4 years ago

@sinadabiri Step 6: Running the file CNN-Ensemble-Keras.py failed at some point (after some hours training model). I attempted this more than 10-times, but run into ZeroDivisionError problem as below:

.....
.....
.....
Epoch 95/100
25956/25956 [==============================] - 18s 703us/step - loss: 0.3272 - acc: 0.9729
Epoch 96/100
25956/25956 [==============================] - 18s 699us/step - loss: 0.3191 - acc: 0.9745
Epoch 97/100
25956/25956 [==============================] - 18s 698us/step - loss: 0.3171 - acc: 0.9758
Epoch 98/100
25956/25956 [==============================] - 18s 698us/step - loss: 0.3339 - acc: 0.9728
Epoch 99/100
25956/25956 [==============================] - 18s 697us/step - loss: 0.3387 - acc: 0.9721
Epoch 100/100
25956/25956 [==============================] - 18s 698us/step - loss: 0.3116 - acc: 0.9749
6489/6489 [==============================] - 1s 84us/step
Traceback (most recent call last):
 File "CNN-Ensemble-keras.py", line 111, in <module>
   Precision.append(len(TruePositive[i]) * 1./len(PredictedPositive[i]))
ZeroDivisionError: float division by zero
(venv) akil@IT-PC:~/Desktop/tempo/Transport-Mode-GPS-CNN$

Since Step 5 CNN-Keras.py file input is not found (i.e file Revised_KerasData_Smoothing.pickle ) I assumed (similar to what's reported by @poteman in #1 ) it actually refers to the output file of Step 4 Keras_Data_Creation.py which is actually Revised_KerasData_NoSmoothing.pickle. This way, Step 5 runs successfully.

But Step 6, which take the same file input as Step 5 keeps failing with the above error.

How do I fix this please?

@sinadabiri Sorry to get back on this issue again? But I cannot figure out why it fails with this error CNN-Ensemble.py