{"cells":[{"metadata":{},"cell_type":"markdown","source":"quick_ml Official Website -> https://www.quickml.info"},{"metadata":{},"cell_type":"markdown","source":"## Summary -> <br>\nIn this notebook, we'll learn how to generated **Unlabeled TFRecords Dataset** using quick_ml. <br>\nUnlabeled TFRecords Dataset is usually needed for testing purposes. Unlike, Labeled TFRecords Dataset, Unlabeled TFRecords Dataset contains ids & images rather than labels & images. Let's delve into it."},{"metadata":{},"cell_type":"markdown","source":"### Installation"},{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2020-08-26T03:40:10.527479Z","iopub.status.busy":"2020-08-26T03:40:10.526657Z","iopub.status.idle":"2020-08-26T03:41:34.536868Z","shell.execute_reply":"2020-08-26T03:41:34.538772Z"},"papermill":{"duration":84.030963,"end_time":"2020-08-26T03:41:34.539706","exception":false,"start_time":"2020-08-26T03:40:10.508743","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"!pip install -q quick-ml","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"After successful installation, do necessary imports. Import tensorflow first, then quick_ml. <br>\nIf the execution was successful, an output message will be obtained which displays \"Tensorflow Successfully imported.\" along with the version number"},{"metadata":{"execution":{"iopub.execute_input":"2020-08-26T03:41:34.617429Z","iopub.status.busy":"2020-08-26T03:41:34.616015Z","iopub.status.idle":"2020-08-26T03:41:41.388579Z","shell.execute_reply":"2020-08-26T03:41:41.387363Z"},"papermill":{"duration":6.814381,"end_time":"2020-08-26T03:41:41.388788","exception":false,"start_time":"2020-08-26T03:41:34.574407","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"import tensorflow as tf\nimport quick_ml","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.013577,"end_time":"2020-08-26T03:41:41.420958","exception":false,"start_time":"2020-08-26T03:41:41.407381","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Obtain the dataset"},{"metadata":{"_kg_hide-output":true,"execution":{"iopub.execute_input":"2020-08-26T03:41:41.466476Z","iopub.status.busy":"2020-08-26T03:41:41.464262Z","iopub.status.idle":"2020-08-26T03:41:47.445478Z","shell.execute_reply":"2020-08-26T03:41:47.446109Z"},"papermill":{"duration":6.012224,"end_time":"2020-08-26T03:41:47.446275","exception":false,"start_time":"2020-08-26T03:41:41.434051","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"!unzip /kaggle/input/dogs-vs-cats/test1.zip","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Define where your dataset is located in the TEST_DIR variable"},{"metadata":{"execution":{"iopub.execute_input":"2020-08-26T03:41:47.603263Z","iopub.status.busy":"2020-08-26T03:41:47.6022Z","iopub.status.idle":"2020-08-26T03:41:47.605697Z","shell.execute_reply":"2020-08-26T03:41:47.604856Z"},"papermill":{"duration":0.082759,"end_time":"2020-08-26T03:41:47.605849","exception":false,"start_time":"2020-08-26T03:41:47.52309","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"TEST_DIR = '/kaggle/working/test1'","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"To generate unlabeled TFRecords Dataset, you need two things -> <br>\n* create_tfrecord_unlabeled\n* get_addrs_ids\n\n<br><br> create_tfrecord_unlabeled() generates Unlabeled TFRecord Dataset. However, we need to supply addresses & ids of the images. This is also taken care of by quick_ml using get_addrs_ids(). <br>\nVisit https://www.quickml.info/making-custom-datasets-tfrecords and scroll down to Unlabeled Data section to learn more."},{"metadata":{"execution":{"iopub.execute_input":"2020-08-26T03:41:47.754938Z","iopub.status.busy":"2020-08-26T03:41:47.753921Z","iopub.status.idle":"2020-08-26T03:41:47.756784Z","shell.execute_reply":"2020-08-26T03:41:47.757409Z"},"papermill":{"duration":0.079596,"end_time":"2020-08-26T03:41:47.75761","exception":false,"start_time":"2020-08-26T03:41:47.678014","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"from quick_ml.tfrecords_maker import create_tfrecord_unlabeled\n\nfrom quick_ml.tfrecords_maker import get_addrs_ids","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-08-26T03:41:47.903998Z","iopub.status.busy":"2020-08-26T03:41:47.902924Z","iopub.status.idle":"2020-08-26T03:41:47.973781Z","shell.execute_reply":"2020-08-26T03:41:47.973076Z"},"papermill":{"duration":0.145561,"end_time":"2020-08-26T03:41:47.973928","exception":false,"start_time":"2020-08-26T03:41:47.828367","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"addrs, ids = get_addrs_ids(TEST_DIR)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-08-26T03:41:48.12792Z","iopub.status.busy":"2020-08-26T03:41:48.127051Z","iopub.status.idle":"2020-08-26T03:42:28.344588Z","shell.execute_reply":"2020-08-26T03:42:28.343881Z"},"papermill":{"duration":40.295189,"end_time":"2020-08-26T03:42:28.344777","exception":false,"start_time":"2020-08-26T03:41:48.049588","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"unlabeled_dataset = create_tfrecord_unlabeled('test_cats_dogs_192x192.tfrecords', addrs, ids, IMAGE_SIZE = (192,192))","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.086436,"end_time":"2020-08-26T03:42:28.519724","exception":false,"start_time":"2020-08-26T03:42:28.433288","status":"completed"},"tags":[]},"cell_type":"markdown","source":"Saving the Unlabeled TFRecord Format ->  <br>\n            {\n\t\t\t'image' : tf.io.FixedLenFeature([], tf.string),\n\t\t\t'idnum' : tf.io.FixedLenFeature([], tf.string)\n\t\t\t}"},{"metadata":{"papermill":{"duration":0.087976,"end_time":"2020-08-26T03:42:28.694904","exception":false,"start_time":"2020-08-26T03:42:28.606928","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.095117,"end_time":"2020-08-26T03:42:28.879494","exception":false,"start_time":"2020-08-26T03:42:28.784377","status":"completed"},"tags":[]},"cell_type":"markdown","source":"## Visualize and Check the data"},{"metadata":{"execution":{"iopub.execute_input":"2020-08-26T03:42:29.112151Z","iopub.status.busy":"2020-08-26T03:42:29.110912Z","iopub.status.idle":"2020-08-26T03:42:29.114995Z","shell.execute_reply":"2020-08-26T03:42:29.114243Z"},"papermill":{"duration":0.112319,"end_time":"2020-08-26T03:42:29.115135","exception":false,"start_time":"2020-08-26T03:42:29.002816","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"from quick_ml.visualize_and_check_data import check_batch_and_ids","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.086372,"end_time":"2020-08-26T03:42:29.292129","exception":false,"start_time":"2020-08-26T03:42:29.205757","status":"completed"},"tags":[]},"cell_type":"markdown","source":"Now, to visualize the tfrecords made, we'll be reading the dataset. To read the dataset, we'll use get_unlabeled_tfrecords_format and pass the tfrecords format for unlabeled data in the variable 'dictionary_unlabeled' as a string along with another variable, IMAGE_SIZE."},{"metadata":{"execution":{"iopub.execute_input":"2020-08-26T03:42:29.470667Z","iopub.status.busy":"2020-08-26T03:42:29.469468Z","iopub.status.idle":"2020-08-26T03:42:29.473319Z","shell.execute_reply":"2020-08-26T03:42:29.472665Z"},"papermill":{"duration":0.095784,"end_time":"2020-08-26T03:42:29.473523","exception":false,"start_time":"2020-08-26T03:42:29.377739","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"dictionary_unlabeled = \"{ 'image' : tf.io.FixedLenFeature([], tf.string), 'idnum' : tf.io.FixedLenFeature([], tf.string) }\"\nIMAGE_SIZE = \"192,192\"\n\nfrom quick_ml.begin_tpu import get_unlabeled_tfrecord_format\n\nget_unlabeled_tfrecord_format(dictionary_unlabeled, IMAGE_SIZE)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-08-26T03:42:29.693253Z","iopub.status.busy":"2020-08-26T03:42:29.692303Z","iopub.status.idle":"2020-08-26T03:42:32.839768Z","shell.execute_reply":"2020-08-26T03:42:32.840373Z"},"papermill":{"duration":3.280489,"end_time":"2020-08-26T03:42:32.840569","exception":false,"start_time":"2020-08-26T03:42:29.56008","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"check_batch_and_ids('/kaggle/working/test_cats_dogs_192x192.tfrecords', 15, 3,5, (10,10))","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":1.988122,"end_time":"2020-08-26T03:42:34.920368","exception":false,"start_time":"2020-08-26T03:42:32.932246","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","papermill":{"duration":0.105173,"end_time":"2020-08-26T03:42:35.139263","exception":false,"start_time":"2020-08-26T03:42:35.03409","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}