{ "cells": [ { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "from utils import *\n", "warnings.filterwarnings('ignore')\n", "%matplotlib inline\n" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "import ssl\n", "ssl._create_default_https_context = ssl._create_unverified_context" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "fd_collection = getCollection(\"team_5_mwdb_phase_2\", \"fd_collection\")\n" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "from tkinter.filedialog import askopenfilename\n", "import tkinter\n", "from torchvision.io import read_image\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## !feature extraction for full database!" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(3, 337, 510)\n", "(3, 325, 492)\n", "(3, 349, 528)\n", "(3, 360, 545)\n", "(3, 333, 504)\n", "(3, 316, 479)\n", "(3, 308, 466)\n", "(3, 358, 542)\n", "(3, 311, 471)\n", "(3, 341, 516)\n", "(3, 374, 566)\n", "(3, 325, 492)\n", "(3, 333, 504)\n", "(3, 308, 466)\n", "(3, 329, 498)\n", "(3, 311, 471)\n", "(3, 304, 461)\n", "(3, 323, 489)\n", "(3, 309, 468)\n", "(3, 309, 468)\n", "(3, 313, 473)\n", "(3, 339, 513)\n", "(3, 321, 487)\n", "(3, 362, 548)\n", "(3, 349, 528)\n", "(3, 362, 548)\n", "(3, 367, 555)\n", "(3, 331, 501)\n", "(3, 347, 525)\n", "(3, 318, 481)\n", "(3, 327, 495)\n", "(3, 360, 545)\n", "(3, 333, 504)\n", "(3, 351, 532)\n", "(3, 304, 461)\n", "(3, 313, 473)\n", "(3, 308, 466)\n", "(3, 295, 447)\n", "(3, 301, 456)\n", "(3, 313, 473)\n", "(3, 304, 461)\n", "(3, 303, 458)\n", "(3, 308, 466)\n", "(3, 318, 481)\n", "(3, 320, 484)\n", "(3, 418, 633)\n", "(3, 395, 598)\n", "(3, 424, 642)\n", "(3, 389, 589)\n", "(3, 412, 623)\n", "(3, 430, 652)\n", "(3, 384, 582)\n", "(3, 412, 623)\n", "(3, 409, 619)\n", "(3, 379, 574)\n", "(3, 418, 633)\n", "(3, 339, 513)\n", "(3, 295, 447)\n", "(3, 289, 437)\n", "(3, 349, 528)\n", "(3, 367, 555)\n", "(3, 313, 473)\n", "(3, 339, 513)\n", "(3, 276, 418)\n", "(3, 314, 476)\n", "(3, 335, 507)\n", "(3, 337, 510)\n", "(3, 333, 504)\n", "(3, 320, 484)\n", "(3, 325, 492)\n", "(3, 341, 516)\n", "(3, 318, 481)\n", "(3, 343, 519)\n", "(3, 325, 492)\n", "(3, 349, 528)\n", "(3, 339, 513)\n", "(3, 327, 495)\n", "(3, 339, 513)\n", "(3, 349, 528)\n", "(3, 444, 672)\n", "(3, 452, 685)\n", "(3, 468, 708)\n", "(3, 326, 494)\n", "(3, 326, 494)\n", "(3, 321, 485)\n", "(3, 341, 517)\n", "(3, 338, 511)\n", "(3, 334, 506)\n", "(3, 380, 576)\n", "(3, 293, 444)\n", "(3, 317, 481)\n", "(3, 322, 487)\n", "(3, 307, 465)\n", "(3, 317, 481)\n", "(3, 376, 569)\n", "(3, 358, 542)\n", "(3, 338, 511)\n", "(3, 358, 542)\n", "(3, 370, 561)\n", "(3, 393, 595)\n", "(3, 379, 574)\n", "(3, 363, 550)\n", "(3, 379, 574)\n", "(3, 367, 556)\n", "(3, 376, 569)\n", "(3, 379, 574)\n", "(3, 370, 561)\n", "(3, 320, 484)\n", "(3, 329, 499)\n", "(3, 322, 487)\n", "(3, 325, 492)\n", "(3, 305, 462)\n", "(3, 302, 458)\n", "(3, 326, 494)\n", "(3, 331, 501)\n", "(3, 298, 451)\n", "(3, 314, 476)\n", "(3, 347, 526)\n", "(3, 279, 423)\n", "(3, 317, 481)\n", "(3, 344, 520)\n", "(3, 345, 522)\n", "(3, 363, 550)\n", "(3, 369, 558)\n", "(3, 329, 499)\n", "(3, 373, 565)\n", "(3, 351, 532)\n", "(3, 382, 578)\n", "(3, 373, 565)\n", "(3, 359, 544)\n", "(3, 315, 477)\n", "(3, 316, 479)\n", "(3, 326, 494)\n", "(3, 290, 440)\n", "(3, 288, 436)\n", "(3, 316, 479)\n", "(3, 284, 431)\n", "(3, 301, 456)\n", "(3, 315, 477)\n", "(3, 299, 452)\n", "(3, 301, 456)\n", "(3, 304, 461)\n", "(3, 333, 504)\n", "(3, 344, 520)\n", "(3, 341, 517)\n", "(3, 316, 479)\n", "(3, 338, 511)\n", "(3, 324, 490)\n", "(3, 331, 501)\n", "(3, 332, 502)\n", "(3, 338, 511)\n", "(3, 334, 506)\n", "(3, 340, 515)\n", "(3, 307, 465)\n", "(3, 354, 536)\n", "(3, 293, 444)\n", "(3, 308, 467)\n", "(3, 331, 501)\n", "(3, 284, 431)\n", "(3, 300, 454)\n", "(3, 302, 458)\n", "(3, 345, 522)\n", "(3, 323, 489)\n", "(3, 349, 528)\n", "(3, 311, 471)\n", "(3, 320, 484)\n", "(3, 329, 499)\n", "(3, 360, 546)\n", "(3, 345, 522)\n", "(3, 339, 513)\n", "(3, 323, 489)\n", "(3, 317, 481)\n", "(3, 323, 489)\n", "(3, 300, 455)\n", "(3, 305, 462)\n", "(3, 322, 487)\n", "(3, 293, 444)\n", "(3, 292, 443)\n", "(3, 301, 456)\n", "(3, 317, 481)\n", "(3, 310, 470)\n", "(3, 301, 456)\n", "(3, 299, 452)\n", "(3, 291, 441)\n", "(3, 332, 502)\n", "(3, 283, 428)\n", "(3, 332, 502)\n", "(3, 318, 482)\n", "(3, 312, 473)\n", "(3, 314, 476)\n", "(3, 326, 494)\n", "(3, 326, 494)\n", "(3, 325, 492)\n", "(3, 334, 506)\n", "(3, 275, 417)\n", "(3, 279, 422)\n", "(3, 305, 462)\n", "(3, 334, 506)\n", "(3, 335, 508)\n", "(3, 335, 508)\n", "(3, 352, 534)\n", "(3, 324, 490)\n", "(3, 326, 494)\n", "(3, 326, 494)\n", "(3, 326, 494)\n", "(3, 324, 490)\n", "(3, 354, 536)\n", "(3, 332, 502)\n", "(3, 350, 530)\n", "(3, 329, 499)\n" ] }, { "ename": "OperationFailure", "evalue": "you are over your space quota, using 514 MB of 512 MB, full error: {'ok': 0, 'errmsg': 'you are over your space quota, using 514 MB of 512 MB', 'code': 8000, 'codeName': 'AtlasError'}", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mOperationFailure\u001b[0m Traceback (most recent call last)", "\u001b[1;32m/Users/pavanrathnakarshetty/Documents/Multimedia and Web Databases/Phase 2/CSE515_MWDB_Project/Phase 2/task_0.ipynb Cell 6\u001b[0m line \u001b[0;36m9\n\u001b[1;32m 6\u001b[0m image_fd \u001b[39m=\u001b[39m get_all_fd(idx)\n\u001b[1;32m 8\u001b[0m \u001b[39m# Store to collection (update if existing)\u001b[39;00m\n\u001b[0;32m----> 9\u001b[0m fd_collection\u001b[39m.\u001b[39;49mupdate_one(\n\u001b[1;32m 10\u001b[0m {\u001b[39m\"\u001b[39;49m\u001b[39mimage_id\u001b[39;49m\u001b[39m\"\u001b[39;49m: idx},\n\u001b[1;32m 11\u001b[0m {\u001b[39m\"\u001b[39;49m\u001b[39m$set\u001b[39;49m\u001b[39m\"\u001b[39;49m: image_fd},\n\u001b[1;32m 12\u001b[0m upsert\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m,\n\u001b[1;32m 13\u001b[0m )\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/collection.py:1088\u001b[0m, in \u001b[0;36mCollection.update_one\u001b[0;34m(self, filter, update, upsert, bypass_document_validation, collation, array_filters, hint, session, let, comment)\u001b[0m\n\u001b[1;32m 1084\u001b[0m common\u001b[39m.\u001b[39mvalidate_list_or_none(\u001b[39m\"\u001b[39m\u001b[39marray_filters\u001b[39m\u001b[39m\"\u001b[39m, array_filters)\n\u001b[1;32m 1086\u001b[0m write_concern \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_write_concern_for(session)\n\u001b[1;32m 1087\u001b[0m \u001b[39mreturn\u001b[39;00m UpdateResult(\n\u001b[0;32m-> 1088\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_update_retryable(\n\u001b[1;32m 1089\u001b[0m \u001b[39mfilter\u001b[39;49m,\n\u001b[1;32m 1090\u001b[0m update,\n\u001b[1;32m 1091\u001b[0m upsert,\n\u001b[1;32m 1092\u001b[0m write_concern\u001b[39m=\u001b[39;49mwrite_concern,\n\u001b[1;32m 1093\u001b[0m bypass_doc_val\u001b[39m=\u001b[39;49mbypass_document_validation,\n\u001b[1;32m 1094\u001b[0m collation\u001b[39m=\u001b[39;49mcollation,\n\u001b[1;32m 1095\u001b[0m array_filters\u001b[39m=\u001b[39;49marray_filters,\n\u001b[1;32m 1096\u001b[0m hint\u001b[39m=\u001b[39;49mhint,\n\u001b[1;32m 1097\u001b[0m session\u001b[39m=\u001b[39;49msession,\n\u001b[1;32m 1098\u001b[0m let\u001b[39m=\u001b[39;49mlet,\n\u001b[1;32m 1099\u001b[0m comment\u001b[39m=\u001b[39;49mcomment,\n\u001b[1;32m 1100\u001b[0m ),\n\u001b[1;32m 1101\u001b[0m write_concern\u001b[39m.\u001b[39macknowledged,\n\u001b[1;32m 1102\u001b[0m )\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/collection.py:883\u001b[0m, in \u001b[0;36mCollection._update_retryable\u001b[0;34m(self, criteria, document, upsert, multi, write_concern, op_id, ordered, bypass_doc_val, collation, array_filters, hint, session, let, comment)\u001b[0m\n\u001b[1;32m 861\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_update\u001b[39m(\n\u001b[1;32m 862\u001b[0m session: Optional[ClientSession], conn: Connection, retryable_write: \u001b[39mbool\u001b[39m\n\u001b[1;32m 863\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Optional[Mapping[\u001b[39mstr\u001b[39m, Any]]:\n\u001b[1;32m 864\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_update(\n\u001b[1;32m 865\u001b[0m conn,\n\u001b[1;32m 866\u001b[0m criteria,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 880\u001b[0m comment\u001b[39m=\u001b[39mcomment,\n\u001b[1;32m 881\u001b[0m )\n\u001b[0;32m--> 883\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__database\u001b[39m.\u001b[39;49mclient\u001b[39m.\u001b[39;49m_retryable_write(\n\u001b[1;32m 884\u001b[0m (write_concern \u001b[39mor\u001b[39;49;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mwrite_concern)\u001b[39m.\u001b[39;49macknowledged \u001b[39mand\u001b[39;49;00m \u001b[39mnot\u001b[39;49;00m multi, _update, session\n\u001b[1;32m 885\u001b[0m )\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/mongo_client.py:1568\u001b[0m, in \u001b[0;36mMongoClient._retryable_write\u001b[0;34m(self, retryable, func, session)\u001b[0m\n\u001b[1;32m 1566\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Internal retryable write helper.\"\"\"\u001b[39;00m\n\u001b[1;32m 1567\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_tmp_session(session) \u001b[39mas\u001b[39;00m s:\n\u001b[0;32m-> 1568\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_retry_with_session(retryable, func, s, \u001b[39mNone\u001b[39;49;00m)\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/mongo_client.py:1413\u001b[0m, in \u001b[0;36mMongoClient._retry_with_session\u001b[0;34m(self, retryable, func, session, bulk)\u001b[0m\n\u001b[1;32m 1403\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Execute an operation with at most one consecutive retries\u001b[39;00m\n\u001b[1;32m 1404\u001b[0m \n\u001b[1;32m 1405\u001b[0m \u001b[39mReturns func()'s return value on success. On error retries the same\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1408\u001b[0m \u001b[39mRe-raises any exception thrown by func().\u001b[39;00m\n\u001b[1;32m 1409\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 1410\u001b[0m retryable \u001b[39m=\u001b[39m \u001b[39mbool\u001b[39m(\n\u001b[1;32m 1411\u001b[0m retryable \u001b[39mand\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39moptions\u001b[39m.\u001b[39mretry_writes \u001b[39mand\u001b[39;00m session \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m session\u001b[39m.\u001b[39min_transaction\n\u001b[1;32m 1412\u001b[0m )\n\u001b[0;32m-> 1413\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_retry_internal(retryable, func, session, bulk)\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/_csot.py:108\u001b[0m, in \u001b[0;36mapply..csot_wrapper\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 106\u001b[0m \u001b[39mwith\u001b[39;00m _TimeoutContext(timeout):\n\u001b[1;32m 107\u001b[0m \u001b[39mreturn\u001b[39;00m func(\u001b[39mself\u001b[39m, \u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m--> 108\u001b[0m \u001b[39mreturn\u001b[39;00m func(\u001b[39mself\u001b[39;49m, \u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/mongo_client.py:1460\u001b[0m, in \u001b[0;36mMongoClient._retry_internal\u001b[0;34m(self, retryable, func, session, bulk)\u001b[0m\n\u001b[1;32m 1458\u001b[0m \u001b[39mraise\u001b[39;00m last_error\n\u001b[1;32m 1459\u001b[0m retryable \u001b[39m=\u001b[39m \u001b[39mFalse\u001b[39;00m\n\u001b[0;32m-> 1460\u001b[0m \u001b[39mreturn\u001b[39;00m func(session, conn, retryable)\n\u001b[1;32m 1461\u001b[0m \u001b[39mexcept\u001b[39;00m ServerSelectionTimeoutError:\n\u001b[1;32m 1462\u001b[0m \u001b[39mif\u001b[39;00m is_retrying():\n\u001b[1;32m 1463\u001b[0m \u001b[39m# The application may think the write was never attempted\u001b[39;00m\n\u001b[1;32m 1464\u001b[0m \u001b[39m# if we raise ServerSelectionTimeoutError on the retry\u001b[39;00m\n\u001b[1;32m 1465\u001b[0m \u001b[39m# attempt. Raise the original exception instead.\u001b[39;00m\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/collection.py:864\u001b[0m, in \u001b[0;36mCollection._update_retryable.._update\u001b[0;34m(session, conn, retryable_write)\u001b[0m\n\u001b[1;32m 861\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_update\u001b[39m(\n\u001b[1;32m 862\u001b[0m session: Optional[ClientSession], conn: Connection, retryable_write: \u001b[39mbool\u001b[39m\n\u001b[1;32m 863\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Optional[Mapping[\u001b[39mstr\u001b[39m, Any]]:\n\u001b[0;32m--> 864\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_update(\n\u001b[1;32m 865\u001b[0m conn,\n\u001b[1;32m 866\u001b[0m criteria,\n\u001b[1;32m 867\u001b[0m document,\n\u001b[1;32m 868\u001b[0m upsert\u001b[39m=\u001b[39;49mupsert,\n\u001b[1;32m 869\u001b[0m multi\u001b[39m=\u001b[39;49mmulti,\n\u001b[1;32m 870\u001b[0m write_concern\u001b[39m=\u001b[39;49mwrite_concern,\n\u001b[1;32m 871\u001b[0m op_id\u001b[39m=\u001b[39;49mop_id,\n\u001b[1;32m 872\u001b[0m ordered\u001b[39m=\u001b[39;49mordered,\n\u001b[1;32m 873\u001b[0m bypass_doc_val\u001b[39m=\u001b[39;49mbypass_doc_val,\n\u001b[1;32m 874\u001b[0m collation\u001b[39m=\u001b[39;49mcollation,\n\u001b[1;32m 875\u001b[0m array_filters\u001b[39m=\u001b[39;49marray_filters,\n\u001b[1;32m 876\u001b[0m hint\u001b[39m=\u001b[39;49mhint,\n\u001b[1;32m 877\u001b[0m session\u001b[39m=\u001b[39;49msession,\n\u001b[1;32m 878\u001b[0m retryable_write\u001b[39m=\u001b[39;49mretryable_write,\n\u001b[1;32m 879\u001b[0m let\u001b[39m=\u001b[39;49mlet,\n\u001b[1;32m 880\u001b[0m comment\u001b[39m=\u001b[39;49mcomment,\n\u001b[1;32m 881\u001b[0m )\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/collection.py:818\u001b[0m, in \u001b[0;36mCollection._update\u001b[0;34m(self, conn, criteria, document, upsert, multi, write_concern, op_id, ordered, bypass_doc_val, collation, array_filters, hint, session, retryable_write, let, comment)\u001b[0m\n\u001b[1;32m 814\u001b[0m command[\u001b[39m\"\u001b[39m\u001b[39mbypassDocumentValidation\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n\u001b[1;32m 816\u001b[0m \u001b[39m# The command result has to be published for APM unmodified\u001b[39;00m\n\u001b[1;32m 817\u001b[0m \u001b[39m# so we make a shallow copy here before adding updatedExisting.\u001b[39;00m\n\u001b[0;32m--> 818\u001b[0m result \u001b[39m=\u001b[39m conn\u001b[39m.\u001b[39;49mcommand(\n\u001b[1;32m 819\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__database\u001b[39m.\u001b[39;49mname,\n\u001b[1;32m 820\u001b[0m command,\n\u001b[1;32m 821\u001b[0m write_concern\u001b[39m=\u001b[39;49mwrite_concern,\n\u001b[1;32m 822\u001b[0m codec_options\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__write_response_codec_options,\n\u001b[1;32m 823\u001b[0m session\u001b[39m=\u001b[39;49msession,\n\u001b[1;32m 824\u001b[0m client\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m__database\u001b[39m.\u001b[39;49mclient,\n\u001b[1;32m 825\u001b[0m retryable_write\u001b[39m=\u001b[39;49mretryable_write,\n\u001b[1;32m 826\u001b[0m )\u001b[39m.\u001b[39mcopy()\n\u001b[1;32m 827\u001b[0m _check_write_command_response(result)\n\u001b[1;32m 828\u001b[0m \u001b[39m# Add the updatedExisting field for compatibility.\u001b[39;00m\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/helpers.py:315\u001b[0m, in \u001b[0;36m_handle_reauth..inner\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 312\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mpymongo\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mpool\u001b[39;00m \u001b[39mimport\u001b[39;00m Connection\n\u001b[1;32m 314\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 315\u001b[0m \u001b[39mreturn\u001b[39;00m func(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 316\u001b[0m \u001b[39mexcept\u001b[39;00m OperationFailure \u001b[39mas\u001b[39;00m exc:\n\u001b[1;32m 317\u001b[0m \u001b[39mif\u001b[39;00m no_reauth:\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/pool.py:932\u001b[0m, in \u001b[0;36mConnection.command\u001b[0;34m(self, dbname, spec, read_preference, codec_options, check, allowable_errors, read_concern, write_concern, parse_write_concern_error, collation, session, client, retryable_write, publish_events, user_fields, exhaust_allowed)\u001b[0m\n\u001b[1;32m 930\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_raise_if_not_writable(unacknowledged)\n\u001b[1;32m 931\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 932\u001b[0m \u001b[39mreturn\u001b[39;00m command(\n\u001b[1;32m 933\u001b[0m \u001b[39mself\u001b[39;49m,\n\u001b[1;32m 934\u001b[0m dbname,\n\u001b[1;32m 935\u001b[0m spec,\n\u001b[1;32m 936\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mis_mongos,\n\u001b[1;32m 937\u001b[0m read_preference,\n\u001b[1;32m 938\u001b[0m codec_options,\n\u001b[1;32m 939\u001b[0m session,\n\u001b[1;32m 940\u001b[0m client,\n\u001b[1;32m 941\u001b[0m check,\n\u001b[1;32m 942\u001b[0m allowable_errors,\n\u001b[1;32m 943\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49maddress,\n\u001b[1;32m 944\u001b[0m listeners,\n\u001b[1;32m 945\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mmax_bson_size,\n\u001b[1;32m 946\u001b[0m read_concern,\n\u001b[1;32m 947\u001b[0m parse_write_concern_error\u001b[39m=\u001b[39;49mparse_write_concern_error,\n\u001b[1;32m 948\u001b[0m collation\u001b[39m=\u001b[39;49mcollation,\n\u001b[1;32m 949\u001b[0m compression_ctx\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mcompression_context,\n\u001b[1;32m 950\u001b[0m use_op_msg\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mop_msg_enabled,\n\u001b[1;32m 951\u001b[0m unacknowledged\u001b[39m=\u001b[39;49munacknowledged,\n\u001b[1;32m 952\u001b[0m user_fields\u001b[39m=\u001b[39;49muser_fields,\n\u001b[1;32m 953\u001b[0m exhaust_allowed\u001b[39m=\u001b[39;49mexhaust_allowed,\n\u001b[1;32m 954\u001b[0m write_concern\u001b[39m=\u001b[39;49mwrite_concern,\n\u001b[1;32m 955\u001b[0m )\n\u001b[1;32m 956\u001b[0m \u001b[39mexcept\u001b[39;00m (OperationFailure, NotPrimaryError):\n\u001b[1;32m 957\u001b[0m \u001b[39mraise\u001b[39;00m\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/network.py:191\u001b[0m, in \u001b[0;36mcommand\u001b[0;34m(conn, dbname, spec, is_mongos, read_preference, codec_options, session, client, check, allowable_errors, address, listeners, max_bson_size, read_concern, parse_write_concern_error, collation, compression_ctx, use_op_msg, unacknowledged, user_fields, exhaust_allowed, write_concern)\u001b[0m\n\u001b[1;32m 189\u001b[0m client\u001b[39m.\u001b[39m_process_response(response_doc, session)\n\u001b[1;32m 190\u001b[0m \u001b[39mif\u001b[39;00m check:\n\u001b[0;32m--> 191\u001b[0m helpers\u001b[39m.\u001b[39;49m_check_command_response(\n\u001b[1;32m 192\u001b[0m response_doc,\n\u001b[1;32m 193\u001b[0m conn\u001b[39m.\u001b[39;49mmax_wire_version,\n\u001b[1;32m 194\u001b[0m allowable_errors,\n\u001b[1;32m 195\u001b[0m parse_write_concern_error\u001b[39m=\u001b[39;49mparse_write_concern_error,\n\u001b[1;32m 196\u001b[0m )\n\u001b[1;32m 197\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m exc:\n\u001b[1;32m 198\u001b[0m \u001b[39mif\u001b[39;00m publish:\n", "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pymongo/helpers.py:223\u001b[0m, in \u001b[0;36m_check_command_response\u001b[0;34m(response, max_wire_version, allowable_errors, parse_write_concern_error)\u001b[0m\n\u001b[1;32m 220\u001b[0m \u001b[39melif\u001b[39;00m code \u001b[39m==\u001b[39m \u001b[39m43\u001b[39m:\n\u001b[1;32m 221\u001b[0m \u001b[39mraise\u001b[39;00m CursorNotFound(errmsg, code, response, max_wire_version)\n\u001b[0;32m--> 223\u001b[0m \u001b[39mraise\u001b[39;00m OperationFailure(errmsg, code, response, max_wire_version)\n", "\u001b[0;31mOperationFailure\u001b[0m: you are over your space quota, using 514 MB of 512 MB, full error: {'ok': 0, 'errmsg': 'you are over your space quota, using 514 MB of 512 MB', 'code': 8000, 'codeName': 'AtlasError'}" ] } ], "source": [ "start = 0\n", "stop = len(dataset)\n", "step = 2 # even-numbered image IDs only\n", "\n", "for idx in range(start, stop, step):\n", " image_fd = get_all_fd(idx)\n", "\n", " # Store to collection (update if existing)\n", " fd_collection.update_one(\n", " {\"image_id\": idx},\n", " {\"$set\": image_fd},\n", " upsert=True,\n", " )\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get input as image ID (dataset) or from image file" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "invalid literal for int() with base 10: ''", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m/Users/pavanrathnakarshetty/Documents/Multimedia and Web Databases/Phase 2/CSE515_MWDB_Project/Phase 2/task_0.ipynb Cell 8\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> 1\u001b[0m selected_image_id \u001b[39m=\u001b[39m \u001b[39mint\u001b[39;49m(\n\u001b[1;32m 2\u001b[0m \u001b[39minput\u001b[39;49m(\u001b[39m\"\u001b[39;49m\u001b[39mEnter image ID: (-1 if you want to select an image file)\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n\u001b[1;32m 3\u001b[0m )\n\u001b[1;32m 4\u001b[0m \u001b[39mif\u001b[39;00m selected_image_id \u001b[39m==\u001b[39m \u001b[39m-\u001b[39m\u001b[39m1\u001b[39m:\n\u001b[1;32m 5\u001b[0m \u001b[39m# pick image and get label using tkinter\u001b[39;00m\n\u001b[1;32m 6\u001b[0m root \u001b[39m=\u001b[39m tkinter\u001b[39m.\u001b[39mTk()\n", "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: ''" ] } ], "source": [ "selected_image_id = int(\n", " input(\"Enter image ID: (-1 if you want to select an image file)\")\n", ")\n", "if selected_image_id == -1:\n", " # pick image and get label using tkinter\n", " root = tkinter.Tk()\n", " root.attributes(\"-topmost\", True)\n", " selected_image_path = askopenfilename(title=\"Select Image File\")\n", " root.withdraw()\n", " print(selected_image_path)\n", " sample_image = read_image(selected_image_path).div(255) # scale to [0,1] range\n", " sample_label = int(input(\"Enter image label number: (0 to 100)\"))\n", "else:\n", " # get image and label from dataset\n", " sample_image, sample_label = dataset[selected_image_id]\n", "\n", "# Show selected image\n", "plt.imshow(transforms.ToPILImage()(sample_image))\n", "plt.show()\n", "\n", "k = int(input(\"Enter value of k: \"))\n", "if k < 1:\n", " raise ValueError(\"k should be a positive integer\")\n", "\n", "selected_feature_model = valid_feature_models[\n", " str(input(\"Enter feature model - one of \" + str(list(valid_feature_models.keys()))))\n", "]\n", "\n", "selected_distance_measure = feature_distance_matches[selected_feature_model]\n", "\n", "if selected_image_id == -1:\n", " show_similar_images_for_image(\n", " fd_collection,\n", " -1,\n", " sample_image,\n", " sample_label,\n", " k,\n", " selected_feature_model,\n", " selected_distance_measure,\n", " save_plots=False,\n", " )\n", "else:\n", " show_similar_images_for_image(\n", " fd_collection,\n", " selected_image_id,\n", " None,\n", " None,\n", " k,\n", " selected_feature_model,\n", " selected_distance_measure,\n", " save_plots=False,\n", " )\n" ] }, { "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.11.5" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }