{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":14315,"databundleVersionId":862230,"sourceType":"competition"}],"dockerImageVersionId":30260,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"Object Detection","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport tensorflow.compat.v1 as tf\ntf.disable_v2_behavior()\nimport tensorflow_hub as hub\nfrom PIL import Image, ImageColor, ImageDraw, ImageFont\nimport time\n\nimport warnings\nwarnings.filterwarnings(action=\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:16.114586Z","iopub.execute_input":"2022-11-19T12:11:16.11508Z","iopub.status.idle":"2022-11-19T12:11:22.652544Z","shell.execute_reply.started":"2022-11-19T12:11:16.115039Z","shell.execute_reply":"2022-11-19T12:11:22.651343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DIR_PATH = '../input/open-images-2019-object-detection/'","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:22.655392Z","iopub.execute_input":"2022-11-19T12:11:22.657493Z","iopub.status.idle":"2022-11-19T12:11:22.662011Z","shell.execute_reply.started":"2022-11-19T12:11:22.657445Z","shell.execute_reply":"2022-11-19T12:11:22.660808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_image_paths = list(map(lambda x: DIR_PATH+'test/'+x, os.listdir(DIR_PATH+'test/')))\nall_image_ids   = list(path.split(DIR_PATH+'test/')[1][:-4] for path in all_image_paths)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:22.663416Z","iopub.execute_input":"2022-11-19T12:11:22.664083Z","iopub.status.idle":"2022-11-19T12:11:24.8982Z","shell.execute_reply.started":"2022-11-19T12:11:22.664045Z","shell.execute_reply":"2022-11-19T12:11:24.897045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('len(all_image_paths):', len(all_image_paths))\nprint('len(all_image_ids)  :', len(all_image_ids))","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:24.899483Z","iopub.execute_input":"2022-11-19T12:11:24.899789Z","iopub.status.idle":"2022-11-19T12:11:24.906458Z","shell.execute_reply.started":"2022-11-19T12:11:24.899758Z","shell.execute_reply":"2022-11-19T12:11:24.905245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('\\n'.join(all_image_paths[:5]))","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:24.910461Z","iopub.execute_input":"2022-11-19T12:11:24.9113Z","iopub.status.idle":"2022-11-19T12:11:24.917957Z","shell.execute_reply.started":"2022-11-19T12:11:24.911251Z","shell.execute_reply":"2022-11-19T12:11:24.91668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('\\n'.join(all_image_ids[:5]))","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:24.919916Z","iopub.execute_input":"2022-11-19T12:11:24.92076Z","iopub.status.idle":"2022-11-19T12:11:24.930175Z","shell.execute_reply.started":"2022-11-19T12:11:24.920705Z","shell.execute_reply":"2022-11-19T12:11:24.928911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_image(i):\n    plt.imshow(Image.open(all_image_paths[i]))","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:24.931764Z","iopub.execute_input":"2022-11-19T12:11:24.932891Z","iopub.status.idle":"2022-11-19T12:11:24.941159Z","shell.execute_reply.started":"2022-11-19T12:11:24.932827Z","shell.execute_reply":"2022-11-19T12:11:24.940135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_prediction_string(res):\n    with tf.device('/device:GPU:0'):\n        pred_strs = []\n        for i, score in enumerate(res['detection_scores']):\n            single_pred_str = ''\n            single_pred_str += res['detection_class_names'][i].decode(\"utf-8\") + ' ' + str(score) + ' '\n            single_pred_str += ' '.join(str(x) for x in res['detection_boxes'][i])\n            pred_strs.append(single_pred_str)\n        return ' '.join(map(str, pred_strs))","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:24.942787Z","iopub.execute_input":"2022-11-19T12:11:24.943145Z","iopub.status.idle":"2022-11-19T12:11:24.957791Z","shell.execute_reply.started":"2022-11-19T12:11:24.943115Z","shell.execute_reply":"2022-11-19T12:11:24.956933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_prediction_entry(i, res):\n    return {\n        \"ImageID\": all_image_ids[i],\n        \"PredictionString\": get_prediction_string(res)\n    }","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:24.959275Z","iopub.execute_input":"2022-11-19T12:11:24.959904Z","iopub.status.idle":"2022-11-19T12:11:24.96867Z","shell.execute_reply.started":"2022-11-19T12:11:24.959868Z","shell.execute_reply":"2022-11-19T12:11:24.967682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"The following GPU devices are available: %s\" % tf.test.gpu_device_name())","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:24.970235Z","iopub.execute_input":"2022-11-19T12:11:24.970556Z","iopub.status.idle":"2022-11-19T12:11:24.995704Z","shell.execute_reply.started":"2022-11-19T12:11:24.970528Z","shell.execute_reply":"2022-11-19T12:11:24.994868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.version","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:24.999332Z","iopub.execute_input":"2022-11-19T12:11:24.999965Z","iopub.status.idle":"2022-11-19T12:11:25.011605Z","shell.execute_reply.started":"2022-11-19T12:11:24.999929Z","shell.execute_reply":"2022-11-19T12:11:25.010489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.layers import Conv2D\nfrom keras.layers import Input\nfrom keras.layers import BatchNormalization\nfrom keras.layers import LeakyReLU\nfrom keras.layers import ZeroPadding2D\nfrom keras.layers import UpSampling2D\nfrom keras.layers import merge\nfrom keras.models import Model","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.013607Z","iopub.execute_input":"2022-11-19T12:11:25.014408Z","iopub.status.idle":"2022-11-19T12:11:25.023301Z","shell.execute_reply.started":"2022-11-19T12:11:25.01434Z","shell.execute_reply":"2022-11-19T12:11:25.022111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def generate_layers(n_layers, filters, kernel, stride, bnorm, leaky, idx):\n    layers = []\n    for i in range(n_layers):\n        layers += [{'filter': filters[i], 'kernel': kernel[i], 'stride': stride[i], \n                    'bnorm': bnorm[i], 'leaky': leaky[i], 'idx': idx[i]}]\n    return layers","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.024619Z","iopub.execute_input":"2022-11-19T12:11:25.025019Z","iopub.status.idle":"2022-11-19T12:11:25.033442Z","shell.execute_reply.started":"2022-11-19T12:11:25.024986Z","shell.execute_reply":"2022-11-19T12:11:25.032498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def constract_neural_network():\n    neural_network_layers = {\n         0: generate_layers(n_layers=4, filters=[32,64,32,64],  kernel=[3,3,1,3],   stride=[1,2,1,1], \n                                        bnorm=[1,1,1,1],        leaky=[1,1,1,1],    idx=[0,1,2,3]),\n         1: generate_layers(n_layers=3, filters=[128,64,128],   kernel=[3,1,3],     stride=[2,1,1], \n                                        bnorm=[1,1,1],          leaky=[1,1,1],      idx=[5,6,7]),\n         2: generate_layers(n_layers=2, filters=[64,128],       kernel=[1,3],       stride=[1,1], \n                                        bnorm=[1,1],            leaky=[1,1],        idx=[9,10]),\n         3: generate_layers(n_layers=3, filters=[256,128,256],  kernel=[3,1,3],     stride=[2,1,1], \n                                        bnorm=[1,1,1],          leaky=[1,1,1],      idx=[12,13,14]),\n         4: generate_layers(n_layers=2, filters=[128,256],      kernel=[1,3],       stride=[1,1], \n                                        bnorm=[1,1],            leaky=[1,1],        idx=[16+i*3, 17+i*3]),\n         5: generate_layers(n_layers=3, filters=[512,256,512],  kernel=[3,1,3],     stride=[2,1,1], \n                                        bnorm=[1,1,1],          leaky=[1,1,1],      idx=[37,38,39]),\n         6: generate_layers(n_layers=2, filters=[256,512],      kernel=[1,3],       stride=[1,1], \n                                        bnorm=[1,1],            leaky=[1,1],        idx=[41+i*3, 42+i*3]),\n         7: generate_layers(n_layers=3, filters=[1024,512,1024], kernel=[3,1,3],    stride=[2,1,1], \n                                        bnorm=[1,1,1],          leaky=[1,1,1],      idx=[62,63,64]),\n         8: generate_layers(n_layers=2, filters=[512,1024],     kernel=[1,3],       stride=[1,1], \n                                        bnorm=[1,1],            leaky=[1,1],        idx=[66+i*3, 67+i*3]),\n         9: generate_layers(n_layers=5, filters=[512,1024,512,1024,512], \n                                        kernel=[1,3,1,3,1],                         stride=[1,1,1,1,1], \n                                        bnorm=[1,1,1,1,1],      leaky=[1,1,1,1,1],  idx=[75,76,77,78,79]),\n        10: generate_layers(n_layers=2, filters=[1024,255],     kernel=[3,1],       stride=[1,1], \n                                        bnorm=[1,0],            leaky=[1,0],        idx=[80,81]),\n        11: generate_layers(n_layers=1, filters=[256],          kernel=[1],         stride=[1], \n                                        bnorm=[1],              leaky=[1],          idx=[84]),\n        12: generate_layers(n_layers=5, filters=[256,512,256,512,256], \n                                        kernel=[1,3,1,3,1],                         stride=[1,1,1,1,1], \n                                        bnorm=[1,1,1,1,1],      leaky=[1,1,1,1,1],  idx=[87,88,89,90,91]),\n        13: generate_layers(n_layers=2, filters=[512,255],      kernel=[3,1],       stride=[1,1], \n                                        bnorm=[1,0],            leaky=[1,0],        idx=[92,93]),\n        14: generate_layers(n_layers=1, filters=[128],          kernel=[1],         stride=[1], \n                                        bnorm=[1],              leaky=[1],          idx=[96]),\n        15: generate_layers(n_layers=7, filters=[128,256,128,256,128,256,255], \n                                        kernel=[1,3,1,3,1,3,1],                     stride=[1,1,1,1,1,1,1], \n                                        bnorm=[1,1,1,1,1,1,0],  leaky=[1,1,1,1,1,1,0], \n                                        idx=[99,100,101,102,103,104,105]),\n    }\n    return neural_network_layers","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.040726Z","iopub.execute_input":"2022-11-19T12:11:25.041128Z","iopub.status.idle":"2022-11-19T12:11:25.06564Z","shell.execute_reply.started":"2022-11-19T12:11:25.041094Z","shell.execute_reply":"2022-11-19T12:11:25.064747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def conv_block(x, layers, skip=True):\n    for i in range(len(layers)):\n        if skip and i == len(layers) - 2:\n            skip_conn = x\n        if layers[i]['stride'] > 1: \n            x = ZeroPadding2D(((1,0), (1,0)))(x)\n        layer_name = 'conv_' + str(layers[i]['idx'])\n        x = Conv2D(layers[i]['filter'], layers[i]['kernel'],\n                   strides=conv['stride'],\n                   padding=('valid' if layers[i]['stride'] > 1 else 'same'), \n                   name=layer_name,\n                   use_bias=(not layers[i]['bnorm']))(x)\n        if layers[i]['bnorm']: \n            layer_name = 'bnorm_' + str(layers[i]['idx'])\n            x = BatchNormalization(epsilon=0.001, name=layer_name)(x)\n        if layers[i]['leaky']: \n            layer_name = 'leaky_' + str(layers[i]['idx'])\n            x = LeakyReLU(alpha=0.1, name=layer_name)(x)\n    return x if not skip else merge.add([skip_conn, x])","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.066797Z","iopub.execute_input":"2022-11-19T12:11:25.067617Z","iopub.status.idle":"2022-11-19T12:11:25.082378Z","shell.execute_reply.started":"2022-11-19T12:11:25.067579Z","shell.execute_reply":"2022-11-19T12:11:25.081199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def constract_yolov3_model():\n    input_image = Input(shape=(None, None, 3))\n    neural_network_layers = constract_neural_network()\n    x = conv_block(input_image, neural_network_layers[0])   # Layer  0 to  4\n    x = conv_block(x, neural_network_layers[1])             # Layer  5 to  8\n    x = conv_block(x, neural_network_layers[2])             # Layer  9 to 11\n    x = conv_block(x, neural_network_layers[3])             # Layer 12 to 15\n    for i in range(7):                                      # Layer 16 to 36\n        x = conv_block(x, neural_network_layers[4])\n    skip_36 = x\n    x = conv_block(x, neural_network_layers[5])         # Layer 37 to 40\n    for i in range(7):                                  # Layer 41 to 61\n        x = conv_block(x, neural_network_layers[6])\n    skip_61 = x\n    x = conv_block(x, neural_network_layers[7])         # Layer 62 to 65\n    for i in range(3):                                  # Layer 66 to 74\n        x = conv_block(x, neural_network_layers[8])\n    x = conv_block(x, neural_network_layers[9], skip=False)         # Layer 75 to 79\n    yolo_82 = conv_block(x, neural_network_layers[10], skip=False)  # Layer 80 to 82\n    x = conv_block(x, neural_network_layers[11], skip=False)        # Layer 83 to 86\n    x = UpSampling2D(2)(x)\n    x = merge.concatenate([x, skip_61])\n    x = conv_block(x, neural_network_layers[12], skip=False)        # Layer 87 to 91\n    yolo_94 = conv_block(x, neural_network_layers[13], skip=False)  # Layer 92 to 94\n    x = conv_block(x, neural_network_layers[14], skip=False)        # Layer 95 to 98\n    x = UpSampling2D(2)(x)\n    x = merge.concatenate([x, skip_36])\n    yolo_106 = conv_block(x, neural_network_layers[15], skip=False) # Layer 99 to 106\n    model = Model(input_image, [yolo_82, yolo_94, yolo_106])\n    return model","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.083525Z","iopub.execute_input":"2022-11-19T12:11:25.084316Z","iopub.status.idle":"2022-11-19T12:11:25.100581Z","shell.execute_reply.started":"2022-11-19T12:11:25.08428Z","shell.execute_reply":"2022-11-19T12:11:25.099352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def draw_bounding_box_on_image(image, ymin, xmin, ymax, xmax, color, font, thickness=4, display_str_list=()):\n    draw = ImageDraw.Draw(image)\n    w, h = image.size\n    (left, right) = (xmin * w, xmax * w)\n    (top, bottom) = (ymin * h, ymax * h)\n    line_points = [(left, top), (left, bottom), (right, bottom), (right, top), (left, top)]\n    draw.line(line_points, width=thickness, fill=color)\n    display_heights = [font.getsize(ds)[1] for ds in display_str_list]\n    total_display_height = (1 + 2 * 0.05) * sum(display_heights)\n    text_bottom = top if top > total_display_height else bottom + total_display_height\n\n    for display_str in display_str_list[::-1]:\n        text_width, text_height = font.getsize(display_str)\n        margin = np.ceil(0.05 * text_height)\n        rect_points = [(left, text_bottom - text_height - 2 * margin), \n                       (left + text_width, text_bottom)]\n        draw.rectangle(rect_points, fill=color)\n        draw.text((left + margin, text_bottom - text_height - margin),\n                  display_str, fill=\"black\", font=font)\n        text_bottom -= text_height - 2 * margin","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.10212Z","iopub.execute_input":"2022-11-19T12:11:25.10293Z","iopub.status.idle":"2022-11-19T12:11:25.116959Z","shell.execute_reply.started":"2022-11-19T12:11:25.102889Z","shell.execute_reply":"2022-11-19T12:11:25.115759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def draw_boxes(image, boxes, class_names, scores, max_boxes=10, min_score=0.1):\n    colors = list(ImageColor.colormap.values())\n    font = ImageFont.load_default()\n\n    for i in range(min(boxes.shape[0], max_boxes)):\n        if scores[i] < min_score:\n            continue\n        ymin, xmin, ymax, xmax = tuple(boxes[i].tolist())\n        display_str = \"{}: {}%\".format(class_names[i].decode(\"ascii\"),\n                                           int(100 * scores[i]))\n        color = colors[hash(class_names[i]) % len(colors)]\n        image_pil = Image.fromarray(np.uint8(image)).convert(\"RGB\")\n        draw_bounding_box_on_image(image_pil, ymin, xmin, ymax, xmax,\n                                   color, font, display_str_list=[display_str])\n        np.copyto(image, np.array(image_pil))\n    return image","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.11845Z","iopub.execute_input":"2022-11-19T12:11:25.118799Z","iopub.status.idle":"2022-11-19T12:11:25.134299Z","shell.execute_reply.started":"2022-11-19T12:11:25.118767Z","shell.execute_reply":"2022-11-19T12:11:25.133128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def detect_objects(i, predictions=[]):\n    module_handle = \"https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1\"\n\n    with tf.device('/device:GPU:0'):\n        with tf.Graph().as_default():\n            detector = hub.Module(module_handle)\n            image_string_placeholder = tf.placeholder(tf.string)\n            decoded_image = tf.image.decode_jpeg(image_string_placeholder)\n            decoded_image_float = tf.image.convert_image_dtype(image=decoded_image, dtype=tf.float32)\n            module_input = tf.expand_dims(decoded_image_float, 0)\n            res = detector(module_input, as_dict=True)\n            init_ops = [tf.global_variables_initializer(), tf.tables_initializer()]\n            session = tf.Session()\n            session.run(init_ops)\n            \n            with tf.gfile.Open(all_image_paths[i], \"rb\") as binfile:\n                image_string = binfile.read()\n            inference_start_time = time.clock()\n            res_out, image_out = session.run([res, decoded_image],\n                                             feed_dict={image_string_placeholder: image_string})\n            inference_end_time = time.clock()\n            predictions.append(get_prediction_entry(i, res_out))\n            print('For %s found %d objects in %d seconds' % (all_image_paths[i].split('/')[-1], \n                                                             len(res_out[\"detection_scores\"]), \n                                                             int(inference_end_time - inference_start_time)))\n            return res_out, image_out, predictions","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.135667Z","iopub.execute_input":"2022-11-19T12:11:25.136035Z","iopub.status.idle":"2022-11-19T12:11:25.147034Z","shell.execute_reply.started":"2022-11-19T12:11:25.136003Z","shell.execute_reply":"2022-11-19T12:11:25.146073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def detect_objects_in_image(i):\n    res_out, image_out, predictions = detect_objects(i)\n    image_out = np.array(image_out)\n    image_with_boxes = draw_boxes(image_out,\n                                  res_out[\"detection_boxes\"],\n                                  res_out[\"detection_class_entities\"], \n                                  res_out[\"detection_scores\"])\n    img = Image.fromarray(np.uint8(image_with_boxes)).convert('RGB')\n    plt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.148864Z","iopub.execute_input":"2022-11-19T12:11:25.149759Z","iopub.status.idle":"2022-11-19T12:11:25.161604Z","shell.execute_reply.started":"2022-11-19T12:11:25.149713Z","shell.execute_reply":"2022-11-19T12:11:25.160679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_image(0)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.163117Z","iopub.execute_input":"2022-11-19T12:11:25.164197Z","iopub.status.idle":"2022-11-19T12:11:25.640201Z","shell.execute_reply.started":"2022-11-19T12:11:25.164153Z","shell.execute_reply":"2022-11-19T12:11:25.639007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_objects_in_image(0)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:11:25.641681Z","iopub.execute_input":"2022-11-19T12:11:25.642465Z","iopub.status.idle":"2022-11-19T12:13:35.949111Z","shell.execute_reply.started":"2022-11-19T12:11:25.642418Z","shell.execute_reply":"2022-11-19T12:13:35.947933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_image(1)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:13:35.950761Z","iopub.execute_input":"2022-11-19T12:13:35.951103Z","iopub.status.idle":"2022-11-19T12:13:36.296068Z","shell.execute_reply.started":"2022-11-19T12:13:35.951073Z","shell.execute_reply":"2022-11-19T12:13:36.294874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_objects_in_image(1)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:13:36.29754Z","iopub.execute_input":"2022-11-19T12:13:36.297881Z","iopub.status.idle":"2022-11-19T12:15:47.460135Z","shell.execute_reply.started":"2022-11-19T12:13:36.297852Z","shell.execute_reply":"2022-11-19T12:15:47.458984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_image(2)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:18:01.367486Z","iopub.execute_input":"2022-11-19T12:18:01.368232Z","iopub.status.idle":"2022-11-19T12:18:01.72078Z","shell.execute_reply.started":"2022-11-19T12:18:01.368186Z","shell.execute_reply":"2022-11-19T12:18:01.719916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_objects_in_image(2)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:18:01.721951Z","iopub.execute_input":"2022-11-19T12:18:01.722696Z","iopub.status.idle":"2022-11-19T12:20:15.169856Z","shell.execute_reply.started":"2022-11-19T12:18:01.722661Z","shell.execute_reply":"2022-11-19T12:20:15.168748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = []\nfor i in range(10):\n    detect_objects(i, predictions)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-11-19T12:22:30.723515Z","iopub.execute_input":"2022-11-19T12:22:30.72431Z","iopub.status.idle":"2022-11-19T12:45:13.32187Z","shell.execute_reply.started":"2022-11-19T12:22:30.724262Z","shell.execute_reply":"2022-11-19T12:45:13.320956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions_df = pd.DataFrame(predictions)\npredictions_df","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:45:13.336449Z","iopub.execute_input":"2022-11-19T12:45:13.336886Z","iopub.status.idle":"2022-11-19T12:45:13.442636Z","shell.execute_reply.started":"2022-11-19T12:45:13.336852Z","shell.execute_reply":"2022-11-19T12:45:13.441356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.read_csv(DIR_PATH+'sample_submission.csv')\nsubmission_df.update(predictions_df)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:45:13.444239Z","iopub.execute_input":"2022-11-19T12:45:13.444582Z","iopub.status.idle":"2022-11-19T12:45:13.67851Z","shell.execute_reply.started":"2022-11-19T12:45:13.444549Z","shell.execute_reply":"2022-11-19T12:45:13.677343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv('./10_values_submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-11-19T12:45:13.680226Z","iopub.execute_input":"2022-11-19T12:45:13.680582Z","iopub.status.idle":"2022-11-19T12:45:13.945797Z","shell.execute_reply.started":"2022-11-19T12:45:13.68055Z","shell.execute_reply":"2022-11-19T12:45:13.944268Z"},"trusted":true},"execution_count":null,"outputs":[]}]}