Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tfhub object detection improvements #50

Merged
merged 37 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9f206df
Fix Colab's incompatibility w/ Pillow version
cfascina Dec 2, 2022
60682f5
Add %%capture to predict notebook
cfascina Dec 2, 2022
2eb2751
Implements os.path.basename() instead of slicing
cfascina Dec 2, 2022
88c0383
Removes auth key
cfascina Dec 2, 2022
86f5fe7
Adding os.path.basename()
cfascina Dec 5, 2022
e76f902
Improvements at base64 version
cfascina Dec 5, 2022
87fb250
Pillow version update at pip installations
cfascina Dec 5, 2022
d119076
Parallel processing improvements
cfascina Dec 14, 2022
cd3697f
Parallel processing improvements
cfascina Dec 14, 2022
38c45e8
Removes Verta's host from os environment
cfascina Dec 22, 2022
9be625a
Changes get_or_create_endpoint() to get_endpoint() on predict notebooks
cfascina Dec 22, 2022
c3e8c34
Removes Verta's host from os environment
cfascina Dec 22, 2022
eb70169
Removes debug=True parameter in Client()
cfascina Dec 22, 2022
2ae0635
Download images with wget to work at Colab
cfascina Dec 23, 2022
3ab791a
Remove zip() from executor.map() and adjust results DataFrame
cfascina Dec 23, 2022
15df682
Merges deploy/predict base64 notebooks
cfascina Dec 23, 2022
83e7005
Merges deploy/predict url notebooks and adjusts folder structure
cfascina Dec 23, 2022
0a0eee9
Update Colab's badges
cfascina Dec 23, 2022
fdb072f
Remove json dependency
cfascina Jan 2, 2023
a931b97
Cleaner code for results in dataframe
cfascina Jan 2, 2023
6c46a5d
Removes in-class print message
cfascina Jan 2, 2023
ecf5b5d
Changes at ModelAPI args
cfascina Jan 2, 2023
8e86a0d
Cleanup in Model class and ModelAPI code
cfascina Jan 2, 2023
8f7e5dd
Cleaner code for results in dataframe
cfascina Jan 2, 2023
e048490
Implements wget instead of urllib.request
cfascina Jan 2, 2023
534d7b2
Colab's tested NB
cfascina Jan 2, 2023
393c870
Colab's tested NB
cfascina Jan 2, 2023
cbe1260
Fix model playground.
cfascina Jan 2, 2023
66cc22e
Removes unnecessary methods param
cfascina Jan 3, 2023
8c642fd
Cleans code to get images urls
cfascina Jan 3, 2023
8625657
Changes at model describe()
cfascina Jan 3, 2023
19b1e50
Merge branch 'tfhub-object-detection-improvements' of https://github.…
cfascina Jan 3, 2023
222887e
Saves image after PIL operations
cfascina Jan 3, 2023
73a06c6
Changes predict() to accept lists
cfascina Jan 3, 2023
adb10b5
Model input as dict
cfascina Jan 5, 2023
1e08412
Fix example() dict key
cfascina Jan 5, 2023
89e1005
Remove unnecessary nesting at model predictions
cfascina Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deployment/tfhub/object-detection/base64/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env/
images/
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "99FgJuGtHbK-"
},
"source": [
"# Object Identification (TensorFlow Hub) - Base64 Images"
"# Object Detection - SSD Mobilenet V2 from TensorFlow Hub (Base64 Images)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"id": "aYVICIPxIqAM"
},
"source": [
"This notebook identifies whether a given object is present in a set of images. If the object is found, it returns a dataframe with the file name, score and bounding boxes.\n",
"We are using a dataset from [UCF](https://www.crcv.ucf.edu/data/GMCP_Geolocalization/#Dataset) that contains 62,058 high quality Google Street View images, and [TensorFlow Hub](https://www.tensorflow.org/hub), a library and platform for transfer learning."
"This model identifies objects present in images, returning its scores, labels and bounding boxes.\n",
"\n",
"We are using a dataset from [UCF](https://www.crcv.ucf.edu/data/GMCP_Geolocalization/#Dataset) and the model [SSD Mobilenet V2](https://tfhub.dev/google/openimages_v4/ssd/mobilenet_v2/1) from [TensorFlow Hub](https://www.tensorflow.org/hub)."
]
},
{
Expand All @@ -33,7 +38,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook has been tested with Python 3.10.6 and the following package versions:"
"This notebook has been tested with **Python 3.8.15** and the following package versions:"
]
},
{
Expand All @@ -42,8 +47,9 @@
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"!pip install dill==0.3.6\n",
"!pip install Pillow==9.3.0\n",
"!pip install Pillow==7.1.2\n",
"!pip install tensorflow==2.11.0\n",
"!pip install tensorflow-hub==0.12.0\n",
"!pip install verta==0.21.1\n",
Expand Down Expand Up @@ -111,8 +117,8 @@
" img_arr = np.array(Image.open(img_bytes), dtype=np.uint8)\n",
" img = Image.fromarray(img_arr)\n",
" img = ImageOps.grayscale(img)\n",
" img.thumbnail((width, height), Image.Resampling.LANCZOS)\n",
" img.save(path, format = 'JPEG', quality = 90)\n",
" img.thumbnail((width, height), Image.LANCZOS)\n",
" img.save(path)\n",
" \n",
" print(f\"Image downloaded to {path}.\")\n",
" return path\n",
Expand Down Expand Up @@ -179,38 +185,7 @@
" file, img_arr = data\n",
" result = self.detect_objects(file, img_arr)\n",
"\n",
" return result\n",
"\n",
" def describe(self):\n",
" \"\"\"Return a description of the service.\"\"\" \n",
" return {\n",
" \"method\": \"predict\",\n",
" \"args\": f\"{self.example()}\",\n",
" \"returns\": \"file, has_car, score, ymin, xmin, ymax, xmax\",\n",
" \"description\": \"\"\"\n",
" Identify whether a given object is present in the image, with its score and bounding boxes.\n",
" \"\"\",\n",
" \"input_description\": \"\"\"\n",
" A list with base64 images.\n",
" \"\"\",\n",
" \"output_description\": \"\"\"\n",
" A CSV file with information about all the processed images.\n",
" The columns presents the file names, if the object was found (boolean), its score and bounding boxes.\n",
" \"\"\"\n",
" }\n",
" \n",
" def example(self):\n",
" \"\"\"Return example input json-serializable data.\"\"\"\n",
" url = 'http://s3.amazonaws.com/verta-starter/street-view-images/000001_0.jpg'\n",
" file = url.split('/')[-1]\n",
" wget.download(url, file)\n",
"\n",
" with open(file, 'rb') as img:\n",
" img_bytes = base64.b64encode(img.read())\n",
" img_str = img_bytes.decode('utf-8')\n",
" img_str = json.dumps(img_str)\n",
" \n",
" return [\"000001_0.jpg\", img_str]"
" return result"
]
},
{
Expand Down Expand Up @@ -349,7 +324,7 @@
"source": [
"assert status['status'] == \"active\"\n",
"url = 'http://s3.amazonaws.com/verta-starter/street-view-images/000001_0.jpg'\n",
"file = url.split('/')[-1]\n",
"file = os.path.basename(url)\n",
"wget.download(url, file)\n",
"\n",
"with open(file, 'rb') as img:\n",
Expand All @@ -364,7 +339,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.8.15 ('.env': venv)",
"language": "python",
"name": "python3"
},
Expand All @@ -378,11 +353,11 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.8.15 (default, Oct 12 2022, 19:15:16) \n[GCC 11.2.0]"
},
"vscode": {
"interpreter": {
"hash": "2bb62b3221a3e8eb4d56ef3abf33b59c1166039d4d316f70559cb86bddd6b450"
"hash": "8fcee05e428355ba9289075b405db6efadfd667fc0be61680b205b2b303cc40a"
}
}
},
Expand Down
Loading