{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import PIL.Image\n\n# these sys calls aren't actually necesarry in Kaggle notebooks, but you may need to add the data directory to your pythonpath to run the sample API off of Kaggle\nimport sys\nsys.path.append('../input/tensorflow-great-barrier-reef')   \n\nimport greatbarrierreef\nenv = greatbarrierreef.make_env()   # initialize the environment\niter_test = env.iter_test()    # an iterator which loops over the test set and sample submission","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-11-18T19:36:49.063881Z","iopub.execute_input":"2021-11-18T19:36:49.064783Z","iopub.status.idle":"2021-11-18T19:36:49.128579Z","shell.execute_reply.started":"2021-11-18T19:36:49.06466Z","shell.execute_reply":"2021-11-18T19:36:49.127797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The API will return one image per call as pixel array, and the relevant row from the sample prediction dataframe ","metadata":{}},{"cell_type":"code","source":"pixel_array, sample_prediction_df = next(iter_test)\npixel_array","metadata":{"execution":{"iopub.status.busy":"2021-11-18T19:36:49.130926Z","iopub.execute_input":"2021-11-18T19:36:49.131253Z","iopub.status.idle":"2021-11-18T19:36:49.432714Z","shell.execute_reply.started":"2021-11-18T19:36:49.131222Z","shell.execute_reply":"2021-11-18T19:36:49.431753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PIL.Image.fromarray(pixel_array)","metadata":{"execution":{"iopub.status.busy":"2021-11-18T19:36:49.43415Z","iopub.execute_input":"2021-11-18T19:36:49.43511Z","iopub.status.idle":"2021-11-18T19:36:50.030089Z","shell.execute_reply.started":"2021-11-18T19:36:49.435059Z","shell.execute_reply":"2021-11-18T19:36:50.028818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The sample prediction dataframe includes a valid default prediction that you will want to overwrite.","metadata":{}},{"cell_type":"code","source":"sample_prediction_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-18T19:36:50.032318Z","iopub.execute_input":"2021-11-18T19:36:50.033153Z","iopub.status.idle":"2021-11-18T19:36:50.049547Z","shell.execute_reply.started":"2021-11-18T19:36:50.033092Z","shell.execute_reply":"2021-11-18T19:36:50.048407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We have to register a prediction before we can get the next image.","metadata":{}},{"cell_type":"code","source":"env.predict(sample_prediction_df)  ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for (pixel_array, sample_prediction_df) in iter_test:  # iterate through all test set images\n    sample_prediction_df['annotations'] = '0.5 123 456 10 10'  # make your predictions here\n    env.predict(sample_prediction_df)   # register your predictions","metadata":{"execution":{"iopub.status.busy":"2021-11-18T19:55:17.950151Z","iopub.execute_input":"2021-11-18T19:55:17.950548Z","iopub.status.idle":"2021-11-18T19:55:18.022355Z","shell.execute_reply.started":"2021-11-18T19:55:17.950508Z","shell.execute_reply":"2021-11-18T19:55:18.021034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}