diff --git a/.gitignore b/.gitignore index 30cbe59..d0d6e80 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ Train&Test_C/ result_ssd7_panel/ result_ssd7_panel_cell/ Thermal/ - +fault_jpg/ +fault_jpg_1/ diff --git a/Panel_Detector_Fault_1.ipynb b/Panel_Detector_Fault_1.ipynb new file mode 100644 index 0000000..84649d6 --- /dev/null +++ b/Panel_Detector_Fault_1.ipynb @@ -0,0 +1,1601 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Cargar el modelo ssd7 \n", + "(https://github.com/pierluigiferrari/ssd_keras#how-to-fine-tune-one-of-the-trained-models-on-your-own-dataset)\n", + "\n", + "Training del SSD7 (modelo reducido de SSD). Parámetros en config_7.json y descargar VGG_ILSVRC_16_layers_fc_reduced.h5\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Using TensorFlow backend.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Training on: \t{'1': 1}\n", + "\n", + "\n", + "Loading pretrained weights.\n", + "\n", + "WARNING:tensorflow:From /home/dl-desktop/anaconda3/envs/tf_gpu/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Colocations handled automatically by placer.\n", + "WARNING:tensorflow:From /home/dl-desktop/Desktop/Rentadrone/ssd_keras-master/keras_loss_function/keras_ssd_loss.py:133: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Use tf.cast instead.\n", + "WARNING:tensorflow:From /home/dl-desktop/Desktop/Rentadrone/ssd_keras-master/keras_loss_function/keras_ssd_loss.py:166: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Use tf.cast instead.\n", + "WARNING:tensorflow:From /home/dl-desktop/anaconda3/envs/tf_gpu/lib/python3.6/site-packages/tensorflow/python/ops/math_grad.py:102: div (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Deprecated in favor of operator or tf.math.divide.\n" + ] + } + ], + "source": [ + "from keras.optimizers import Adam, SGD\n", + "from keras.callbacks import ModelCheckpoint, LearningRateScheduler, TerminateOnNaN, CSVLogger\n", + "from keras import backend as K\n", + "from keras.models import load_model\n", + "from math import ceil\n", + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "import os\n", + "import json\n", + "import xml.etree.cElementTree as ET\n", + "\n", + "import sys\n", + "sys.path += [os.path.abspath('../ssd_keras-master')]\n", + "\n", + "from keras_loss_function.keras_ssd_loss import SSDLoss\n", + "from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes\n", + "from keras_layers.keras_layer_DecodeDetections import DecodeDetections\n", + "from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast\n", + "from keras_layers.keras_layer_L2Normalization import L2Normalization\n", + "from ssd_encoder_decoder.ssd_input_encoder import SSDInputEncoder\n", + "from ssd_encoder_decoder.ssd_output_decoder import decode_detections, decode_detections_fast\n", + "from data_generator.object_detection_2d_data_generator import DataGenerator\n", + "from data_generator.object_detection_2d_geometric_ops import Resize\n", + "from data_generator.object_detection_2d_photometric_ops import ConvertTo3Channels\n", + "from data_generator.data_augmentation_chain_original_ssd import SSDDataAugmentation\n", + "from data_generator.object_detection_2d_misc_utils import apply_inverse_transforms\n", + "from eval_utils.average_precision_evaluator import Evaluator\n", + "from data_generator.data_augmentation_chain_variable_input_size import DataAugmentationVariableInputSize\n", + "from data_generator.data_augmentation_chain_constant_input_size import DataAugmentationConstantInputSize\n", + "\n", + "\n", + "def makedirs(path):\n", + " try:\n", + " os.makedirs(path)\n", + " except OSError:\n", + " if not os.path.isdir(path):\n", + " raise\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "K.tensorflow_backend._get_available_gpus()\n", + "\n", + "\n", + "def lr_schedule(epoch):\n", + " if epoch < 80:\n", + " return 0.001\n", + " elif epoch < 100:\n", + " return 0.0001\n", + " else:\n", + " return 0.00001\n", + "\n", + "config_path = 'config_300_fault_1.json'\n", + "\n", + "\n", + "with open(config_path) as config_buffer:\n", + " config = json.loads(config_buffer.read())\n", + "\n", + "###############################\n", + "# Parse the annotations\n", + "###############################\n", + "path_imgs_training = config['train']['train_image_folder']\n", + "path_anns_training = config['train']['train_annot_folder']\n", + "path_imgs_val = config['test']['test_image_folder']\n", + "path_anns_val = config['test']['test_annot_folder']\n", + "labels = config['model']['labels']\n", + "categories = {}\n", + "#categories = {\"Razor\": 1, \"Gun\": 2, \"Knife\": 3, \"Shuriken\": 4} #la categoría 0 es la background\n", + "for i in range(len(labels)): categories[labels[i]] = i+1\n", + "print('\\nTraining on: \\t' + str(categories) + '\\n')\n", + "\n", + "####################################\n", + "# Parameters\n", + "###################################\n", + " #%%\n", + "img_height = config['model']['input'] # Height of the model input images\n", + "img_width = config['model']['input'] # Width of the model input images\n", + "img_channels = 3 # Number of color channels of the model input images\n", + "mean_color = [123, 117, 104] # The per-channel mean of the images in the dataset. Do not change this value if you're using any of the pre-trained weights.\n", + "swap_channels = [2, 1, 0] # The color channel order in the original SSD is BGR, so we'll have the model reverse the color channel order of the input images.\n", + "n_classes = len(labels) # Number of positive classes, e.g. 20 for Pascal VOC, 80 for MS COCO\n", + "scales_pascal = [0.01, 0.05, 0.1, 0.2, 0.37, 0.54, 0.71] # The anchor box scaling factors used in the original SSD300 for the Pascal VOC datasets\n", + "#scales_coco = [0.07, 0.15, 0.33, 0.51, 0.69, 0.87, 1.05] # The anchor box scaling factors used in the original SSD300 for the MS COCO datasets\n", + "scales = scales_pascal\n", + "aspect_ratios = [[1.0, 2.0, 0.5],\n", + " [1.0, 2.0, 0.5, 3.0, 1.0/3.0],\n", + " [1.0, 2.0, 0.5, 3.0, 1.0/3.0],\n", + " [1.0, 2.0, 0.5, 3.0, 1.0/3.0],\n", + " [1.0, 2.0, 0.5],\n", + " [1.0, 2.0, 0.5]] # The anchor box aspect ratios used in the original SSD300; the order matters\n", + "two_boxes_for_ar1 = True\n", + "steps = [8, 16, 32, 64, 100, 300] # The space between two adjacent anchor box center points for each predictor layer.\n", + "offsets = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5] # The offsets of the first anchor box center points from the top and left borders of the image as a fraction of the step size for each predictor layer.\n", + "clip_boxes = False # Whether or not to clip the anchor boxes to lie entirely within the image boundaries\n", + "variances = [0.1, 0.1, 0.2, 0.2] # The variances by which the encoded target coordinates are divided as in the original implementation\n", + "normalize_coords = True\n", + "\n", + "K.clear_session() # Clear previous models from memory.\n", + "\n", + "\n", + "model_path = config['train']['saved_weights_name']\n", + "# 3: Instantiate an optimizer and the SSD loss function and compile the model.\n", + "# If you want to follow the original Caffe implementation, use the preset SGD\n", + "# optimizer, otherwise I'd recommend the commented-out Adam optimizer.\n", + "\n", + "\n", + "if config['model']['backend'] == 'ssd7':\n", + " #weights_path = 'VGG_ILSVRC_16_layers_fc_reduced.h5'\n", + " scales = [0.08, 0.16, 0.32, 0.64, 0.96] # An explicit list of anchor box scaling factors. If this is passed, it will override `min_scale` and `max_scale`.\n", + " aspect_ratios = [0.5 ,1.0, 2.0] # The list of aspect ratios for the anchor boxes\n", + " two_boxes_for_ar1 = True # Whether or not you want to generate two anchor boxes for aspect ratio 1\n", + " steps = None # In case you'd like to set the step sizes for the anchor box grids manually; not recommended\n", + " offsets = None\n", + "\n", + "if os.path.exists(model_path):\n", + " print(\"\\nLoading pretrained weights.\\n\")\n", + " # We need to create an SSDLoss object in order to pass that to the model loader.\n", + " ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)\n", + "\n", + " K.clear_session() # Clear previous models from memory.\n", + " model = load_model(model_path, custom_objects={'AnchorBoxes': AnchorBoxes,\n", + " 'L2Normalization': L2Normalization,\n", + " 'compute_loss': ssd_loss.compute_loss})\n", + "\n", + "\n", + "else:\n", + " ####################################\n", + " # Build the Keras model.\n", + " ###################################\n", + "\n", + " if config['model']['backend'] == 'ssd300':\n", + " #weights_path = 'VGG_VOC0712Plus_SSD_300x300_ft_iter_160000.h5'\n", + " from models.keras_ssd300 import ssd_300 as ssd\n", + "\n", + " model = ssd(image_size=(img_height, img_width, img_channels),\n", + " n_classes=n_classes,\n", + " mode='training',\n", + " l2_regularization=0.0005,\n", + " scales=scales,\n", + " aspect_ratios_per_layer=aspect_ratios,\n", + " two_boxes_for_ar1=two_boxes_for_ar1,\n", + " steps=steps,\n", + " offsets=offsets,\n", + " clip_boxes=clip_boxes,\n", + " variances=variances,\n", + " normalize_coords=normalize_coords,\n", + " subtract_mean=mean_color,\n", + " swap_channels=swap_channels)\n", + "\n", + "\n", + " elif config['model']['backend'] == 'ssd7':\n", + " #weights_path = 'VGG_ILSVRC_16_layers_fc_reduced.h5'\n", + " from models.keras_ssd7 import build_model as ssd\n", + " scales = [0.08, 0.16, 0.32, 0.64, 0.96] # An explicit list of anchor box scaling factors. If this is passed, it will override `min_scale` and `max_scale`.\n", + " aspect_ratios = [0.5 ,1.0, 2.0] # The list of aspect ratios for the anchor boxes\n", + " two_boxes_for_ar1 = True # Whether or not you want to generate two anchor boxes for aspect ratio 1\n", + " steps = None # In case you'd like to set the step sizes for the anchor box grids manually; not recommended\n", + " offsets = None\n", + " model = ssd(image_size=(img_height, img_width, img_channels),\n", + " n_classes=n_classes,\n", + " mode='training',\n", + " l2_regularization=0.0005,\n", + " scales=scales,\n", + " aspect_ratios_global=aspect_ratios,\n", + " aspect_ratios_per_layer=None,\n", + " two_boxes_for_ar1=two_boxes_for_ar1,\n", + " steps=steps,\n", + " offsets=offsets,\n", + " clip_boxes=clip_boxes,\n", + " variances=variances,\n", + " normalize_coords=normalize_coords,\n", + " subtract_mean=None,\n", + " divide_by_stddev=None)\n", + "\n", + " else :\n", + " print('Wrong Backend')\n", + "\n", + "\n", + "\n", + " print('OK create model')\n", + " #sgd = SGD(lr=config['train']['learning_rate'], momentum=0.9, decay=0.0, nesterov=False)\n", + "\n", + " # TODO: Set the path to the weights you want to load. only for ssd300 or ssd512\n", + "\n", + " weights_path = '../ssd_keras-master/VGG_ILSVRC_16_layers_fc_reduced.h5'\n", + " print(\"\\nLoading pretrained weights VGG.\\n\")\n", + " model.load_weights(weights_path, by_name=True)\n", + "\n", + " # 3: Instantiate an optimizer and the SSD loss function and compile the model.\n", + " # If you want to follow the original Caffe implementation, use the preset SGD\n", + " # optimizer, otherwise I'd recommend the commented-out Adam optimizer.\n", + "\n", + "\n", + " #adam = Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)\n", + " #sgd = SGD(lr=0.001, momentum=0.9, decay=0.0, nesterov=False)\n", + " optimizer = Adam(lr=config['train']['learning_rate'], beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)\n", + " ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)\n", + " model.compile(optimizer=optimizer, loss=ssd_loss.compute_loss)\n", + "\n", + " model.summary()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Instanciar los generadores de datos y entrenamiento del modelo.\n", + "\n", + "*Cambio realizado para leer png y jpg. keras-ssd-master/data_generator/object_detection_2d_data_generator.py función parse_xml\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Processing image set 'train.txt': 100%|██████████| 783/783 [00:01<00:00, 511.30it/s]\n", + "Processing image set 'test.txt': 100%|██████████| 117/117 [00:00<00:00, 449.85it/s]\n", + "1 : 2246\n", + "Number of images in the training dataset:\t 783\n", + "Number of images in the validation dataset:\t 117\n", + "Epoch 1/100\n", + "\n", + "Epoch 00001: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 471s 942ms/step - loss: 3.8465 - val_loss: 3.9360\n", + "\n", + "Epoch 00001: val_loss improved from inf to 3.93599, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 2/100\n", + "\n", + "Epoch 00002: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 465s 931ms/step - loss: 3.8139 - val_loss: 3.8815\n", + "\n", + "Epoch 00002: val_loss improved from 3.93599 to 3.88150, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 3/100\n", + "\n", + "Epoch 00003: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 460s 920ms/step - loss: 3.8367 - val_loss: 3.9229\n", + "\n", + "Epoch 00003: val_loss did not improve from 3.88150\n", + "Epoch 4/100\n", + "\n", + "Epoch 00004: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 458s 917ms/step - loss: 3.8556 - val_loss: 3.8905\n", + "\n", + "Epoch 00004: val_loss did not improve from 3.88150\n", + "Epoch 5/100\n", + "\n", + "Epoch 00005: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 453s 907ms/step - loss: 3.8205 - val_loss: 3.8369\n", + "\n", + "Epoch 00005: val_loss improved from 3.88150 to 3.83686, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 6/100\n", + "\n", + "Epoch 00006: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 900ms/step - loss: 3.8164 - val_loss: 3.9733\n", + "\n", + "Epoch 00006: val_loss did not improve from 3.83686\n", + "Epoch 7/100\n", + "\n", + "Epoch 00007: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 453s 905ms/step - loss: 3.7874 - val_loss: 3.8792\n", + "\n", + "Epoch 00007: val_loss did not improve from 3.83686\n", + "Epoch 8/100\n", + "\n", + "Epoch 00008: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.7895 - val_loss: 3.8497\n", + "\n", + "Epoch 00008: val_loss did not improve from 3.83686\n", + "Epoch 9/100\n", + "\n", + "Epoch 00009: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 454s 908ms/step - loss: 3.8056 - val_loss: 3.8965\n", + "\n", + "Epoch 00009: val_loss did not improve from 3.83686\n", + "Epoch 10/100\n", + "\n", + "Epoch 00010: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 457s 914ms/step - loss: 3.7874 - val_loss: 3.8854\n", + "\n", + "Epoch 00010: val_loss did not improve from 3.83686\n", + "Epoch 11/100\n", + "\n", + "Epoch 00011: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 458s 917ms/step - loss: 3.7937 - val_loss: 3.9264\n", + "\n", + "Epoch 00011: val_loss did not improve from 3.83686\n", + "Epoch 12/100\n", + "\n", + "Epoch 00012: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 456s 913ms/step - loss: 3.8105 - val_loss: 3.8769\n", + "\n", + "Epoch 00012: val_loss did not improve from 3.83686\n", + "Epoch 13/100\n", + "\n", + "Epoch 00013: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 460s 921ms/step - loss: 3.8102 - val_loss: 3.9104\n", + "\n", + "Epoch 00013: val_loss did not improve from 3.83686\n", + "Epoch 14/100\n", + "\n", + "Epoch 00014: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 456s 912ms/step - loss: 3.8034 - val_loss: 3.8571\n", + "\n", + "Epoch 00014: val_loss did not improve from 3.83686\n", + "Epoch 15/100\n", + "\n", + "Epoch 00015: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 458s 917ms/step - loss: 3.7412 - val_loss: 3.8471\n", + "\n", + "Epoch 00015: val_loss did not improve from 3.83686\n", + "Epoch 16/100\n", + "\n", + "Epoch 00016: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.7816 - val_loss: 3.8868\n", + "\n", + "Epoch 00016: val_loss did not improve from 3.83686\n", + "Epoch 17/100\n", + "\n", + "Epoch 00017: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.7849 - val_loss: 3.9379\n", + "\n", + "Epoch 00017: val_loss did not improve from 3.83686\n", + "Epoch 18/100\n", + "\n", + "Epoch 00018: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.7739 - val_loss: 3.8811\n", + "\n", + "Epoch 00018: val_loss did not improve from 3.83686\n", + "Epoch 19/100\n", + "\n", + "Epoch 00019: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.7704 - val_loss: 3.8714\n", + "\n", + "Epoch 00019: val_loss did not improve from 3.83686\n", + "Epoch 20/100\n", + "\n", + "Epoch 00020: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.7367 - val_loss: 3.9438\n", + "\n", + "Epoch 00020: val_loss did not improve from 3.83686\n", + "Epoch 21/100\n", + "\n", + "Epoch 00021: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.7554 - val_loss: 3.9248\n", + "\n", + "Epoch 00021: val_loss did not improve from 3.83686\n", + "Epoch 22/100\n", + "\n", + "Epoch 00022: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.7682 - val_loss: 3.9140\n", + "\n", + "Epoch 00022: val_loss did not improve from 3.83686\n", + "Epoch 23/100\n", + "\n", + "Epoch 00023: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.7867 - val_loss: 3.8202\n", + "\n", + "Epoch 00023: val_loss improved from 3.83686 to 3.82025, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 24/100\n", + "\n", + "Epoch 00024: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.7498 - val_loss: 3.8610\n", + "\n", + "Epoch 00024: val_loss did not improve from 3.82025\n", + "Epoch 25/100\n", + "\n", + "Epoch 00025: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.7391 - val_loss: 3.8886\n", + "\n", + "Epoch 00025: val_loss did not improve from 3.82025\n", + "Epoch 26/100\n", + "\n", + "Epoch 00026: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.7487 - val_loss: 3.8860\n", + "\n", + "Epoch 00026: val_loss did not improve from 3.82025\n", + "Epoch 27/100\n", + "\n", + "Epoch 00027: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.6680 - val_loss: 3.3866\n", + "\n", + "Epoch 00027: val_loss improved from 3.82025 to 3.38664, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 28/100\n", + "\n", + "Epoch 00028: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.6011 - val_loss: 3.3802\n", + "\n", + "Epoch 00028: val_loss improved from 3.38664 to 3.38020, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 29/100\n", + "\n", + "Epoch 00029: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.5266 - val_loss: 3.3741\n", + "\n", + "Epoch 00029: val_loss improved from 3.38020 to 3.37413, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 30/100\n", + "\n", + "Epoch 00030: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.5440 - val_loss: 3.3658\n", + "\n", + "Epoch 00030: val_loss improved from 3.37413 to 3.36583, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 31/100\n", + "\n", + "Epoch 00031: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.5227 - val_loss: 3.2712\n", + "\n", + "Epoch 00031: val_loss improved from 3.36583 to 3.27118, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 32/100\n", + "\n", + "Epoch 00032: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.5003 - val_loss: 3.2636\n", + "\n", + "Epoch 00032: val_loss improved from 3.27118 to 3.26357, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 33/100\n", + "\n", + "Epoch 00033: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.5573 - val_loss: 3.2981\n", + "\n", + "Epoch 00033: val_loss did not improve from 3.26357\n", + "Epoch 34/100\n", + "\n", + "Epoch 00034: LearningRateScheduler setting learning rate to 0.001.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "500/500 [==============================] - 451s 902ms/step - loss: 3.5104 - val_loss: 3.3216\n", + "\n", + "Epoch 00034: val_loss did not improve from 3.26357\n", + "Epoch 35/100\n", + "\n", + "Epoch 00035: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.4535 - val_loss: 3.2405\n", + "\n", + "Epoch 00035: val_loss improved from 3.26357 to 3.24054, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 36/100\n", + "\n", + "Epoch 00036: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.4667 - val_loss: 3.2127\n", + "\n", + "Epoch 00036: val_loss improved from 3.24054 to 3.21267, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 37/100\n", + "\n", + "Epoch 00037: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.4625 - val_loss: 3.2967\n", + "\n", + "Epoch 00037: val_loss did not improve from 3.21267\n", + "Epoch 38/100\n", + "\n", + "Epoch 00038: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.4349 - val_loss: 3.2318\n", + "\n", + "Epoch 00038: val_loss did not improve from 3.21267\n", + "Epoch 39/100\n", + "\n", + "Epoch 00039: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.4616 - val_loss: 3.2234\n", + "\n", + "Epoch 00039: val_loss did not improve from 3.21267\n", + "Epoch 40/100\n", + "\n", + "Epoch 00040: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.4579 - val_loss: 3.2443\n", + "\n", + "Epoch 00040: val_loss did not improve from 3.21267\n", + "Epoch 41/100\n", + "\n", + "Epoch 00041: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.4741 - val_loss: 3.1831\n", + "\n", + "Epoch 00041: val_loss improved from 3.21267 to 3.18308, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 42/100\n", + "\n", + "Epoch 00042: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.4098 - val_loss: 3.1778\n", + "\n", + "Epoch 00042: val_loss improved from 3.18308 to 3.17781, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 43/100\n", + "\n", + "Epoch 00043: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.4194 - val_loss: 3.3141\n", + "\n", + "Epoch 00043: val_loss did not improve from 3.17781\n", + "Epoch 44/100\n", + "\n", + "Epoch 00044: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.4294 - val_loss: 3.1888\n", + "\n", + "Epoch 00044: val_loss did not improve from 3.17781\n", + "Epoch 45/100\n", + "\n", + "Epoch 00045: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.4157 - val_loss: 3.2060\n", + "\n", + "Epoch 00045: val_loss did not improve from 3.17781\n", + "Epoch 46/100\n", + "\n", + "Epoch 00046: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.4147 - val_loss: 3.1829\n", + "\n", + "Epoch 00046: val_loss did not improve from 3.17781\n", + "Epoch 47/100\n", + "\n", + "Epoch 00047: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.4061 - val_loss: 3.2214\n", + "\n", + "Epoch 00047: val_loss did not improve from 3.17781\n", + "Epoch 48/100\n", + "\n", + "Epoch 00048: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.4013 - val_loss: 3.1010\n", + "\n", + "Epoch 00048: val_loss improved from 3.17781 to 3.10097, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 49/100\n", + "\n", + "Epoch 00049: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.4092 - val_loss: 3.1462\n", + "\n", + "Epoch 00049: val_loss did not improve from 3.10097\n", + "Epoch 50/100\n", + "\n", + "Epoch 00050: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3759 - val_loss: 3.1760\n", + "\n", + "Epoch 00050: val_loss did not improve from 3.10097\n", + "Epoch 51/100\n", + "\n", + "Epoch 00051: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.4261 - val_loss: 3.1638\n", + "\n", + "Epoch 00051: val_loss did not improve from 3.10097\n", + "Epoch 52/100\n", + "\n", + "Epoch 00052: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3900 - val_loss: 3.2724\n", + "\n", + "Epoch 00052: val_loss did not improve from 3.10097\n", + "Epoch 53/100\n", + "\n", + "Epoch 00053: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3771 - val_loss: 3.1456\n", + "\n", + "Epoch 00053: val_loss did not improve from 3.10097\n", + "Epoch 54/100\n", + "\n", + "Epoch 00054: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3997 - val_loss: 3.2297\n", + "\n", + "Epoch 00054: val_loss did not improve from 3.10097\n", + "Epoch 55/100\n", + "\n", + "Epoch 00055: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3632 - val_loss: 3.1960\n", + "\n", + "Epoch 00055: val_loss did not improve from 3.10097\n", + "Epoch 56/100\n", + "\n", + "Epoch 00056: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3829 - val_loss: 3.1371\n", + "\n", + "Epoch 00056: val_loss did not improve from 3.10097\n", + "Epoch 57/100\n", + "\n", + "Epoch 00057: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3724 - val_loss: 3.1169\n", + "\n", + "Epoch 00057: val_loss did not improve from 3.10097\n", + "Epoch 58/100\n", + "\n", + "Epoch 00058: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3625 - val_loss: 3.2694\n", + "\n", + "Epoch 00058: val_loss did not improve from 3.10097\n", + "Epoch 59/100\n", + "\n", + "Epoch 00059: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3691 - val_loss: 3.1037\n", + "\n", + "Epoch 00059: val_loss did not improve from 3.10097\n", + "Epoch 60/100\n", + "\n", + "Epoch 00060: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3976 - val_loss: 3.1110\n", + "\n", + "Epoch 00060: val_loss did not improve from 3.10097\n", + "Epoch 61/100\n", + "\n", + "Epoch 00061: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.3747 - val_loss: 3.1192\n", + "\n", + "Epoch 00061: val_loss did not improve from 3.10097\n", + "Epoch 62/100\n", + "\n", + "Epoch 00062: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 452s 903ms/step - loss: 3.3526 - val_loss: 3.1612\n", + "\n", + "Epoch 00062: val_loss did not improve from 3.10097\n", + "Epoch 63/100\n", + "\n", + "Epoch 00063: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 452s 903ms/step - loss: 3.4435 - val_loss: 3.1396\n", + "\n", + "Epoch 00063: val_loss did not improve from 3.10097\n", + "Epoch 64/100\n", + "\n", + "Epoch 00064: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 452s 903ms/step - loss: 3.3811 - val_loss: 3.1575\n", + "\n", + "Epoch 00064: val_loss did not improve from 3.10097\n", + "Epoch 65/100\n", + "\n", + "Epoch 00065: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3493 - val_loss: 3.2337\n", + "\n", + "Epoch 00065: val_loss did not improve from 3.10097\n", + "Epoch 66/100\n", + "\n", + "Epoch 00066: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 903ms/step - loss: 3.3510 - val_loss: 3.1230\n", + "\n", + "Epoch 00066: val_loss did not improve from 3.10097\n", + "Epoch 67/100\n", + "\n", + "Epoch 00067: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3569 - val_loss: 3.1419\n", + "\n", + "Epoch 00067: val_loss did not improve from 3.10097\n", + "Epoch 68/100\n", + "\n", + "Epoch 00068: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.3372 - val_loss: 3.0772\n", + "\n", + "Epoch 00068: val_loss improved from 3.10097 to 3.07717, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 69/100\n", + "\n", + "Epoch 00069: LearningRateScheduler setting learning rate to 0.001.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "500/500 [==============================] - 449s 898ms/step - loss: 3.3732 - val_loss: 3.1180\n", + "\n", + "Epoch 00069: val_loss did not improve from 3.07717\n", + "Epoch 70/100\n", + "\n", + "Epoch 00070: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.3438 - val_loss: 3.1318\n", + "\n", + "Epoch 00070: val_loss did not improve from 3.07717\n", + "Epoch 71/100\n", + "\n", + "Epoch 00071: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3451 - val_loss: 3.1492\n", + "\n", + "Epoch 00071: val_loss did not improve from 3.07717\n", + "Epoch 72/100\n", + "\n", + "Epoch 00072: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.3055 - val_loss: 3.1092\n", + "\n", + "Epoch 00072: val_loss did not improve from 3.07717\n", + "Epoch 73/100\n", + "\n", + "Epoch 00073: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3299 - val_loss: 3.2583\n", + "\n", + "Epoch 00073: val_loss did not improve from 3.07717\n", + "Epoch 74/100\n", + "\n", + "Epoch 00074: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3542 - val_loss: 3.1427\n", + "\n", + "Epoch 00074: val_loss did not improve from 3.07717\n", + "Epoch 75/100\n", + "\n", + "Epoch 00075: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3353 - val_loss: 3.1750\n", + "\n", + "Epoch 00075: val_loss did not improve from 3.07717\n", + "Epoch 76/100\n", + "\n", + "Epoch 00076: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3239 - val_loss: 3.1659\n", + "\n", + "Epoch 00076: val_loss did not improve from 3.07717\n", + "Epoch 77/100\n", + "\n", + "Epoch 00077: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3305 - val_loss: 3.0835\n", + "\n", + "Epoch 00077: val_loss did not improve from 3.07717\n", + "Epoch 78/100\n", + "\n", + "Epoch 00078: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.3211 - val_loss: 3.1030\n", + "\n", + "Epoch 00078: val_loss did not improve from 3.07717\n", + "Epoch 79/100\n", + "\n", + "Epoch 00079: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3223 - val_loss: 3.1195\n", + "\n", + "Epoch 00079: val_loss did not improve from 3.07717\n", + "Epoch 80/100\n", + "\n", + "Epoch 00080: LearningRateScheduler setting learning rate to 0.001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.3430 - val_loss: 3.2754\n", + "\n", + "Epoch 00080: val_loss did not improve from 3.07717\n", + "Epoch 81/100\n", + "\n", + "Epoch 00081: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.1907 - val_loss: 2.9731\n", + "\n", + "Epoch 00081: val_loss improved from 3.07717 to 2.97306, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 82/100\n", + "\n", + "Epoch 00082: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.1456 - val_loss: 2.9711\n", + "\n", + "Epoch 00082: val_loss improved from 2.97306 to 2.97114, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 83/100\n", + "\n", + "Epoch 00083: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.1248 - val_loss: 2.9670\n", + "\n", + "Epoch 00083: val_loss improved from 2.97114 to 2.96699, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 84/100\n", + "\n", + "Epoch 00084: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.1167 - val_loss: 2.9557\n", + "\n", + "Epoch 00084: val_loss improved from 2.96699 to 2.95567, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 85/100\n", + "\n", + "Epoch 00085: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.1287 - val_loss: 2.9472\n", + "\n", + "Epoch 00085: val_loss improved from 2.95567 to 2.94721, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 86/100\n", + "\n", + "Epoch 00086: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.1195 - val_loss: 2.9572\n", + "\n", + "Epoch 00086: val_loss did not improve from 2.94721\n", + "Epoch 87/100\n", + "\n", + "Epoch 00087: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.0942 - val_loss: 2.9739\n", + "\n", + "Epoch 00087: val_loss did not improve from 2.94721\n", + "Epoch 88/100\n", + "\n", + "Epoch 00088: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.0693 - val_loss: 2.9428\n", + "\n", + "Epoch 00088: val_loss improved from 2.94721 to 2.94277, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 89/100\n", + "\n", + "Epoch 00089: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.0901 - val_loss: 2.9392\n", + "\n", + "Epoch 00089: val_loss improved from 2.94277 to 2.93917, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 90/100\n", + "\n", + "Epoch 00090: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.0916 - val_loss: 2.9386\n", + "\n", + "Epoch 00090: val_loss improved from 2.93917 to 2.93864, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 91/100\n", + "\n", + "Epoch 00091: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.0853 - val_loss: 2.9484\n", + "\n", + "Epoch 00091: val_loss did not improve from 2.93864\n", + "Epoch 92/100\n", + "\n", + "Epoch 00092: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.0696 - val_loss: 2.9277\n", + "\n", + "Epoch 00092: val_loss improved from 2.93864 to 2.92770, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 93/100\n", + "\n", + "Epoch 00093: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 901ms/step - loss: 3.0827 - val_loss: 2.9312\n", + "\n", + "Epoch 00093: val_loss did not improve from 2.92770\n", + "Epoch 94/100\n", + "\n", + "Epoch 00094: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.0772 - val_loss: 2.9390\n", + "\n", + "Epoch 00094: val_loss did not improve from 2.92770\n", + "Epoch 95/100\n", + "\n", + "Epoch 00095: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.0609 - val_loss: 2.9373\n", + "\n", + "Epoch 00095: val_loss did not improve from 2.92770\n", + "Epoch 96/100\n", + "\n", + "Epoch 00096: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.0587 - val_loss: 2.9377\n", + "\n", + "Epoch 00096: val_loss did not improve from 2.92770\n", + "Epoch 97/100\n", + "\n", + "Epoch 00097: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.0529 - val_loss: 2.9221\n", + "\n", + "Epoch 00097: val_loss improved from 2.92770 to 2.92209, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 98/100\n", + "\n", + "Epoch 00098: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.0698 - val_loss: 2.9095\n", + "\n", + "Epoch 00098: val_loss improved from 2.92209 to 2.90946, saving model to experimento_ssd300_fault_1.h5\n", + "Epoch 99/100\n", + "\n", + "Epoch 00099: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 450s 901ms/step - loss: 3.0672 - val_loss: 2.9138\n", + "\n", + "Epoch 00099: val_loss did not improve from 2.90946\n", + "Epoch 100/100\n", + "\n", + "Epoch 00100: LearningRateScheduler setting learning rate to 0.0001.\n", + "500/500 [==============================] - 451s 902ms/step - loss: 3.0530 - val_loss: 2.9209\n", + "\n", + "Epoch 00100: val_loss did not improve from 2.90946\n" + ] + } + ], + "source": [ + "#ENTRENAMIENTO DE MODELO\n", + "#####################################################################\n", + "# Instantiate two `DataGenerator` objects: One for training, one for validation.\n", + "######################################################################\n", + "# Optional: If you have enough memory, consider loading the images into memory for the reasons explained above.\n", + "\n", + "train_dataset = DataGenerator(load_images_into_memory=False, hdf5_dataset_path=None)\n", + "val_dataset = DataGenerator(load_images_into_memory=False, hdf5_dataset_path=None)\n", + "\n", + "# 2: Parse the image and label lists for the training and validation datasets. This can take a while.\n", + "\n", + "\n", + "\n", + "# The XML parser needs to now what object class names to look for and in which order to map them to integers.\n", + "classes = ['background' ] + labels\n", + "\n", + "train_dataset.parse_xml(images_dirs= [config['train']['train_image_folder']],\n", + " image_set_filenames=[config['train']['train_image_set_filename']],\n", + " annotations_dirs=[config['train']['train_annot_folder']],\n", + " #classes=classes,\n", + " #include_classes='all',\n", + " classes = classes, \n", + " include_classes= [1],\n", + " exclude_truncated=False,\n", + " exclude_difficult=False,\n", + " ret=False)\n", + "\n", + "val_dataset.parse_xml(images_dirs= [config['test']['test_image_folder']],\n", + " image_set_filenames=[config['test']['test_image_set_filename']],\n", + " annotations_dirs=[config['test']['test_annot_folder']],\n", + " #classes=classes,\n", + " #include_classes='all',\n", + " classes = classes, \n", + " include_classes=[1],\n", + " exclude_truncated=False,\n", + " exclude_difficult=False,\n", + " ret=False)\n", + "\n", + "#########################\n", + "# 3: Set the batch size.\n", + "#########################\n", + "batch_size = config['train']['batch_size'] # Change the batch size if you like, or if you run into GPU memory issues.\n", + "\n", + "##########################\n", + "# 4: Set the image transformations for pre-processing and data augmentation options.\n", + "##########################\n", + "# For the training generator:\n", + "\n", + "\n", + "# For the validation generator:\n", + "convert_to_3_channels = ConvertTo3Channels()\n", + "resize = Resize(height=img_height, width=img_width)\n", + "\n", + "######################################3\n", + "# 5: Instantiate an encoder that can encode ground truth labels into the format needed by the SSD loss function.\n", + "#########################################\n", + "# The encoder constructor needs the spatial dimensions of the model's predictor layers to create the anchor boxes.\n", + "if config['model']['backend'] == 'ssd300':\n", + " predictor_sizes = [model.get_layer('conv4_3_norm_mbox_conf').output_shape[1:3],\n", + " model.get_layer('fc7_mbox_conf').output_shape[1:3],\n", + " model.get_layer('conv6_2_mbox_conf').output_shape[1:3],\n", + " model.get_layer('conv7_2_mbox_conf').output_shape[1:3],\n", + " model.get_layer('conv8_2_mbox_conf').output_shape[1:3],\n", + " model.get_layer('conv9_2_mbox_conf').output_shape[1:3]]\n", + " ssd_input_encoder = SSDInputEncoder(img_height=img_height,\n", + " img_width=img_width,\n", + " n_classes=n_classes,\n", + " predictor_sizes=predictor_sizes,\n", + " scales=scales,\n", + " aspect_ratios_per_layer=aspect_ratios,\n", + " two_boxes_for_ar1=two_boxes_for_ar1,\n", + " steps=steps,\n", + " offsets=offsets,\n", + " clip_boxes=clip_boxes,\n", + " variances=variances,\n", + " matching_type='multi',\n", + " pos_iou_threshold=0.5,\n", + " neg_iou_limit=0.5,\n", + " normalize_coords=normalize_coords)\n", + "\n", + "elif config['model']['backend'] == 'ssd7':\n", + " predictor_sizes = [model.get_layer('classes4').output_shape[1:3],\n", + " model.get_layer('classes5').output_shape[1:3],\n", + " model.get_layer('classes6').output_shape[1:3],\n", + " model.get_layer('classes7').output_shape[1:3]]\n", + " ssd_input_encoder = SSDInputEncoder(img_height=img_height,\n", + " img_width=img_width,\n", + " n_classes=n_classes,\n", + " predictor_sizes=predictor_sizes,\n", + " scales=scales,\n", + " aspect_ratios_global=aspect_ratios,\n", + " two_boxes_for_ar1=two_boxes_for_ar1,\n", + " steps=steps,\n", + " offsets=offsets,\n", + " clip_boxes=clip_boxes,\n", + " variances=variances,\n", + " matching_type='multi',\n", + " pos_iou_threshold=0.5,\n", + " neg_iou_limit=0.3,\n", + " normalize_coords=normalize_coords)\n", + "\n", + "\n", + "\n", + " \n", + "data_augmentation_chain = DataAugmentationVariableInputSize(resize_height = img_height,\n", + " resize_width = img_width,\n", + " random_brightness=(-48, 48, 0.5),\n", + " random_contrast=(0.5, 1.8, 0.5),\n", + " random_saturation=(0.5, 1.8, 0.5),\n", + " random_hue=(18, 0.5),\n", + " random_flip=0.5,\n", + " n_trials_max=3,\n", + " clip_boxes=True,\n", + " overlap_criterion='area',\n", + " bounds_box_filter=(0.3, 1.0),\n", + " bounds_validator=(0.5, 1.0),\n", + " n_boxes_min=1,\n", + " background=(0,0,0))\n", + "#######################\n", + "# 6: Create the generator handles that will be passed to Keras' `fit_generator()` function.\n", + "#######################\n", + "\n", + "train_generator = train_dataset.generate(batch_size=batch_size,\n", + " shuffle=True,\n", + " transformations= [data_augmentation_chain],\n", + " label_encoder=ssd_input_encoder,\n", + " returns={'processed_images',\n", + " 'encoded_labels'},\n", + " keep_images_without_gt=False)\n", + "\n", + "val_generator = val_dataset.generate(batch_size=batch_size,\n", + " shuffle=False,\n", + " transformations=[convert_to_3_channels,\n", + " resize],\n", + " label_encoder=ssd_input_encoder,\n", + " returns={'processed_images',\n", + " 'encoded_labels'},\n", + " keep_images_without_gt=False)\n", + "\n", + "# Summary instance training\n", + "category_train_list = []\n", + "for image_label in train_dataset.labels:\n", + " category_train_list += [i[0] for i in image_label]\n", + "summary_category_training = {train_dataset.classes[i]: category_train_list.count(i) for i in list(set(category_train_list))}\n", + "for i in summary_category_training.keys():\n", + " print(i, ': {:.0f}'.format(summary_category_training[i]))\n", + "\n", + "\n", + "\n", + "# Get the number of samples in the training and validations datasets.\n", + "train_dataset_size = train_dataset.get_dataset_size()\n", + "val_dataset_size = val_dataset.get_dataset_size()\n", + "\n", + "print(\"Number of images in the training dataset:\\t{:>6}\".format(train_dataset_size))\n", + "print(\"Number of images in the validation dataset:\\t{:>6}\".format(val_dataset_size))\n", + "\n", + "\n", + "\n", + "##########################\n", + "# Define model callbacks.\n", + "#########################\n", + "\n", + "# TODO: Set the filepath under which you want to save the model.\n", + "model_checkpoint = ModelCheckpoint(filepath= config['train']['saved_weights_name'],\n", + " monitor='val_loss',\n", + " verbose=1,\n", + " save_best_only=True,\n", + " save_weights_only=False,\n", + " mode='auto',\n", + " period=1)\n", + "#model_checkpoint.best =\n", + "\n", + "csv_logger = CSVLogger(filename='log.csv',\n", + " separator=',',\n", + " append=True)\n", + "\n", + "learning_rate_scheduler = LearningRateScheduler(schedule=lr_schedule,\n", + " verbose=1)\n", + "\n", + "terminate_on_nan = TerminateOnNaN()\n", + "\n", + "callbacks = [model_checkpoint,\n", + " csv_logger,\n", + " learning_rate_scheduler,\n", + " terminate_on_nan]\n", + "\n", + "\n", + "\n", + "batch_images, batch_labels = next(train_generator)\n", + "\n", + "\n", + "initial_epoch = 0\n", + "final_epoch = 100 #config['train']['nb_epochs']\n", + "steps_per_epoch = 500\n", + "\n", + "history = model.fit_generator(generator=train_generator,\n", + " steps_per_epoch=steps_per_epoch,\n", + " epochs=final_epoch,\n", + " callbacks=callbacks,\n", + " validation_data=val_generator,\n", + " validation_steps=ceil(val_dataset_size/batch_size*10),\n", + " initial_epoch=initial_epoch,\n", + " verbose = 1 if config['train']['debug'] else 2)\n", + "\n", + "history_path = config['train']['saved_weights_name'].split('.')[0] + '_history'\n", + "\n", + "np.save(history_path, history.history)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "classes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_keys(['val_loss', 'loss', 'lr'])\n" + ] + }, + { + "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51zzc65NHAP8GaKf1/vsK99e0SPb8UcBIEYyiLfNn4rsMI5981+H90PfDj//MPAfUNdtsHinLvOOdfgnBuP36+POueuBB4DLs1PVlTbDOCc2ww0mtmU/FvnAMsp4n2NbxI6w8wS+b/1Hdtc1Pu6n33t2/uBD+XPHjoDaN/RhHRInHNF+wAuAF4B1gD/VujyDNI2vgVfJXwBWJp/XIBvM38EWJX/t6bQZR2k7Z8N/D7/fCKwEFgN/AaIFbp8g7C9M4BF+f39W2BYse9r4GvASmAZ8HMgVoz7GrgL3w+Sxv/i//i+9i2+aeh7+WPbi/izqg553RpiQkQk4Iq5aUhERAZAQSAiEnAKAhGRgFMQiIgEnIJARCTgFAQig8zMZu8YIVXkjUhBICIScAoCkTwzu8rMFprZUjP7Yf5+B11m9r9mtsTMHjGzuvy0M8zsmfxY8Pf2Gyd+kpktMLPn8/Mcm198eb/7CNyZv0pW5A1BQSACmNnxwOXAWc65GUAWuBI/yNkS59wpwBPAV/Oz/Az4knNuOv7Kzh3v3wl8zzl3Mn5MnB2X/c8EPoe/N8ZE/HhJIm8IkQNPIhII5wCnAn/L/1gvxQ/wlQN+lZ/mDuAeM6sCqp1zT+Tfvx34jZlVAGOcc/cCOOf6APLLW+ica8q/XgqMB/4y+JslcmAKAhHPgNudc9ft8qbZl3ebbn9jsuyvuSfZ73kW/d+TNxA1DYl4jwCXmlk97LxX7DH4/yM7Rrn8IPAX51w70Gpmb82/fzXwhPP3gWgys/fklxEzs8SQboXIIdCvEhHAObfczP4deMjMQvgRID+Nv/nLiWa2GH93rMvzs3wY+EH+QL8W+Gj+/auBH5rZf+SX8f4h3AyRQ6LRR0X2w8y6nHPlhS6HyGBS05CISMCpRiAiEnCqEYiIBJyCQEQk4BQEIiIBpyAQEQk4BYGISMD9f1XwMI4bD5NVAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "experimento_ssd300_fault_1.h5\n" + ] + } + ], + "source": [ + "#Graficar aprendizaje\n", + "\n", + "history_path =config['train']['saved_weights_name'].split('.')[0] + '_history'\n", + "\n", + "hist_load = np.load(history_path + '.npy',allow_pickle=True).item()\n", + "\n", + "print(hist_load.keys())\n", + "\n", + "# summarize history for loss\n", + "plt.plot(hist_load['loss'])\n", + "plt.plot(hist_load['val_loss'])\n", + "plt.title('model loss')\n", + "plt.ylabel('loss')\n", + "plt.xlabel('epoch')\n", + "plt.legend(['train', 'test'], loc='upper left')\n", + "plt.ylim((0, 10)) \n", + "plt.show()\n", + "\n", + "print(config['train']['saved_weights_name'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Evaluación del Modelo" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'json' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconfig_path\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mconfig_buffer\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mconfig\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconfig_buffer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'json' is not defined" + ] + } + ], + "source": [ + "\n", + "config_path = 'config_300_fault_1.json'\n", + "\n", + "with open(config_path) as config_buffer:\n", + " config = json.loads(config_buffer.read())\n", + "\n", + " \n", + "model_mode = 'training'\n", + "# TODO: Set the path to the `.h5` file of the model to be loaded.\n", + "model_path = config['train']['saved_weights_name']\n", + "\n", + "# We need to create an SSDLoss object in order to pass that to the model loader.\n", + "ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)\n", + "\n", + "K.clear_session() # Clear previous models from memory.\n", + "\n", + "model = load_model(model_path, custom_objects={'AnchorBoxes': AnchorBoxes,\n", + " 'L2Normalization': L2Normalization,\n", + " 'DecodeDetections': DecodeDetections,\n", + " 'compute_loss': ssd_loss.compute_loss})\n", + "\n", + "\n", + " \n", + "train_dataset = DataGenerator(load_images_into_memory=False, hdf5_dataset_path=None)\n", + "val_dataset = DataGenerator(load_images_into_memory=False, hdf5_dataset_path=None)\n", + "\n", + "# 2: Parse the image and label lists for the training and validation datasets. This can take a while.\n", + "\n", + "\n", + "\n", + "# The XML parser needs to now what object class names to look for and in which order to map them to integers.\n", + "classes = ['background' ] + labels\n", + "\n", + "train_dataset.parse_xml(images_dirs= [config['train']['train_image_folder']],\n", + " image_set_filenames=[config['train']['train_image_set_filename']],\n", + " annotations_dirs=[config['train']['train_annot_folder']],\n", + " classes=classes,\n", + " include_classes='all',\n", + " #classes = ['background', 'panel', 'cell'], \n", + " #include_classes=classes,\n", + " exclude_truncated=False,\n", + " exclude_difficult=False,\n", + " ret=False)\n", + "\n", + "val_dataset.parse_xml(images_dirs= [config['test']['test_image_folder']],\n", + " image_set_filenames=[config['test']['test_image_set_filename']],\n", + " annotations_dirs=[config['test']['test_annot_folder']],\n", + " classes=classes,\n", + " include_classes='all',\n", + " #classes = ['background', 'panel', 'cell'], \n", + " #include_classes=classes,\n", + " exclude_truncated=False,\n", + " exclude_difficult=False,\n", + " ret=False)\n", + "\n", + "#########################\n", + "# 3: Set the batch size.\n", + "#########################\n", + "batch_size = config['train']['batch_size'] # Change the batch size if you like, or if you run into GPU memory issues.\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "evaluator = Evaluator(model=model,\n", + " n_classes=n_classes,\n", + " data_generator=val_dataset,\n", + " model_mode='training')\n", + "\n", + "results = evaluator(img_height=img_height,\n", + " img_width=img_width,\n", + " batch_size=4,\n", + " data_generator_mode='resize',\n", + " round_confidences=False,\n", + " matching_iou_threshold=0.5,\n", + " border_pixels='include',\n", + " sorting_algorithm='quicksort',\n", + " average_precision_mode='sample',\n", + " num_recall_points=11,\n", + " ignore_neutral_boxes=True,\n", + " return_precisions=True,\n", + " return_recalls=True,\n", + " return_average_precisions=True,\n", + " verbose=True)\n", + "\n", + "mean_average_precision, average_precisions, precisions, recalls = results\n", + "total_instances = []\n", + "precisions = []\n", + "\n", + "for i in range(1, len(average_precisions)):\n", + " \n", + " print('{:.0f} instances of class'.format(len(recalls[i])),\n", + " classes[i], 'with average precision: {:.4f}'.format(average_precisions[i]))\n", + " total_instances.append(len(recalls[i]))\n", + " precisions.append(average_precisions[i])\n", + "\n", + "if sum(total_instances) == 0:\n", + " \n", + " print('No test instances found.')\n", + "\n", + "else:\n", + "\n", + " print('mAP using the weighted average of precisions among classes: {:.4f}'.format(sum([a * b for a, b in zip(total_instances, precisions)]) / sum(total_instances)))\n", + " print('mAP: {:.4f}'.format(sum(precisions) / sum(x > 0 for x in total_instances)))\n", + "\n", + " for i in range(1, len(average_precisions)):\n", + " print(\"{:<14}{:<6}{}\".format(classes[i], 'AP', round(average_precisions[i], 3)))\n", + " print()\n", + " print(\"{:<14}{:<6}{}\".format('','mAP', round(mean_average_precision, 3)))" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ceil(val_dataset_size/batch_size)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Cargar nuevamente el modelo desde los pesos.\n", + "Predicción" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Training on: \t{'1': 1}\n", + "\n" + ] + } + ], + "source": [ + "from imageio import imread\n", + "from keras.preprocessing import image\n", + "import time\n", + "\n", + "config_path = 'config_300_fault_1.json'\n", + "input_path = ['fault_jpg_1/']\n", + "output_path = 'result_ssd300_fault_1/'\n", + "\n", + "with open(config_path) as config_buffer:\n", + " config = json.loads(config_buffer.read())\n", + "\n", + "makedirs(output_path)\n", + "###############################\n", + "# Parse the annotations\n", + "###############################\n", + "score_threshold = 0.25\n", + "score_threshold_iou = 0.5\n", + "labels = config['model']['labels']\n", + "categories = {}\n", + "#categories = {\"Razor\": 1, \"Gun\": 2, \"Knife\": 3, \"Shuriken\": 4} #la categoría 0 es la background\n", + "for i in range(len(labels)): categories[labels[i]] = i+1\n", + "print('\\nTraining on: \\t' + str(categories) + '\\n')\n", + "\n", + "img_height = config['model']['input'] # Height of the model input images\n", + "img_width = config['model']['input'] # Width of the model input images\n", + "img_channels = 3 # Number of color channels of the model input images\n", + "n_classes = len(labels) # Number of positive classes, e.g. 20 for Pascal VOC, 80 for MS COCO\n", + "classes = ['background'] + labels\n", + "\n", + "model_mode = 'training'\n", + "# TODO: Set the path to the `.h5` file of the model to be loaded.\n", + "model_path = config['train']['saved_weights_name']\n", + "\n", + "# We need to create an SSDLoss object in order to pass that to the model loader.\n", + "ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)\n", + "\n", + "K.clear_session() # Clear previous models from memory.\n", + "\n", + "model = load_model(model_path, custom_objects={'AnchorBoxes': AnchorBoxes,\n", + " 'L2Normalization': L2Normalization,\n", + " 'DecodeDetections': DecodeDetections,\n", + " 'compute_loss': ssd_loss.compute_loss})\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tiempo Total: 27.768\n", + "Tiempo promedio por imagen: 1.111\n", + "OK\n" + ] + } + ], + "source": [ + "image_paths = []\n", + "for inp in input_path:\n", + " if os.path.isdir(inp):\n", + " for inp_file in os.listdir(inp):\n", + " image_paths += [inp + inp_file]\n", + " else:\n", + " image_paths += [inp]\n", + "\n", + "image_paths = [inp_file for inp_file in image_paths if (inp_file[-4:] in ['.jpg', '.png', 'JPEG'])]\n", + "times = []\n", + "\n", + "\n", + "for img_path in image_paths:\n", + " orig_images = [] # Store the images here.\n", + " input_images = [] # Store resized versions of the images here.\n", + " #print(img_path)\n", + "\n", + " # preprocess image for network\n", + " orig_images.append(imread(img_path))\n", + " img = image.load_img(img_path, target_size=(img_height, img_width))\n", + " img = image.img_to_array(img)\n", + " input_images.append(img)\n", + " input_images = np.array(input_images)\n", + " # process image\n", + " start = time.time()\n", + " y_pred = model.predict(input_images)\n", + " y_pred_decoded = decode_detections(y_pred,\n", + " confidence_thresh=score_threshold,\n", + " iou_threshold=score_threshold_iou,\n", + " top_k=200,\n", + " normalize_coords=True,\n", + " img_height=img_height,\n", + " img_width=img_width)\n", + "\n", + "\n", + " #print(\"processing time: \", time.time() - start)\n", + " times.append(time.time() - start)\n", + " # correct for image scale\n", + "\n", + " # visualize detections\n", + " # Set the colors for the bounding boxes\n", + " colors = plt.cm.brg(np.linspace(0, 1, 21)).tolist()\n", + "\n", + " plt.figure(figsize=(20,12))\n", + " plt.imshow(orig_images[0],cmap = 'gray')\n", + "\n", + " current_axis = plt.gca()\n", + " #print(y_pred)\n", + " for box in y_pred_decoded[0]:\n", + " # Transform the predicted bounding boxes for the 300x300 image to the original image dimensions.\n", + "\n", + " xmin = box[2] * orig_images[0].shape[1] / img_width\n", + " ymin = box[3] * orig_images[0].shape[0] / img_height\n", + " xmax = box[4] * orig_images[0].shape[1] / img_width\n", + " ymax = box[5] * orig_images[0].shape[0] / img_height\n", + "\n", + " color = colors[int(box[0])]\n", + " label = '{}: {:.2f}'.format(classes[int(box[0])], box[1])\n", + " current_axis.add_patch(plt.Rectangle((xmin, ymin), xmax-xmin, ymax-ymin, color=color, fill=False, linewidth=2))\n", + " current_axis.text(xmin, ymin, label, size='x-large', color='white', bbox={'facecolor':color, 'alpha':1.0})\n", + "\n", + " #plt.figure(figsize=(15, 15))\n", + " #plt.axis('off')\n", + " save_path = output_path + img_path.split('/')[-1]\n", + " plt.savefig(save_path)\n", + " plt.close()\n", + " \n", + "file = open(output_path + 'time.txt','w')\n", + "\n", + "file.write('Tiempo promedio:' + str(np.mean(times)))\n", + "\n", + "file.close()\n", + "print('Tiempo Total: {:.3f}'.format(np.sum(times)))\n", + "print('Tiempo promedio por imagen: {:.3f}'.format(np.mean(times)))\n", + "print('OK')" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "panel : 69\n", + "cell : 423\n" + ] + } + ], + "source": [ + "\n", + "# Summary instance training\n", + "category_train_list = []\n", + "for image_label in train_dataset.labels:\n", + " category_train_list += [i[0] for i in train_dataset.labels[0]]\n", + "summary_category_training = {train_dataset.classes[i]: category_train_list.count(i) for i in list(set(category_train_list))}\n", + "for i in summary_category_training.keys():\n", + " print(i, ': {:.0f}'.format(summary_category_training[i]))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 : 6030\n" + ] + } + ], + "source": [ + "for i in summary_category_training.keys():\n", + " print(i, ': {:.0f}'.format(summary_category_training[i]))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Panel_Detector_Fault_C.ipynb b/Panel_Detector_Fault_C.ipynb new file mode 100644 index 0000000..3d1a448 --- /dev/null +++ b/Panel_Detector_Fault_C.ipynb @@ -0,0 +1,1297 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Cargar el modelo ssd7 \n", + "(https://github.com/pierluigiferrari/ssd_keras#how-to-fine-tune-one-of-the-trained-models-on-your-own-dataset)\n", + "\n", + "Training del SSD7 (modelo reducido de SSD). Parámetros en config_7.json y descargar VGG_ILSVRC_16_layers_fc_reduced.h5\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Using TensorFlow backend.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Training on: \t{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8}\n", + "\n", + "WARNING:tensorflow:From /home/dl-desktop/anaconda3/envs/tf_gpu/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Colocations handled automatically by placer.\n", + "OK create model\n", + "\n", + "Loading pretrained weights VGG.\n", + "\n", + "WARNING:tensorflow:From /home/dl-desktop/Desktop/Rentadrone/ssd_keras-master/keras_loss_function/keras_ssd_loss.py:133: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Use tf.cast instead.\n", + "WARNING:tensorflow:From /home/dl-desktop/Desktop/Rentadrone/ssd_keras-master/keras_loss_function/keras_ssd_loss.py:166: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Use tf.cast instead.\n", + "__________________________________________________________________________________________________\n", + "Layer (type) Output Shape Param # Connected to \n", + "==================================================================================================\n", + "input_1 (InputLayer) (None, 400, 400, 3) 0 \n", + "__________________________________________________________________________________________________\n", + "identity_layer (Lambda) (None, 400, 400, 3) 0 input_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "input_mean_normalization (Lambd (None, 400, 400, 3) 0 identity_layer[0][0] \n", + "__________________________________________________________________________________________________\n", + "input_channel_swap (Lambda) (None, 400, 400, 3) 0 input_mean_normalization[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv1_1 (Conv2D) (None, 400, 400, 64) 1792 input_channel_swap[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv1_2 (Conv2D) (None, 400, 400, 64) 36928 conv1_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "pool1 (MaxPooling2D) (None, 200, 200, 64) 0 conv1_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv2_1 (Conv2D) (None, 200, 200, 128 73856 pool1[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv2_2 (Conv2D) (None, 200, 200, 128 147584 conv2_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "pool2 (MaxPooling2D) (None, 100, 100, 128 0 conv2_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv3_1 (Conv2D) (None, 100, 100, 256 295168 pool2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv3_2 (Conv2D) (None, 100, 100, 256 590080 conv3_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv3_3 (Conv2D) (None, 100, 100, 256 590080 conv3_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "pool3 (MaxPooling2D) (None, 50, 50, 256) 0 conv3_3[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_1 (Conv2D) (None, 50, 50, 512) 1180160 pool3[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_2 (Conv2D) (None, 50, 50, 512) 2359808 conv4_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_3 (Conv2D) (None, 50, 50, 512) 2359808 conv4_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "pool4 (MaxPooling2D) (None, 25, 25, 512) 0 conv4_3[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv5_1 (Conv2D) (None, 25, 25, 512) 2359808 pool4[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv5_2 (Conv2D) (None, 25, 25, 512) 2359808 conv5_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv5_3 (Conv2D) (None, 25, 25, 512) 2359808 conv5_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "pool5 (MaxPooling2D) (None, 25, 25, 512) 0 conv5_3[0][0] \n", + "__________________________________________________________________________________________________\n", + "fc6 (Conv2D) (None, 25, 25, 1024) 4719616 pool5[0][0] \n", + "__________________________________________________________________________________________________\n", + "fc7 (Conv2D) (None, 25, 25, 1024) 1049600 fc6[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv6_1 (Conv2D) (None, 25, 25, 256) 262400 fc7[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv6_padding (ZeroPadding2D) (None, 27, 27, 256) 0 conv6_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv6_2 (Conv2D) (None, 13, 13, 512) 1180160 conv6_padding[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv7_1 (Conv2D) (None, 13, 13, 128) 65664 conv6_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv7_padding (ZeroPadding2D) (None, 15, 15, 128) 0 conv7_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv7_2 (Conv2D) (None, 7, 7, 256) 295168 conv7_padding[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv8_1 (Conv2D) (None, 7, 7, 128) 32896 conv7_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv8_2 (Conv2D) (None, 5, 5, 256) 295168 conv8_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv9_1 (Conv2D) (None, 5, 5, 128) 32896 conv8_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_3_norm (L2Normalization) (None, 50, 50, 512) 512 conv4_3[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv9_2 (Conv2D) (None, 3, 3, 256) 295168 conv9_1[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_3_norm_mbox_conf (Conv2D) (None, 50, 50, 36) 165924 conv4_3_norm[0][0] \n", + "__________________________________________________________________________________________________\n", + "fc7_mbox_conf (Conv2D) (None, 25, 25, 54) 497718 fc7[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv6_2_mbox_conf (Conv2D) (None, 13, 13, 54) 248886 conv6_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv7_2_mbox_conf (Conv2D) (None, 7, 7, 54) 124470 conv7_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv8_2_mbox_conf (Conv2D) (None, 5, 5, 36) 82980 conv8_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv9_2_mbox_conf (Conv2D) (None, 3, 3, 36) 82980 conv9_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_3_norm_mbox_loc (Conv2D) (None, 50, 50, 16) 73744 conv4_3_norm[0][0] \n", + "__________________________________________________________________________________________________\n", + "fc7_mbox_loc (Conv2D) (None, 25, 25, 24) 221208 fc7[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv6_2_mbox_loc (Conv2D) (None, 13, 13, 24) 110616 conv6_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv7_2_mbox_loc (Conv2D) (None, 7, 7, 24) 55320 conv7_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv8_2_mbox_loc (Conv2D) (None, 5, 5, 16) 36880 conv8_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv9_2_mbox_loc (Conv2D) (None, 3, 3, 16) 36880 conv9_2[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_3_norm_mbox_conf_reshape (None, 10000, 9) 0 conv4_3_norm_mbox_conf[0][0] \n", + "__________________________________________________________________________________________________\n", + "fc7_mbox_conf_reshape (Reshape) (None, 3750, 9) 0 fc7_mbox_conf[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv6_2_mbox_conf_reshape (Resh (None, 1014, 9) 0 conv6_2_mbox_conf[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv7_2_mbox_conf_reshape (Resh (None, 294, 9) 0 conv7_2_mbox_conf[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv8_2_mbox_conf_reshape (Resh (None, 100, 9) 0 conv8_2_mbox_conf[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv9_2_mbox_conf_reshape (Resh (None, 36, 9) 0 conv9_2_mbox_conf[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_3_norm_mbox_priorbox (Anc (None, 50, 50, 4, 8) 0 conv4_3_norm_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "fc7_mbox_priorbox (AnchorBoxes) (None, 25, 25, 6, 8) 0 fc7_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv6_2_mbox_priorbox (AnchorBo (None, 13, 13, 6, 8) 0 conv6_2_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv7_2_mbox_priorbox (AnchorBo (None, 7, 7, 6, 8) 0 conv7_2_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv8_2_mbox_priorbox (AnchorBo (None, 5, 5, 4, 8) 0 conv8_2_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv9_2_mbox_priorbox (AnchorBo (None, 3, 3, 4, 8) 0 conv9_2_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "mbox_conf (Concatenate) (None, 15194, 9) 0 conv4_3_norm_mbox_conf_reshape[0]\n", + " fc7_mbox_conf_reshape[0][0] \n", + " conv6_2_mbox_conf_reshape[0][0] \n", + " conv7_2_mbox_conf_reshape[0][0] \n", + " conv8_2_mbox_conf_reshape[0][0] \n", + " conv9_2_mbox_conf_reshape[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_3_norm_mbox_loc_reshape ( (None, 10000, 4) 0 conv4_3_norm_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "fc7_mbox_loc_reshape (Reshape) (None, 3750, 4) 0 fc7_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv6_2_mbox_loc_reshape (Resha (None, 1014, 4) 0 conv6_2_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv7_2_mbox_loc_reshape (Resha (None, 294, 4) 0 conv7_2_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv8_2_mbox_loc_reshape (Resha (None, 100, 4) 0 conv8_2_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv9_2_mbox_loc_reshape (Resha (None, 36, 4) 0 conv9_2_mbox_loc[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv4_3_norm_mbox_priorbox_resh (None, 10000, 8) 0 conv4_3_norm_mbox_priorbox[0][0] \n", + "__________________________________________________________________________________________________\n", + "fc7_mbox_priorbox_reshape (Resh (None, 3750, 8) 0 fc7_mbox_priorbox[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv6_2_mbox_priorbox_reshape ( (None, 1014, 8) 0 conv6_2_mbox_priorbox[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv7_2_mbox_priorbox_reshape ( (None, 294, 8) 0 conv7_2_mbox_priorbox[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv8_2_mbox_priorbox_reshape ( (None, 100, 8) 0 conv8_2_mbox_priorbox[0][0] \n", + "__________________________________________________________________________________________________\n", + "conv9_2_mbox_priorbox_reshape ( (None, 36, 8) 0 conv9_2_mbox_priorbox[0][0] \n", + "__________________________________________________________________________________________________\n", + "mbox_conf_softmax (Activation) (None, 15194, 9) 0 mbox_conf[0][0] \n", + "__________________________________________________________________________________________________\n", + "mbox_loc (Concatenate) (None, 15194, 4) 0 conv4_3_norm_mbox_loc_reshape[0][\n", + " fc7_mbox_loc_reshape[0][0] \n", + " conv6_2_mbox_loc_reshape[0][0] \n", + " conv7_2_mbox_loc_reshape[0][0] \n", + " conv8_2_mbox_loc_reshape[0][0] \n", + " conv9_2_mbox_loc_reshape[0][0] \n", + "__________________________________________________________________________________________________\n", + "mbox_priorbox (Concatenate) (None, 15194, 8) 0 conv4_3_norm_mbox_priorbox_reshap\n", + " fc7_mbox_priorbox_reshape[0][0] \n", + " conv6_2_mbox_priorbox_reshape[0][\n", + " conv7_2_mbox_priorbox_reshape[0][\n", + " conv8_2_mbox_priorbox_reshape[0][\n", + " conv9_2_mbox_priorbox_reshape[0][\n", + "__________________________________________________________________________________________________\n", + "predictions (Concatenate) (None, 15194, 21) 0 mbox_conf_softmax[0][0] \n", + " mbox_loc[0][0] \n", + " mbox_priorbox[0][0] \n", + "==================================================================================================\n", + "Total params: 24,681,542\n", + "Trainable params: 24,681,542\n", + "Non-trainable params: 0\n", + "__________________________________________________________________________________________________\n" + ] + } + ], + "source": [ + "from keras.optimizers import Adam, SGD\n", + "from keras.callbacks import ModelCheckpoint, LearningRateScheduler, TerminateOnNaN, CSVLogger\n", + "from keras import backend as K\n", + "from keras.models import load_model\n", + "from math import ceil\n", + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "import os\n", + "import json\n", + "import xml.etree.cElementTree as ET\n", + "\n", + "import sys\n", + "sys.path += [os.path.abspath('../ssd_keras-master')]\n", + "\n", + "from keras_loss_function.keras_ssd_loss import SSDLoss\n", + "from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes\n", + "from keras_layers.keras_layer_DecodeDetections import DecodeDetections\n", + "from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast\n", + "from keras_layers.keras_layer_L2Normalization import L2Normalization\n", + "from ssd_encoder_decoder.ssd_input_encoder import SSDInputEncoder\n", + "from ssd_encoder_decoder.ssd_output_decoder import decode_detections, decode_detections_fast\n", + "from data_generator.object_detection_2d_data_generator import DataGenerator\n", + "from data_generator.object_detection_2d_geometric_ops import Resize\n", + "from data_generator.object_detection_2d_photometric_ops import ConvertTo3Channels\n", + "from data_generator.data_augmentation_chain_original_ssd import SSDDataAugmentation\n", + "from data_generator.object_detection_2d_misc_utils import apply_inverse_transforms\n", + "from eval_utils.average_precision_evaluator import Evaluator\n", + "from data_generator.data_augmentation_chain_variable_input_size import DataAugmentationVariableInputSize\n", + "from data_generator.data_augmentation_chain_constant_input_size import DataAugmentationConstantInputSize\n", + "\n", + "\n", + "def makedirs(path):\n", + " try:\n", + " os.makedirs(path)\n", + " except OSError:\n", + " if not os.path.isdir(path):\n", + " raise\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "K.tensorflow_backend._get_available_gpus()\n", + "\n", + "\n", + "def lr_schedule(epoch):\n", + " if epoch < 80:\n", + " return 0.001\n", + " elif epoch < 100:\n", + " return 0.0001\n", + " else:\n", + " return 0.00001\n", + "\n", + "config_path = 'config_300_fault_C.json'\n", + "\n", + "\n", + "with open(config_path) as config_buffer:\n", + " config = json.loads(config_buffer.read())\n", + "\n", + "###############################\n", + "# Parse the annotations\n", + "###############################\n", + "path_imgs_training = config['train']['train_image_folder']\n", + "path_anns_training = config['train']['train_annot_folder']\n", + "path_imgs_val = config['test']['test_image_folder']\n", + "path_anns_val = config['test']['test_annot_folder']\n", + "labels = config['model']['labels']\n", + "categories = {}\n", + "#categories = {\"Razor\": 1, \"Gun\": 2, \"Knife\": 3, \"Shuriken\": 4} #la categoría 0 es la background\n", + "for i in range(len(labels)): categories[labels[i]] = i+1\n", + "print('\\nTraining on: \\t' + str(categories) + '\\n')\n", + "\n", + "####################################\n", + "# Parameters\n", + "###################################\n", + " #%%\n", + "img_height = config['model']['input'] # Height of the model input images\n", + "img_width = config['model']['input'] # Width of the model input images\n", + "img_channels = 3 # Number of color channels of the model input images\n", + "mean_color = [123, 117, 104] # The per-channel mean of the images in the dataset. Do not change this value if you're using any of the pre-trained weights.\n", + "swap_channels = [2, 1, 0] # The color channel order in the original SSD is BGR, so we'll have the model reverse the color channel order of the input images.\n", + "n_classes = len(labels) # Number of positive classes, e.g. 20 for Pascal VOC, 80 for MS COCO\n", + "scales_pascal = [0.01, 0.05, 0.1, 0.2, 0.37, 0.54, 0.71] # The anchor box scaling factors used in the original SSD300 for the Pascal VOC datasets\n", + "#scales_coco = [0.07, 0.15, 0.33, 0.51, 0.69, 0.87, 1.05] # The anchor box scaling factors used in the original SSD300 for the MS COCO datasets\n", + "scales = scales_pascal\n", + "aspect_ratios = [[1.0, 2.0, 0.5],\n", + " [1.0, 2.0, 0.5, 3.0, 1.0/3.0],\n", + " [1.0, 2.0, 0.5, 3.0, 1.0/3.0],\n", + " [1.0, 2.0, 0.5, 3.0, 1.0/3.0],\n", + " [1.0, 2.0, 0.5],\n", + " [1.0, 2.0, 0.5]] # The anchor box aspect ratios used in the original SSD300; the order matters\n", + "two_boxes_for_ar1 = True\n", + "steps = [8, 16, 32, 64, 100, 300] # The space between two adjacent anchor box center points for each predictor layer.\n", + "offsets = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5] # The offsets of the first anchor box center points from the top and left borders of the image as a fraction of the step size for each predictor layer.\n", + "clip_boxes = False # Whether or not to clip the anchor boxes to lie entirely within the image boundaries\n", + "variances = [0.1, 0.1, 0.2, 0.2] # The variances by which the encoded target coordinates are divided as in the original implementation\n", + "normalize_coords = True\n", + "\n", + "K.clear_session() # Clear previous models from memory.\n", + "\n", + "\n", + "model_path = config['train']['saved_weights_name']\n", + "# 3: Instantiate an optimizer and the SSD loss function and compile the model.\n", + "# If you want to follow the original Caffe implementation, use the preset SGD\n", + "# optimizer, otherwise I'd recommend the commented-out Adam optimizer.\n", + "\n", + "\n", + "if config['model']['backend'] == 'ssd7':\n", + " #weights_path = 'VGG_ILSVRC_16_layers_fc_reduced.h5'\n", + " scales = [0.08, 0.16, 0.32, 0.64, 0.96] # An explicit list of anchor box scaling factors. If this is passed, it will override `min_scale` and `max_scale`.\n", + " aspect_ratios = [0.5 ,1.0, 2.0] # The list of aspect ratios for the anchor boxes\n", + " two_boxes_for_ar1 = True # Whether or not you want to generate two anchor boxes for aspect ratio 1\n", + " steps = None # In case you'd like to set the step sizes for the anchor box grids manually; not recommended\n", + " offsets = None\n", + "\n", + "if os.path.exists(model_path):\n", + " print(\"\\nLoading pretrained weights.\\n\")\n", + " # We need to create an SSDLoss object in order to pass that to the model loader.\n", + " ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)\n", + "\n", + " K.clear_session() # Clear previous models from memory.\n", + " model = load_model(model_path, custom_objects={'AnchorBoxes': AnchorBoxes,\n", + " 'L2Normalization': L2Normalization,\n", + " 'compute_loss': ssd_loss.compute_loss})\n", + "\n", + "\n", + "else:\n", + " ####################################\n", + " # Build the Keras model.\n", + " ###################################\n", + "\n", + " if config['model']['backend'] == 'ssd300':\n", + " #weights_path = 'VGG_VOC0712Plus_SSD_300x300_ft_iter_160000.h5'\n", + " from models.keras_ssd300 import ssd_300 as ssd\n", + "\n", + " model = ssd(image_size=(img_height, img_width, img_channels),\n", + " n_classes=n_classes,\n", + " mode='training',\n", + " l2_regularization=0.0005,\n", + " scales=scales,\n", + " aspect_ratios_per_layer=aspect_ratios,\n", + " two_boxes_for_ar1=two_boxes_for_ar1,\n", + " steps=steps,\n", + " offsets=offsets,\n", + " clip_boxes=clip_boxes,\n", + " variances=variances,\n", + " normalize_coords=normalize_coords,\n", + " subtract_mean=mean_color,\n", + " swap_channels=swap_channels)\n", + "\n", + "\n", + " elif config['model']['backend'] == 'ssd7':\n", + " #weights_path = 'VGG_ILSVRC_16_layers_fc_reduced.h5'\n", + " from models.keras_ssd7 import build_model as ssd\n", + " scales = [0.08, 0.16, 0.32, 0.64, 0.96] # An explicit list of anchor box scaling factors. If this is passed, it will override `min_scale` and `max_scale`.\n", + " aspect_ratios = [0.5 ,1.0, 2.0] # The list of aspect ratios for the anchor boxes\n", + " two_boxes_for_ar1 = True # Whether or not you want to generate two anchor boxes for aspect ratio 1\n", + " steps = None # In case you'd like to set the step sizes for the anchor box grids manually; not recommended\n", + " offsets = None\n", + " model = ssd(image_size=(img_height, img_width, img_channels),\n", + " n_classes=n_classes,\n", + " mode='training',\n", + " l2_regularization=0.0005,\n", + " scales=scales,\n", + " aspect_ratios_global=aspect_ratios,\n", + " aspect_ratios_per_layer=None,\n", + " two_boxes_for_ar1=two_boxes_for_ar1,\n", + " steps=steps,\n", + " offsets=offsets,\n", + " clip_boxes=clip_boxes,\n", + " variances=variances,\n", + " normalize_coords=normalize_coords,\n", + " subtract_mean=None,\n", + " divide_by_stddev=None)\n", + "\n", + " else :\n", + " print('Wrong Backend')\n", + "\n", + "\n", + "\n", + " print('OK create model')\n", + " #sgd = SGD(lr=config['train']['learning_rate'], momentum=0.9, decay=0.0, nesterov=False)\n", + "\n", + " # TODO: Set the path to the weights you want to load. only for ssd300 or ssd512\n", + "\n", + " weights_path = '../ssd_keras-master/VGG_ILSVRC_16_layers_fc_reduced.h5'\n", + " print(\"\\nLoading pretrained weights VGG.\\n\")\n", + " model.load_weights(weights_path, by_name=True)\n", + "\n", + " # 3: Instantiate an optimizer and the SSD loss function and compile the model.\n", + " # If you want to follow the original Caffe implementation, use the preset SGD\n", + " # optimizer, otherwise I'd recommend the commented-out Adam optimizer.\n", + "\n", + "\n", + " #adam = Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)\n", + " #sgd = SGD(lr=0.001, momentum=0.9, decay=0.0, nesterov=False)\n", + " optimizer = Adam(lr=config['train']['learning_rate'], beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)\n", + " ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)\n", + " model.compile(optimizer=optimizer, loss=ssd_loss.compute_loss)\n", + "\n", + " model.summary()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Instanciar los generadores de datos y entrenamiento del modelo.\n", + "\n", + "*Cambio realizado para leer png y jpg. keras-ssd-master/data_generator/object_detection_2d_data_generator.py función parse_xml\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "Processing image set 'train.txt': 0%| | 0/1337 [00:00\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 187\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 188\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 189\u001b[0;31m \u001b[0mbatch_images\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch_labels\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_generator\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 190\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 191\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/Rentadrone/ssd_keras-master/data_generator/object_detection_2d_data_generator.py\u001b[0m in \u001b[0;36mgenerate\u001b[0;34m(self, batch_size, shuffle, transformations, label_encoder, returns, keep_images_without_gt, degenerate_box_handling)\u001b[0m\n\u001b[1;32m 1019\u001b[0m \u001b[0mbatch_filenames\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfilenames\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcurrent\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mcurrent\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mbatch_size\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1020\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mfilename\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mbatch_filenames\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1021\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mImage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mimage\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1022\u001b[0m \u001b[0mbatch_X\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muint8\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1023\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/anaconda3/envs/tf_gpu/lib/python3.6/site-packages/PIL/Image.py\u001b[0m in \u001b[0;36mopen\u001b[0;34m(fp, mode)\u001b[0m\n\u001b[1;32m 2703\u001b[0m \u001b[0mwarnings\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwarn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2704\u001b[0m raise IOError(\"cannot identify image file %r\"\n\u001b[0;32m-> 2705\u001b[0;31m % (filename if filename else fp))\n\u001b[0m\u001b[1;32m 2706\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2707\u001b[0m \u001b[0;31m#\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mOSError\u001b[0m: cannot identify image file 'Train&Test_C/images/Mision 22_DJI_0067.jpg'" + ] + } + ], + "source": [ + "#ENTRENAMIENTO DE MODELO\n", + "#####################################################################\n", + "# Instantiate two `DataGenerator` objects: One for training, one for validation.\n", + "######################################################################\n", + "# Optional: If you have enough memory, consider loading the images into memory for the reasons explained above.\n", + "\n", + "train_dataset = DataGenerator(load_images_into_memory=False, hdf5_dataset_path=None)\n", + "val_dataset = DataGenerator(load_images_into_memory=False, hdf5_dataset_path=None)\n", + "\n", + "# 2: Parse the image and label lists for the training and validation datasets. This can take a while.\n", + "\n", + "\n", + "\n", + "# The XML parser needs to now what object class names to look for and in which order to map them to integers.\n", + "classes = ['background' ] + labels\n", + "\n", + "train_dataset.parse_xml(images_dirs= [config['train']['train_image_folder']],\n", + " image_set_filenames=[config['train']['train_image_set_filename']],\n", + " annotations_dirs=[config['train']['train_annot_folder']],\n", + " classes=classes,\n", + " include_classes='all',\n", + " #classes = classes, \n", + " #include_classes= [1],\n", + " exclude_truncated=False,\n", + " exclude_difficult=False,\n", + " ret=False)\n", + "\n", + "val_dataset.parse_xml(images_dirs= [config['test']['test_image_folder']],\n", + " image_set_filenames=[config['test']['test_image_set_filename']],\n", + " annotations_dirs=[config['test']['test_annot_folder']],\n", + " classes=classes,\n", + " include_classes='all',\n", + " #classes = classes, \n", + " #include_classes=[1],\n", + " exclude_truncated=False,\n", + " exclude_difficult=False,\n", + " ret=False)\n", + "\n", + "#########################\n", + "# 3: Set the batch size.\n", + "#########################\n", + "batch_size = config['train']['batch_size'] # Change the batch size if you like, or if you run into GPU memory issues.\n", + "\n", + "##########################\n", + "# 4: Set the image transformations for pre-processing and data augmentation options.\n", + "##########################\n", + "# For the training generator:\n", + "\n", + "\n", + "# For the validation generator:\n", + "convert_to_3_channels = ConvertTo3Channels()\n", + "resize = Resize(height=img_height, width=img_width)\n", + "\n", + "######################################3\n", + "# 5: Instantiate an encoder that can encode ground truth labels into the format needed by the SSD loss function.\n", + "#########################################\n", + "# The encoder constructor needs the spatial dimensions of the model's predictor layers to create the anchor boxes.\n", + "if config['model']['backend'] == 'ssd300':\n", + " predictor_sizes = [model.get_layer('conv4_3_norm_mbox_conf').output_shape[1:3],\n", + " model.get_layer('fc7_mbox_conf').output_shape[1:3],\n", + " model.get_layer('conv6_2_mbox_conf').output_shape[1:3],\n", + " model.get_layer('conv7_2_mbox_conf').output_shape[1:3],\n", + " model.get_layer('conv8_2_mbox_conf').output_shape[1:3],\n", + " model.get_layer('conv9_2_mbox_conf').output_shape[1:3]]\n", + " ssd_input_encoder = SSDInputEncoder(img_height=img_height,\n", + " img_width=img_width,\n", + " n_classes=n_classes,\n", + " predictor_sizes=predictor_sizes,\n", + " scales=scales,\n", + " aspect_ratios_per_layer=aspect_ratios,\n", + " two_boxes_for_ar1=two_boxes_for_ar1,\n", + " steps=steps,\n", + " offsets=offsets,\n", + " clip_boxes=clip_boxes,\n", + " variances=variances,\n", + " matching_type='multi',\n", + " pos_iou_threshold=0.5,\n", + " neg_iou_limit=0.5,\n", + " normalize_coords=normalize_coords)\n", + "\n", + "elif config['model']['backend'] == 'ssd7':\n", + " predictor_sizes = [model.get_layer('classes4').output_shape[1:3],\n", + " model.get_layer('classes5').output_shape[1:3],\n", + " model.get_layer('classes6').output_shape[1:3],\n", + " model.get_layer('classes7').output_shape[1:3]]\n", + " ssd_input_encoder = SSDInputEncoder(img_height=img_height,\n", + " img_width=img_width,\n", + " n_classes=n_classes,\n", + " predictor_sizes=predictor_sizes,\n", + " scales=scales,\n", + " aspect_ratios_global=aspect_ratios,\n", + " two_boxes_for_ar1=two_boxes_for_ar1,\n", + " steps=steps,\n", + " offsets=offsets,\n", + " clip_boxes=clip_boxes,\n", + " variances=variances,\n", + " matching_type='multi',\n", + " pos_iou_threshold=0.5,\n", + " neg_iou_limit=0.3,\n", + " normalize_coords=normalize_coords)\n", + "\n", + "\n", + "\n", + " \n", + "data_augmentation_chain = DataAugmentationVariableInputSize(resize_height = img_height,\n", + " resize_width = img_width,\n", + " random_brightness=(-48, 48, 0.5),\n", + " random_contrast=(0.5, 1.8, 0.5),\n", + " random_saturation=(0.5, 1.8, 0.5),\n", + " random_hue=(18, 0.5),\n", + " random_flip=0.5,\n", + " n_trials_max=3,\n", + " clip_boxes=True,\n", + " overlap_criterion='area',\n", + " bounds_box_filter=(0.3, 1.0),\n", + " bounds_validator=(0.5, 1.0),\n", + " n_boxes_min=1,\n", + " background=(0,0,0))\n", + "#######################\n", + "# 6: Create the generator handles that will be passed to Keras' `fit_generator()` function.\n", + "#######################\n", + "\n", + "train_generator = train_dataset.generate(batch_size=batch_size,\n", + " shuffle=True,\n", + " transformations= [data_augmentation_chain],\n", + " label_encoder=ssd_input_encoder,\n", + " returns={'processed_images',\n", + " 'encoded_labels'},\n", + " keep_images_without_gt=False)\n", + "\n", + "val_generator = val_dataset.generate(batch_size=batch_size,\n", + " shuffle=False,\n", + " transformations=[convert_to_3_channels,\n", + " resize],\n", + " label_encoder=ssd_input_encoder,\n", + " returns={'processed_images',\n", + " 'encoded_labels'},\n", + " keep_images_without_gt=False)\n", + "\n", + "# Summary instance training\n", + "category_train_list = []\n", + "for image_label in train_dataset.labels:\n", + " category_train_list += [i[0] for i in image_label]\n", + "summary_category_training = {train_dataset.classes[i]: category_train_list.count(i) for i in list(set(category_train_list))}\n", + "for i in summary_category_training.keys():\n", + " print(i, ': {:.0f}'.format(summary_category_training[i]))\n", + "\n", + "\n", + "\n", + "# Get the number of samples in the training and validations datasets.\n", + "train_dataset_size = train_dataset.get_dataset_size()\n", + "val_dataset_size = val_dataset.get_dataset_size()\n", + "\n", + "print(\"Number of images in the training dataset:\\t{:>6}\".format(train_dataset_size))\n", + "print(\"Number of images in the validation dataset:\\t{:>6}\".format(val_dataset_size))\n", + "\n", + "\n", + "\n", + "##########################\n", + "# Define model callbacks.\n", + "#########################\n", + "\n", + "# TODO: Set the filepath under which you want to save the model.\n", + "model_checkpoint = ModelCheckpoint(filepath= config['train']['saved_weights_name'],\n", + " monitor='val_loss',\n", + " verbose=1,\n", + " save_best_only=True,\n", + " save_weights_only=False,\n", + " mode='auto',\n", + " period=1)\n", + "#model_checkpoint.best =\n", + "\n", + "csv_logger = CSVLogger(filename='log.csv',\n", + " separator=',',\n", + " append=True)\n", + "\n", + "learning_rate_scheduler = LearningRateScheduler(schedule=lr_schedule,\n", + " verbose=1)\n", + "\n", + "terminate_on_nan = TerminateOnNaN()\n", + "\n", + "callbacks = [model_checkpoint,\n", + " csv_logger,\n", + " learning_rate_scheduler,\n", + " terminate_on_nan]\n", + "\n", + "\n", + "\n", + "batch_images, batch_labels = next(train_generator)\n", + "\n", + "\n", + "initial_epoch = 0\n", + "final_epoch = 100 #config['train']['nb_epochs']\n", + "steps_per_epoch = 200\n", + "\n", + "history = model.fit_generator(generator=train_generator,\n", + " steps_per_epoch=steps_per_epoch,\n", + " epochs=final_epoch,\n", + " callbacks=callbacks,\n", + " validation_data=val_generator,\n", + " validation_steps=ceil(val_dataset_size/batch_size*10),\n", + " initial_epoch=initial_epoch,\n", + " verbose = 1 if config['train']['debug'] else 2)\n", + "\n", + "history_path = config['train']['saved_weights_name'].split('.')[0] + '_history'\n", + "\n", + "np.save(history_path, history.history)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['background', '1', '4']" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "classes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_keys(['val_loss', 'loss', 'lr'])\n" + ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEWCAYAAABrDZDcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xd8lfXd//HXJ3sTSAh7hCFDRBBEFFQcWHFb66jVqrWlvWtbW1ur9r5tb3t3/rqsta3iqnshiAMXKgqKTJG9VxIgk0D2/P7++J4gmxCSHMj1fj4eeZBzznXO9b3OCdf7fOdlzjlERCS4IsJdABERCS8FgYhIwCkIREQCTkEgIhJwCgIRkYBTEIiIBJyCQOQQzOw/ZvabRm67yczOP9rXEWltCgIRkYBTEIiIBJyCQI57oSaZO81siZmVmdljZtbJzN4ysxIzm2Fm7ffY/jIzW25mxWY208wG7fHYcDNbFHrei0DcPvu6xMwWh577qZkNbWKZv2Nm68ysyMxeM7OuofvNzP5mZnlmtjN0TENCj11kZitCZcsxs5816Q0T2YeCQNqKq4DxwAnApcBbwC+AdPzf+Y8AzOwE4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QiKUsQm3jjwErnXN/3eOh14CbQr/fBExr7bK1FOfcPc657s653vjP9QPn3DeAD4GvhTZrU8cM4JzbDmSZ2YDQXecBK2jDnzW+SWi0mSWE/tYbjrlNf9Z7ONhn+xrwzdDoodHAzoYmpCZxzrXZH+AiYA2wHvjvcJenhY5xLL5KuARYHPq5CN9m/j6wNvRvh3CXtYWOfxzwRuj3PsA8YB3wMhAb7vK1wPEOAxaEPu9XgfZt/bMG7gNWAcuAp4HYtvhZA8/j+0Fq8N/4bz3YZ4tvGvpn6Ny2FD+qqsn71hITIiIB15abhkREpBEUBCIiAacgEBEJOAWBiEjAKQhERAJOQSDSwsxsXMMKqSLHIgWBiEjAKQhEQszsBjObZ2aLzezh0PUOSs3sL2a2yMzeN7OOoW2HmdlnobXgp+6xTnw/M5thZl+EntM39PJJe1xH4NnQLFmRY4KCQAQws0HAtcAY59wwoA74Bn6Rs0XOuVOAj4BfhZ7yFHCXc24ofmZnw/3PAv90zp2MXxOnYdr/cODH+Gtj9MGvlyRyTIg6/CYigXAeMAKYH/qyHo9f4KseeDG0zTPAFDNrB6Q65z4K3f8k8LKZJQPdnHNTAZxzlQCh15vnnMsO3V4M9AZmt/xhiRyegkDEM+BJ59w9e91pdu8+2x1qTZZDNfdU7fF7Hfq/J8cQNQ2JeO8DXzOzDNh9rdhe+P8jDatcXg/Mds7tBHaY2Zmh+28EPnL+OhDZZnZF6DVizSyhVY9CpAn0rUQEcM6tMLP/Ad41swj8CpC34S/+cqKZLcRfHeva0FNuAh4Kneg3ALeE7r8ReNjMfh16jatb8TBEmkSrj4ocgpmVOueSwl0OkZakpiERkYBTjUBEJOBUIxARCTgFgYhIwCkIREQCTkEgIhJwCgIRkYD7/2LskS6qBNsaAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "experimento_ssd300_fault_C_1.h5\n" + ] + } + ], + "source": [ + "#Graficar aprendizaje\n", + "\n", + "history_path =config['train']['saved_weights_name'].split('.')[0] + '_history'\n", + "\n", + "hist_load = np.load(history_path + '.npy',allow_pickle=True).item()\n", + "\n", + "print(hist_load.keys())\n", + "\n", + "# summarize history for loss\n", + "plt.plot(hist_load['loss'])\n", + "plt.plot(hist_load['val_loss'])\n", + "plt.title('model loss')\n", + "plt.ylabel('loss')\n", + "plt.xlabel('epoch')\n", + "plt.legend(['train', 'test'], loc='upper left')\n", + "plt.ylim((0, 10)) \n", + "plt.show()\n", + "\n", + "print(config['train']['saved_weights_name'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Evaluación del Modelo" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Processing image set 'train.txt': 0%| | 0/1366 [00:00\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[0mreturn_recalls\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 85\u001b[0m \u001b[0mreturn_average_precisions\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 86\u001b[0;31m verbose=True)\n\u001b[0m\u001b[1;32m 87\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 88\u001b[0m \u001b[0mmean_average_precision\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maverage_precisions\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mprecisions\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrecalls\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresults\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/Rentadrone/ssd_keras-master/eval_utils/average_precision_evaluator.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, img_height, img_width, batch_size, data_generator_mode, round_confidences, matching_iou_threshold, border_pixels, sorting_algorithm, average_precision_mode, num_recall_points, ignore_neutral_boxes, return_precisions, return_recalls, return_average_precisions, verbose, decoding_confidence_thresh, decoding_iou_threshold, decoding_top_k, decoding_pred_coords, decoding_normalize_coords)\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[0mround_confidences\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mround_confidences\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 200\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 201\u001b[0;31m ret=False)\n\u001b[0m\u001b[1;32m 202\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 203\u001b[0m \u001b[0;31m#############################################################################################\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/Rentadrone/ssd_keras-master/eval_utils/average_precision_evaluator.py\u001b[0m in \u001b[0;36mpredict_on_dataset\u001b[0;34m(self, img_height, img_width, batch_size, data_generator_mode, decoding_confidence_thresh, decoding_iou_threshold, decoding_top_k, decoding_pred_coords, decoding_normalize_coords, decoding_border_pixels, round_confidences, verbose, ret)\u001b[0m\n\u001b[1;32m 389\u001b[0m \u001b[0mimg_height\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mimg_height\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 390\u001b[0m \u001b[0mimg_width\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mimg_width\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 391\u001b[0;31m border_pixels=decoding_border_pixels)\n\u001b[0m\u001b[1;32m 392\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 393\u001b[0m \u001b[0;31m# Filter out the all-zeros dummy elements of `y_pred`.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/Rentadrone/ssd_keras-master/ssd_encoder_decoder/ssd_output_decoder.py\u001b[0m in \u001b[0;36mdecode_detections\u001b[0;34m(y_pred, confidence_thresh, iou_threshold, top_k, input_coords, normalize_coords, img_height, img_width, border_pixels)\u001b[0m\n\u001b[1;32m 209\u001b[0m \u001b[0mthreshold_met\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msingle_class\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0msingle_class\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0mconfidence_thresh\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;31m# ...keep only those boxes with a confidence above the set threshold.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 210\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mthreshold_met\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# If any boxes made the threshold...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 211\u001b[0;31m \u001b[0mmaxima\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_greedy_nms\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mthreshold_met\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0miou_threshold\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0miou_threshold\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcoords\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'corners'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mborder_pixels\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mborder_pixels\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# ...perform NMS on them.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 212\u001b[0m \u001b[0mmaxima_output\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmaxima\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxima\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# Expand the last dimension by one element to have room for the class ID. This is now an arrray of shape `[n_boxes, 6]`\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 213\u001b[0m \u001b[0mmaxima_output\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclass_id\u001b[0m \u001b[0;31m# Write the class ID to the first column...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/Rentadrone/ssd_keras-master/ssd_encoder_decoder/ssd_output_decoder.py\u001b[0m in \u001b[0;36m_greedy_nms\u001b[0;34m(predictions, iou_threshold, coords, border_pixels)\u001b[0m\n\u001b[1;32m 88\u001b[0m \u001b[0mboxes_left\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdelete\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboxes_left\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaximum_index\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# Now remove the maximum box from `boxes_left`\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 89\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mboxes_left\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mbreak\u001b[0m \u001b[0;31m# If there are no boxes left after this step, break. Otherwise...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 90\u001b[0;31m \u001b[0msimilarities\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0miou\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboxes_left\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaximum_box\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcoords\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcoords\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'element-wise'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mborder_pixels\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mborder_pixels\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# ...compare (IoU) the other left over boxes to the maximum box...\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 91\u001b[0m \u001b[0mboxes_left\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mboxes_left\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0msimilarities\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0miou_threshold\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;31m# ...so that we can remove the ones that overlap too much with the maximum box\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 92\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmaxima\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/Rentadrone/ssd_keras-master/bounding_box_utils/bounding_box_utils.py\u001b[0m in \u001b[0;36miou\u001b[0;34m(boxes1, boxes2, coords, mode, border_pixels)\u001b[0m\n\u001b[1;32m 343\u001b[0m \u001b[0;31m# Compute the interesection areas.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 344\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 345\u001b[0;31m \u001b[0mintersection_areas\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mintersection_area_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboxes1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mboxes2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcoords\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcoords\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 346\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 347\u001b[0m \u001b[0mm\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mboxes1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;31m# The number of boxes in `boxes1`\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Desktop/Rentadrone/ssd_keras-master/bounding_box_utils/bounding_box_utils.py\u001b[0m in \u001b[0;36mintersection_area_\u001b[0;34m(boxes1, boxes2, coords, mode, border_pixels)\u001b[0m\n\u001b[1;32m 278\u001b[0m \u001b[0mside_lengths\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmaximum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_xy\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mmin_xy\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 279\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 280\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mside_lengths\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mside_lengths\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 281\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 282\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "\n", + "config_path = 'config_7_fault_1.json'\n", + "\n", + "with open(config_path) as config_buffer:\n", + " config = json.loads(config_buffer.read())\n", + "\n", + " \n", + "model_mode = 'training'\n", + "# TODO: Set the path to the `.h5` file of the model to be loaded.\n", + "model_path = config['train']['saved_weights_name']\n", + "\n", + "# We need to create an SSDLoss object in order to pass that to the model loader.\n", + "ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)\n", + "\n", + "K.clear_session() # Clear previous models from memory.\n", + "\n", + "model = load_model(model_path, custom_objects={'AnchorBoxes': AnchorBoxes,\n", + " 'L2Normalization': L2Normalization,\n", + " 'DecodeDetections': DecodeDetections,\n", + " 'compute_loss': ssd_loss.compute_loss})\n", + "\n", + "\n", + " \n", + "train_dataset = DataGenerator(load_images_into_memory=False, hdf5_dataset_path=None)\n", + "val_dataset = DataGenerator(load_images_into_memory=False, hdf5_dataset_path=None)\n", + "\n", + "# 2: Parse the image and label lists for the training and validation datasets. This can take a while.\n", + "\n", + "\n", + "\n", + "# The XML parser needs to now what object class names to look for and in which order to map them to integers.\n", + "classes = ['background' ] + labels\n", + "\n", + "train_dataset.parse_xml(images_dirs= [config['train']['train_image_folder']],\n", + " image_set_filenames=[config['train']['train_image_set_filename']],\n", + " annotations_dirs=[config['train']['train_annot_folder']],\n", + " classes=classes,\n", + " include_classes='all',\n", + " #classes = ['background', 'panel', 'cell'], \n", + " #include_classes=classes,\n", + " exclude_truncated=False,\n", + " exclude_difficult=False,\n", + " ret=False)\n", + "\n", + "val_dataset.parse_xml(images_dirs= [config['test']['test_image_folder']],\n", + " image_set_filenames=[config['test']['test_image_set_filename']],\n", + " annotations_dirs=[config['test']['test_annot_folder']],\n", + " classes=classes,\n", + " include_classes='all',\n", + " #classes = ['background', 'panel', 'cell'], \n", + " #include_classes=classes,\n", + " exclude_truncated=False,\n", + " exclude_difficult=False,\n", + " ret=False)\n", + "\n", + "#########################\n", + "# 3: Set the batch size.\n", + "#########################\n", + "batch_size = config['train']['batch_size'] # Change the batch size if you like, or if you run into GPU memory issues.\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "evaluator = Evaluator(model=model,\n", + " n_classes=n_classes,\n", + " data_generator=val_dataset,\n", + " model_mode='training')\n", + "\n", + "results = evaluator(img_height=img_height,\n", + " img_width=img_width,\n", + " batch_size=4,\n", + " data_generator_mode='resize',\n", + " round_confidences=False,\n", + " matching_iou_threshold=0.5,\n", + " border_pixels='include',\n", + " sorting_algorithm='quicksort',\n", + " average_precision_mode='sample',\n", + " num_recall_points=11,\n", + " ignore_neutral_boxes=True,\n", + " return_precisions=True,\n", + " return_recalls=True,\n", + " return_average_precisions=True,\n", + " verbose=True)\n", + "\n", + "mean_average_precision, average_precisions, precisions, recalls = results\n", + "total_instances = []\n", + "precisions = []\n", + "\n", + "for i in range(1, len(average_precisions)):\n", + " \n", + " print('{:.0f} instances of class'.format(len(recalls[i])),\n", + " classes[i], 'with average precision: {:.4f}'.format(average_precisions[i]))\n", + " total_instances.append(len(recalls[i]))\n", + " precisions.append(average_precisions[i])\n", + "\n", + "if sum(total_instances) == 0:\n", + " \n", + " print('No test instances found.')\n", + "\n", + "else:\n", + "\n", + " print('mAP using the weighted average of precisions among classes: {:.4f}'.format(sum([a * b for a, b in zip(total_instances, precisions)]) / sum(total_instances)))\n", + " print('mAP: {:.4f}'.format(sum(precisions) / sum(x > 0 for x in total_instances)))\n", + "\n", + " for i in range(1, len(average_precisions)):\n", + " print(\"{:<14}{:<6}{}\".format(classes[i], 'AP', round(average_precisions[i], 3)))\n", + " print()\n", + " print(\"{:<14}{:<6}{}\".format('','mAP', round(mean_average_precision, 3)))" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ceil(val_dataset_size/batch_size)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Cargar nuevamente el modelo desde los pesos.\n", + "Predicción" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Training on: \t{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8}\n", + "\n" + ] + } + ], + "source": [ + "from imageio import imread\n", + "from keras.preprocessing import image\n", + "import time\n", + "\n", + "config_path = 'config_7_fault_1.json'\n", + "input_path = ['fault_jpg/']\n", + "output_path = 'result_ssd7_fault_1/'\n", + "\n", + "with open(config_path) as config_buffer:\n", + " config = json.loads(config_buffer.read())\n", + "\n", + "makedirs(output_path)\n", + "###############################\n", + "# Parse the annotations\n", + "###############################\n", + "score_threshold = 0.2\n", + "score_threshold_iou = 0.2\n", + "labels = config['model']['labels']\n", + "categories = {}\n", + "#categories = {\"Razor\": 1, \"Gun\": 2, \"Knife\": 3, \"Shuriken\": 4} #la categoría 0 es la background\n", + "for i in range(len(labels)): categories[labels[i]] = i+1\n", + "print('\\nTraining on: \\t' + str(categories) + '\\n')\n", + "\n", + "img_height = config['model']['input'] # Height of the model input images\n", + "img_width = config['model']['input'] # Width of the model input images\n", + "img_channels = 3 # Number of color channels of the model input images\n", + "n_classes = len(labels) # Number of positive classes, e.g. 20 for Pascal VOC, 80 for MS COCO\n", + "classes = ['background'] + labels\n", + "\n", + "model_mode = 'training'\n", + "# TODO: Set the path to the `.h5` file of the model to be loaded.\n", + "model_path = config['train']['saved_weights_name']\n", + "\n", + "# We need to create an SSDLoss object in order to pass that to the model loader.\n", + "ssd_loss = SSDLoss(neg_pos_ratio=3, alpha=1.0)\n", + "\n", + "K.clear_session() # Clear previous models from memory.\n", + "\n", + "model = load_model(model_path, custom_objects={'AnchorBoxes': AnchorBoxes,\n", + " 'L2Normalization': L2Normalization,\n", + " 'DecodeDetections': DecodeDetections,\n", + " 'compute_loss': ssd_loss.compute_loss})\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tiempo Total: 0.629\n", + "Tiempo promedio por imagen: 0.035\n", + "OK\n" + ] + } + ], + "source": [ + "image_paths = []\n", + "for inp in input_path:\n", + " if os.path.isdir(inp):\n", + " for inp_file in os.listdir(inp):\n", + " image_paths += [inp + inp_file]\n", + " else:\n", + " image_paths += [inp]\n", + "\n", + "image_paths = [inp_file for inp_file in image_paths if (inp_file[-4:] in ['.jpg', '.png', 'JPEG'])]\n", + "times = []\n", + "\n", + "\n", + "for img_path in image_paths:\n", + " orig_images = [] # Store the images here.\n", + " input_images = [] # Store resized versions of the images here.\n", + " #print(img_path)\n", + "\n", + " # preprocess image for network\n", + " orig_images.append(imread(img_path))\n", + " img = image.load_img(img_path, target_size=(img_height, img_width))\n", + " img = image.img_to_array(img)\n", + " input_images.append(img)\n", + " input_images = np.array(input_images)\n", + " # process image\n", + " start = time.time()\n", + " y_pred = model.predict(input_images)\n", + " y_pred_decoded = decode_detections(y_pred,\n", + " confidence_thresh=score_threshold,\n", + " iou_threshold=score_threshold_iou,\n", + " top_k=200,\n", + " normalize_coords=True,\n", + " img_height=img_height,\n", + " img_width=img_width)\n", + "\n", + "\n", + " #print(\"processing time: \", time.time() - start)\n", + " times.append(time.time() - start)\n", + " # correct for image scale\n", + "\n", + " # visualize detections\n", + " # Set the colors for the bounding boxes\n", + " colors = plt.cm.brg(np.linspace(0, 1, 21)).tolist()\n", + "\n", + " plt.figure(figsize=(20,12))\n", + " plt.imshow(orig_images[0],cmap = 'gray')\n", + "\n", + " current_axis = plt.gca()\n", + " #print(y_pred)\n", + " for box in y_pred_decoded[0]:\n", + " # Transform the predicted bounding boxes for the 300x300 image to the original image dimensions.\n", + "\n", + " xmin = box[2] * orig_images[0].shape[1] / img_width\n", + " ymin = box[3] * orig_images[0].shape[0] / img_height\n", + " xmax = box[4] * orig_images[0].shape[1] / img_width\n", + " ymax = box[5] * orig_images[0].shape[0] / img_height\n", + "\n", + " color = colors[int(box[0])]\n", + " label = '{}: {:.2f}'.format(classes[int(box[0])], box[1])\n", + " current_axis.add_patch(plt.Rectangle((xmin, ymin), xmax-xmin, ymax-ymin, color=color, fill=False, linewidth=2))\n", + " current_axis.text(xmin, ymin, label, size='x-large', color='white', bbox={'facecolor':color, 'alpha':1.0})\n", + "\n", + " #plt.figure(figsize=(15, 15))\n", + " #plt.axis('off')\n", + " save_path = output_path + img_path.split('/')[-1]\n", + " plt.savefig(save_path)\n", + " plt.close()\n", + " \n", + "file = open(output_path + 'time.txt','w')\n", + "\n", + "file.write('Tiempo promedio:' + str(np.mean(times)))\n", + "\n", + "file.close()\n", + "print('Tiempo Total: {:.3f}'.format(np.sum(times)))\n", + "print('Tiempo promedio por imagen: {:.3f}'.format(np.mean(times)))\n", + "print('OK')" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "panel : 69\n", + "cell : 423\n" + ] + } + ], + "source": [ + "\n", + "# Summary instance training\n", + "category_train_list = []\n", + "for image_label in train_dataset.labels:\n", + " category_train_list += [i[0] for i in train_dataset.labels[0]]\n", + "summary_category_training = {train_dataset.classes[i]: category_train_list.count(i) for i in list(set(category_train_list))}\n", + "for i in summary_category_training.keys():\n", + " print(i, ': {:.0f}'.format(summary_category_training[i]))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 : 6030\n" + ] + } + ], + "source": [ + "for i in summary_category_training.keys():\n", + " print(i, ': {:.0f}'.format(summary_category_training[i]))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/config_300_fault_1.json b/config_300_fault_1.json new file mode 100644 index 0000000..cafcca2 --- /dev/null +++ b/config_300_fault_1.json @@ -0,0 +1,28 @@ +{ + "model" : { + "backend": "ssd300", + "input": 400, + "labels": ["1"] + }, + + "train": { + "train_image_folder": "Train&Test_1/images", + "train_annot_folder": "Train&Test_1/anns", + "train_image_set_filename": "Train&Test_1/train.txt", + + "train_times": 1, + "batch_size": 12, + "learning_rate": 1e-4, + "nb_epochs": 10, + "warmup_epochs": 3, + "saved_weights_name": "experimento_ssd300_fault_1.h5", + "debug": true + }, + + +"test": { + "test_image_folder": "Train&Test_1/images", + "test_annot_folder": "Train&Test_1/anns", + "test_image_set_filename": "Train&Test_1/test.txt" + } +} diff --git a/config_300_fault_C.json b/config_300_fault_C.json new file mode 100644 index 0000000..8efaa7e --- /dev/null +++ b/config_300_fault_C.json @@ -0,0 +1,28 @@ +{ + "model" : { + "backend": "ssd300", + "input": 400, + "labels": ["1","2","3","4","5","6","7","8"] + }, + + "train": { + "train_image_folder": "Train&Test_C/images", + "train_annot_folder": "Train&Test_C/anns", + "train_image_set_filename": "Train&Test_C/train.txt", + + "train_times": 1, + "batch_size": 12, + "learning_rate": 1e-4, + "nb_epochs": 10, + "warmup_epochs": 3, + "saved_weights_name": "experimento_ssd300_fault_C.h5", + "debug": true + }, + + +"test": { + "test_image_folder": "Train&Test_C/images", + "test_annot_folder": "Train&Test_C/anns", + "test_image_set_filename": "Train&Test_C/test.txt" + } +} diff --git a/config_7_fault_1.json b/config_7_fault_1.json new file mode 100644 index 0000000..2c6b8f4 --- /dev/null +++ b/config_7_fault_1.json @@ -0,0 +1,28 @@ +{ + "model" : { + "backend": "ssd7", + "input": 400, + "labels": ["1"] + }, + + "train": { + "train_image_folder": "Train&Test_1/images", + "train_annot_folder": "Train&Test_1/anns", + "train_image_set_filename": "Train&Test_1/train.txt", + + "train_times": 1, + "batch_size": 8, + "learning_rate": 1e-4, + "nb_epochs": 10, + "warmup_epochs": 3, + "saved_weights_name": "experimento_ssd7_fault_1.h5", + "debug": true + }, + + +"test": { + "test_image_folder": "Train&Test_1/images", + "test_annot_folder": "Train&Test_1/anns", + "test_image_set_filename": "Train&Test_1/test.txt" + } +} diff --git a/config_7_fault_C.json b/config_7_fault_C.json new file mode 100644 index 0000000..8db2bb8 --- /dev/null +++ b/config_7_fault_C.json @@ -0,0 +1,28 @@ +{ + "model" : { + "backend": "ssd7", + "input": 400, + "labels": ["1","2","3","4","5","6","7","8"] + }, + + "train": { + "train_image_folder": "Train&Test_C/images", + "train_annot_folder": "Train&Test_C/anns", + "train_image_set_filename": "Train&Test_C/train.txt", + + "train_times": 1, + "batch_size": 8, + "learning_rate": 1e-4, + "nb_epochs": 10, + "warmup_epochs": 3, + "saved_weights_name": "experimento_ssd7_fault_C.h5", + "debug": true + }, + + +"test": { + "test_image_folder": "Train&Test_C/images", + "test_annot_folder": "Train&Test_C/anns", + "test_image_set_filename": "Train&TestTest_C_1/test.txt" + } +}