{"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":"markdown","source":"# Open Images 2019 - Object Detection","metadata":{}},{"cell_type":"code","source":"import 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\nimport os\n\nimport warnings\nwarnings.filterwarnings(action=\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:47:44.874488Z","iopub.execute_input":"2024-06-10T11:47:44.875849Z","iopub.status.idle":"2024-06-10T11:47:53.491384Z","shell.execute_reply.started":"2024-06-10T11:47:44.875705Z","shell.execute_reply":"2024-06-10T11:47:53.489996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(os.listdir(\"../input\"))","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:47:53.493861Z","iopub.execute_input":"2024-06-10T11:47:53.494629Z","iopub.status.idle":"2024-06-10T11:47:53.502671Z","shell.execute_reply.started":"2024-06-10T11:47:53.494590Z","shell.execute_reply":"2024-06-10T11:47:53.500961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(os.listdir(\"../input/open-images-2019-object-detection\"))","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:47:53.504798Z","iopub.execute_input":"2024-06-10T11:47:53.505966Z","iopub.status.idle":"2024-06-10T11:47:53.534757Z","shell.execute_reply.started":"2024-06-10T11:47:53.505905Z","shell.execute_reply":"2024-06-10T11:47:53.533208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DIR_PATH = '../input/open-images-2019-object-detection/'","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:47:53.536598Z","iopub.execute_input":"2024-06-10T11:47:53.537061Z","iopub.status.idle":"2024-06-10T11:47:53.548871Z","shell.execute_reply.started":"2024-06-10T11:47:53.537022Z","shell.execute_reply":"2024-06-10T11:47:53.546953Z"},"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":"2024-06-10T11:47:53.554120Z","iopub.execute_input":"2024-06-10T11:47:53.555242Z","iopub.status.idle":"2024-06-10T11:47:54.537563Z","shell.execute_reply.started":"2024-06-10T11:47:53.555194Z","shell.execute_reply":"2024-06-10T11:47:54.535948Z"},"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":"2024-06-10T11:47:54.539411Z","iopub.execute_input":"2024-06-10T11:47:54.539895Z","iopub.status.idle":"2024-06-10T11:47:54.547768Z","shell.execute_reply.started":"2024-06-10T11:47:54.539857Z","shell.execute_reply":"2024-06-10T11:47:54.546139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('\\n'.join(all_image_paths[:5]))","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:47:54.549335Z","iopub.execute_input":"2024-06-10T11:47:54.549752Z","iopub.status.idle":"2024-06-10T11:47:54.561460Z","shell.execute_reply.started":"2024-06-10T11:47:54.549716Z","shell.execute_reply":"2024-06-10T11:47:54.559832Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('\\n'.join(all_image_ids[:5]))","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:47:54.571165Z","iopub.execute_input":"2024-06-10T11:47:54.571642Z","iopub.status.idle":"2024-06-10T11:47:54.579774Z","shell.execute_reply.started":"2024-06-10T11:47:54.571605Z","shell.execute_reply":"2024-06-10T11:47:54.577790Z"},"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":"2024-06-10T11:47:54.581300Z","iopub.execute_input":"2024-06-10T11:47:54.581726Z","iopub.status.idle":"2024-06-10T11:47:54.591921Z","shell.execute_reply.started":"2024-06-10T11:47:54.581674Z","shell.execute_reply":"2024-06-10T11:47:54.590477Z"},"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":"2024-06-10T11:47:54.593709Z","iopub.execute_input":"2024-06-10T11:47:54.594280Z","iopub.status.idle":"2024-06-10T11:47:54.607736Z","shell.execute_reply.started":"2024-06-10T11:47:54.594232Z","shell.execute_reply":"2024-06-10T11:47:54.606228Z"},"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":"2024-06-10T11:47:54.609913Z","iopub.execute_input":"2024-06-10T11:47:54.610304Z","iopub.status.idle":"2024-06-10T11:47:54.627030Z","shell.execute_reply.started":"2024-06-10T11:47:54.610270Z","shell.execute_reply":"2024-06-10T11:47:54.625604Z"},"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":"2024-06-10T11:47:54.628436Z","iopub.execute_input":"2024-06-10T11:47:54.628799Z","iopub.status.idle":"2024-06-10T11:47:54.658839Z","shell.execute_reply.started":"2024-06-10T11:47:54.628766Z","shell.execute_reply":"2024-06-10T11:47:54.657167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.version","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:47:54.661031Z","iopub.execute_input":"2024-06-10T11:47:54.661662Z","iopub.status.idle":"2024-06-10T11:47:54.678323Z","shell.execute_reply.started":"2024-06-10T11:47:54.661606Z","shell.execute_reply":"2024-06-10T11:47:54.676485Z"},"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":"2024-06-10T11:47:54.686216Z","iopub.execute_input":"2024-06-10T11:47:54.686690Z","iopub.status.idle":"2024-06-10T11:47:54.694631Z","shell.execute_reply.started":"2024-06-10T11:47:54.686652Z","shell.execute_reply":"2024-06-10T11:47:54.693095Z"},"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":"2024-06-10T11:47:54.696372Z","iopub.execute_input":"2024-06-10T11:47:54.696863Z","iopub.status.idle":"2024-06-10T11:47:54.710356Z","shell.execute_reply.started":"2024-06-10T11:47:54.696819Z","shell.execute_reply":"2024-06-10T11:47:54.708958Z"},"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":"2024-06-10T11:47:54.712304Z","iopub.execute_input":"2024-06-10T11:47:54.712751Z","iopub.status.idle":"2024-06-10T11:47:54.752236Z","shell.execute_reply.started":"2024-06-10T11:47:54.712712Z","shell.execute_reply":"2024-06-10T11:47:54.750742Z"},"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":"2024-06-10T11:47:54.754346Z","iopub.execute_input":"2024-06-10T11:47:54.754962Z","iopub.status.idle":"2024-06-10T11:47:54.771793Z","shell.execute_reply.started":"2024-06-10T11:47:54.754915Z","shell.execute_reply":"2024-06-10T11:47:54.770231Z"},"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":"2024-06-10T11:47:54.773818Z","iopub.execute_input":"2024-06-10T11:47:54.774262Z","iopub.status.idle":"2024-06-10T11:47:54.795089Z","shell.execute_reply.started":"2024-06-10T11:47:54.774227Z","shell.execute_reply":"2024-06-10T11:47:54.793263Z"},"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":"2024-06-10T11:47:54.797040Z","iopub.execute_input":"2024-06-10T11:47:54.797519Z","iopub.status.idle":"2024-06-10T11:47:54.819598Z","shell.execute_reply.started":"2024-06-10T11:47:54.797481Z","shell.execute_reply":"2024-06-10T11:47:54.817878Z"},"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":"2024-06-10T11:47:54.821507Z","iopub.execute_input":"2024-06-10T11:47:54.822033Z","iopub.status.idle":"2024-06-10T11:47:54.841022Z","shell.execute_reply.started":"2024-06-10T11:47:54.821987Z","shell.execute_reply":"2024-06-10T11:47:54.839467Z"},"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":"2024-06-10T11:47:54.842679Z","iopub.execute_input":"2024-06-10T11:47:54.843220Z","iopub.status.idle":"2024-06-10T11:47:54.860693Z","shell.execute_reply.started":"2024-06-10T11:47:54.843172Z","shell.execute_reply":"2024-06-10T11:47:54.858927Z"},"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":"2024-06-10T11:47:54.862577Z","iopub.execute_input":"2024-06-10T11:47:54.863029Z","iopub.status.idle":"2024-06-10T11:47:54.881017Z","shell.execute_reply.started":"2024-06-10T11:47:54.862990Z","shell.execute_reply":"2024-06-10T11:47:54.879511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_image(0)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:47:54.882703Z","iopub.execute_input":"2024-06-10T11:47:54.883087Z","iopub.status.idle":"2024-06-10T11:47:55.380811Z","shell.execute_reply.started":"2024-06-10T11:47:54.883046Z","shell.execute_reply":"2024-06-10T11:47:55.379145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_objects_in_image(0)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:47:55.382693Z","iopub.execute_input":"2024-06-10T11:47:55.383120Z","iopub.status.idle":"2024-06-10T11:50:21.890519Z","shell.execute_reply.started":"2024-06-10T11:47:55.383081Z","shell.execute_reply":"2024-06-10T11:50:21.888638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_image(1)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:50:21.892591Z","iopub.execute_input":"2024-06-10T11:50:21.893057Z","iopub.status.idle":"2024-06-10T11:50:22.226370Z","shell.execute_reply.started":"2024-06-10T11:50:21.893016Z","shell.execute_reply":"2024-06-10T11:50:22.224387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_objects_in_image(1)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:50:22.228375Z","iopub.execute_input":"2024-06-10T11:50:22.228821Z","iopub.status.idle":"2024-06-10T11:52:49.812247Z","shell.execute_reply.started":"2024-06-10T11:50:22.228783Z","shell.execute_reply":"2024-06-10T11:52:49.810490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_image(2)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:52:49.814360Z","iopub.execute_input":"2024-06-10T11:52:49.814862Z","iopub.status.idle":"2024-06-10T11:52:50.190504Z","shell.execute_reply.started":"2024-06-10T11:52:49.814816Z","shell.execute_reply":"2024-06-10T11:52:50.188825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_objects_in_image(2)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:52:50.192345Z","iopub.execute_input":"2024-06-10T11:52:50.192775Z","iopub.status.idle":"2024-06-10T11:55:18.294744Z","shell.execute_reply.started":"2024-06-10T11:52:50.192735Z","shell.execute_reply":"2024-06-10T11:55:18.292211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_image(3)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:55:18.298660Z","iopub.execute_input":"2024-06-10T11:55:18.299687Z","iopub.status.idle":"2024-06-10T11:55:18.659154Z","shell.execute_reply.started":"2024-06-10T11:55:18.299629Z","shell.execute_reply":"2024-06-10T11:55:18.657351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_objects_in_image(3)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:55:18.661213Z","iopub.execute_input":"2024-06-10T11:55:18.661684Z","iopub.status.idle":"2024-06-10T11:57:46.546297Z","shell.execute_reply.started":"2024-06-10T11:55:18.661645Z","shell.execute_reply":"2024-06-10T11:57:46.544675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_image(4)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:57:46.548751Z","iopub.execute_input":"2024-06-10T11:57:46.549331Z","iopub.status.idle":"2024-06-10T11:57:46.892747Z","shell.execute_reply.started":"2024-06-10T11:57:46.549265Z","shell.execute_reply":"2024-06-10T11:57:46.891042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"detect_objects_in_image(4)","metadata":{"execution":{"iopub.status.busy":"2024-06-10T11:57:46.894950Z","iopub.execute_input":"2024-06-10T11:57:46.895490Z","iopub.status.idle":"2024-06-10T12:00:15.389829Z","shell.execute_reply.started":"2024-06-10T11:57:46.895443Z","shell.execute_reply":"2024-06-10T12:00:15.388389Z"},"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":"2024-06-10T12:00:15.391847Z","iopub.execute_input":"2024-06-10T12:00:15.392262Z","iopub.status.idle":"2024-06-10T12:25:22.339491Z","shell.execute_reply.started":"2024-06-10T12:00:15.392223Z","shell.execute_reply":"2024-06-10T12:25:22.334220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions_df = pd.DataFrame(predictions)\npredictions_df","metadata":{"execution":{"iopub.status.busy":"2024-06-10T12:25:22.349377Z","iopub.execute_input":"2024-06-10T12:25:22.349848Z","iopub.status.idle":"2024-06-10T12:25:22.471542Z","shell.execute_reply.started":"2024-06-10T12:25:22.349813Z","shell.execute_reply":"2024-06-10T12:25:22.469300Z"},"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":"2024-06-10T12:25:22.474500Z","iopub.execute_input":"2024-06-10T12:25:22.475167Z","iopub.status.idle":"2024-06-10T12:25:22.754202Z","shell.execute_reply.started":"2024-06-10T12:25:22.475108Z","shell.execute_reply":"2024-06-10T12:25:22.752601Z"},"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":"2024-06-10T12:25:22.756483Z","iopub.execute_input":"2024-06-10T12:25:22.757063Z","iopub.status.idle":"2024-06-10T12:25:23.279977Z","shell.execute_reply.started":"2024-06-10T12:25:22.757009Z","shell.execute_reply":"2024-06-10T12:25:23.278217Z"},"trusted":true},"execution_count":null,"outputs":[]}]}