|
255 | 255 | { |
256 | 256 | "cell_type": "code", |
257 | 257 | "source": [ |
| 258 | + "## Complected...Done!\n", |
258 | 259 | "## Load each directory's images and label\n", |
259 | 260 | "\n", |
260 | 261 | "class_mapping = {\n", |
|
294 | 295 | { |
295 | 296 | "cell_type": "code", |
296 | 297 | "source": [ |
| 298 | + "## Complected...Done!\n", |
297 | 299 | "## because your data is in list, convert them to np.array\n", |
298 | 300 | "\n", |
299 | 301 | "from tensorflow.keras.utils import to_categorical\n", |
|
377 | 379 | { |
378 | 380 | "cell_type": "code", |
379 | 381 | "source": [ |
| 382 | + "## Complected...Done!\n", |
| 383 | + "\n", |
380 | 384 | "from keras.models import Sequential\n", |
381 | 385 | "from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense\n", |
382 | 386 | "from keras.optimizers import Adam\n", |
|
430 | 434 | { |
431 | 435 | "cell_type": "code", |
432 | 436 | "source": [ |
| 437 | + "## Complected...Done!\n", |
| 438 | + "\n", |
433 | 439 | "hist = model.fit(\n", |
434 | 440 | " x_train_norm, y_train_encoded,\n", |
435 | 441 | " epochs=100,\n", |
|
455 | 461 | { |
456 | 462 | "cell_type": "code", |
457 | 463 | "source": [ |
| 464 | + "## Complected...Done!\n", |
| 465 | + "\n", |
458 | 466 | "acc = hist.history['accuracy']\n", |
459 | 467 | "val_acc = hist.history['val_accuracy']\n", |
460 | 468 | "epochs = range(1, len(acc) + 1)\n", |
|
487 | 495 | { |
488 | 496 | "cell_type": "code", |
489 | 497 | "source": [ |
| 498 | + "## Complected...Done!\n", |
| 499 | + "\n", |
490 | 500 | "from sklearn.metrics import confusion_matrix\n", |
491 | 501 | "import seaborn as sns\n", |
492 | 502 | "sns.set()\n", |
493 | 503 | "\n", |
494 | | - "##############################################\n", |
495 | | - "############# YOUR CODES GO HERE #############\n", |
496 | | - "y_predicted = ....\n", |
497 | | - "mat = confusion_matrix(..., ...)\n", |
498 | | - "##############################################\n", |
| 504 | + "# Predict class indices\n", |
| 505 | + "y_predicted = np.argmax(model.predict(x_test_norm), axis=1)\n", |
| 506 | + "y_true = np.argmax(y_test_encoded, axis=1)\n", |
| 507 | + "\n", |
| 508 | + "# Compute confusion matrix\n", |
| 509 | + "mat = confusion_matrix(y_true, y_predicted)\n", |
499 | 510 | "\n", |
500 | 511 | "class_labels = ['background', 'chainsaw', 'engine', 'storm']\n", |
501 | 512 | "\n", |
|
504 | 515 | " yticklabels=class_labels)\n", |
505 | 516 | "\n", |
506 | 517 | "plt.xlabel('Predicted label')\n", |
507 | | - "plt.ylabel('Actual label')" |
| 518 | + "plt.ylabel('Actual label')\n" |
508 | 519 | ], |
509 | 520 | "metadata": { |
510 | 521 | "id": "LQKAXBpkVBd-" |
|
0 commit comments