Skip to content

Commit

Permalink
add .quatro
Browse files Browse the repository at this point in the history
  • Loading branch information
thatgeeman committed Aug 15, 2023
1 parent 24b5e8f commit 8448958
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 23 deletions.
2 changes: 1 addition & 1 deletion _proc/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/.quarto/
# /.quarto/
1 change: 1 addition & 0 deletions _proc/.quarto/idx/00_anchor.ipynb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"Generate anchor boxes","markdown":{"yaml":{"description":"Methods to generate anchor boxes of different aspect ratios.","output-file":"anchor.html","title":"Generate anchor boxes"},"headingText":"Ground truth anchor boxes","containsRefs":false,"markdown":"\n\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nTo generate anchor boxes, we need three basic information:\n\n- Input image size, `image_sz`: To position our anchor boxes within the maximum \ncoordinates (`width`, `height`) of the image.\n- Feature map size, `feature_sz`: Feature map is the size (`width`, `height`) \nof the output of a convolutional operation. A $10\\times10$ feature map would mean \n$10\\times10$ local receptive field locations can be traced back into the \ninput image. These 100 receptive field locations ($10\\times10=100$) in the input image \nwould act as our initial anchor box candidates.\n\n![](https://ars.els-cdn.com/content/image/1-s2.0-S0925231217314169-gr4.jpg)\n\n- Aspect ratio of anchor boxes, `asp_ratio`: To generate anchor boxes with \ndifferent `width` to `height` ratio (default `asp_ratio=1`).\n\nUsually multiple anchor boxes with different `feature_sz` and `asp_ratio` are \nneeded. This requirement arises in the case of multiscale object detection.\n\nFor multiscale object detection, feature maps from different convolution \noperations of the network are used to trace back into the input image, to \ngenerate anchor boxes. \nThe [`bxs`](https://thatgeeman.github.io/pybx/anchor.html#bxs) method of `pybx` provides this possibility.\n\nAll methods work with asymetric `image_sz` (and or `feature_szs` as well):\n\nGround truth boxes are anchor boxes with maximum IOU with the true annotations.\n\nLoad actual annotations.\n\nConvert to MultiBx for convenience:\n\nGenerate anchor boxes for object detection task, given that we know: \n\n```py\nimage_sz = (256, 256) # to know the upper bounds of candidate bounding boxes\nfeature_sz = [20, 10, 8, 3]\nasp_ratio = [1, 0.5, 0.3]\n```\n\nStore coords as multibx for convenience.\n\nCan use the true annotations and anchor boxes to calulate the IOU.\n\nThe question: for each true label in the provided true annotations, what are the possible ground truth anchor boxes?\n\nImprove the loop to return only those with good IOU:\n\nNot very far from the original annotations. These scales and aspect ratios can also be read from the label. \nThe finer the anchor boxes, the better the starting positions (ground truth anchor boxes).\n\nIf anchor box labels are passed, they can be preserved instead of overwriting with ground truth labels.\n\nTrue annots can also be a list containing the label as the last item.\n\nMethod to also return just the max IOU ground truth boxes.\n\nCan also use methods for the box to calculate properties or convert to different box formats.\n"},"formats":{"html":{"execute":{"fig-width":7,"fig-height":5,"fig-format":"retina","fig-dpi":96,"df-print":"default","error":false,"eval":true,"cache":null,"freeze":false,"echo":true,"output":true,"warning":true,"include":true,"keep-md":false,"keep-ipynb":false,"ipynb":null,"enabled":false,"daemon":null,"daemon-restart":false,"debug":false,"ipynb-filters":[],"engine":"jupyter"},"render":{"keep-tex":false,"keep-source":false,"keep-hidden":false,"prefer-html":false,"output-divs":true,"output-ext":"html","fig-align":"default","fig-pos":null,"fig-env":null,"code-fold":"none","code-overflow":"scroll","code-link":false,"code-line-numbers":false,"code-tools":false,"tbl-colwidths":"auto","merge-includes":true,"latex-auto-mk":true,"latex-auto-install":true,"latex-clean":true,"latex-max-runs":10,"latex-makeindex":"makeindex","latex-makeindex-opts":[],"latex-tlmgr-opts":[],"latex-input-paths":[],"latex-output-dir":null,"link-external-icon":false,"link-external-newwindow":false,"self-contained-math":false,"format-resources":[]},"pandoc":{"standalone":true,"wrap":"none","default-image-extension":"png","to":"html","css":["styles.css"],"toc":true,"output-file":"anchor.html"},"language":{},"metadata":{"lang":"en","fig-responsive":true,"quarto-version":"1.2.184","theme":"cosmo","description":"Methods to generate anchor boxes of different aspect ratios.","title":"Generate anchor boxes"},"extensions":{"book":{"multiFile":true}}}}}
1 change: 1 addition & 0 deletions _proc/.quarto/idx/01_basics.ipynb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"Basic objects","markdown":{"yaml":{"description":"Basic object types and methods utilized in `pybx`","output-file":"basics.html","title":"Basic objects"},"headingText":"[`get_bx`](https://thatgeeman.github.io/pybx/basics.html#get_bx)","containsRefs":false,"markdown":"\n\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nAnchor box coordinates of type `list`/`dict`/`json`/`array` can be converted \nto a [`Bx`](https://thatgeeman.github.io/pybx/basics.html#bx) instance. Once wrapped as a [`Bx`](https://thatgeeman.github.io/pybx/basics.html#bx) instance, some interesting properties can\nbe calculated from the coordinates. \n\nInitializing an empty [`Bx`](https://thatgeeman.github.io/pybx/basics.html#bx) class. It does a whole lot of things!\n\nGenerate random coordinates for one anchor boxes.\n\nIf a single list is passed, [`Bx`](https://thatgeeman.github.io/pybx/basics.html#bx) will make it a list of list.\n\nSo the correct way to do it would be to pass a list of list.\n\nTo get normalized coordinates wrt to the image dimensions.\n\n[`Bx`](https://thatgeeman.github.io/pybx/basics.html#bx) is inherited by all other types in `pybx`: [`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx), [`MultiBx`](https://thatgeeman.github.io/pybx/basics.html#multibx), `ListBx`, `JsonBx`, exposing the same properties.\n\n[`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx) works with other types of coordinates too. \nIt accepts the coordinates and label for one anchor box in a `list` or `ndarray` \nformat.\n\nWorks with arrays and lists:\n\nCalling the `values` attribute returns the labels along with the coordinates.\n\n[`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx) also exposes a method to calculate the Intersection Over Union (IOU):\n\n[`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx) is also pseudo-iterable (calling an iterator returns `self` itself and not the coordinates or labels).\n\nWorking with multiple bounding boxes and annotaions is usually done with the help\nof [`MultiBx`](https://thatgeeman.github.io/pybx/basics.html#multibx). [`MultiBx`](https://thatgeeman.github.io/pybx/basics.html#multibx) allows iteration.\n\nGenerate random coordinates:\n\nAll annotations are stored as a [`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx) in a container called [`MultiBx`](https://thatgeeman.github.io/pybx/basics.html#multibx)\n\nEach index reveals the stored coordinate as a [`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx)\n\nThey can also be iterated:\n\nOr using list comprehension, properties of individual boxes can be extracted\n\nExtending [`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx) to also accept (`json`, `dict`) formatted coordinates and labels.\n\nAlso accepts keys (for the dict) as a list, otherwise uses `voc_keys`.\n\nMaking [`MultiBx`](https://thatgeeman.github.io/pybx/basics.html#multibx) work with lists with more than 4 items. It is a common practice\nto have the class label along with the coordinates. This classmethod is useful in such \nsituations\n\nInserting classmethod to process lists and dicts in [`MultiBx`](https://thatgeeman.github.io/pybx/basics.html#multibx).\n\nHow the class method works:\n\nChecking if it works with ndarrays\n\nAllowing [`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx) to process a single `dict` and `list` directly.\n\nRemember that [`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx) can only have one box coordinate and label at a time.\n\nWhat does [`make_single_iterable`](https://thatgeeman.github.io/pybx/ops.html#make_single_iterable) do? It converts a single list or dict of \ncoordinates into an iterable list that can be used by [`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx).\n\nThe class method makes it easier to directly call [`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx) without making the coordinates a list of list.\n\n\nWhen in doubt, use [`get_bx`](https://thatgeeman.github.io/pybx/basics.html#get_bx).\n\n[`get_bx`](https://thatgeeman.github.io/pybx/basics.html#get_bx) runs a bunch of if-else statements to call the right module when in doubt.\n\nEnabling stacking of different boxes.\n\nInternally this is what is done to stack them:\n\nAdding a [`MultiBx`](https://thatgeeman.github.io/pybx/basics.html#multibx) to a [`BaseBx`](https://thatgeeman.github.io/pybx/basics.html#basebx) makes the new set of coordinates a [`MultiBx`](https://thatgeeman.github.io/pybx/basics.html#multibx), so a [`BxViolation`](https://thatgeeman.github.io/pybx/excepts.html#bxviolation) warning is issued\nif this was not intended. \n\nTo avoid the [`BxViolation`](https://thatgeeman.github.io/pybx/excepts.html#bxviolation), use the method [`stack_bxs`](https://thatgeeman.github.io/pybx/basics.html#stack_bxs).\n"},"formats":{"html":{"execute":{"fig-width":7,"fig-height":5,"fig-format":"retina","fig-dpi":96,"df-print":"default","error":false,"eval":true,"cache":null,"freeze":false,"echo":true,"output":true,"warning":true,"include":true,"keep-md":false,"keep-ipynb":false,"ipynb":null,"enabled":false,"daemon":null,"daemon-restart":false,"debug":false,"ipynb-filters":[],"engine":"jupyter"},"render":{"keep-tex":false,"keep-source":false,"keep-hidden":false,"prefer-html":false,"output-divs":true,"output-ext":"html","fig-align":"default","fig-pos":null,"fig-env":null,"code-fold":"none","code-overflow":"scroll","code-link":false,"code-line-numbers":false,"code-tools":false,"tbl-colwidths":"auto","merge-includes":true,"latex-auto-mk":true,"latex-auto-install":true,"latex-clean":true,"latex-max-runs":10,"latex-makeindex":"makeindex","latex-makeindex-opts":[],"latex-tlmgr-opts":[],"latex-input-paths":[],"latex-output-dir":null,"link-external-icon":false,"link-external-newwindow":false,"self-contained-math":false,"format-resources":[]},"pandoc":{"standalone":true,"wrap":"none","default-image-extension":"png","to":"html","css":["styles.css"],"toc":true,"output-file":"basics.html"},"language":{},"metadata":{"lang":"en","fig-responsive":true,"quarto-version":"1.2.184","theme":"cosmo","description":"Basic object types and methods utilized in `pybx`","title":"Basic objects"},"extensions":{"book":{"multiFile":true}}}}}
1 change: 1 addition & 0 deletions _proc/.quarto/idx/02_utils.ipynb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"Utilities","markdown":{"yaml":{"description":"Utility functions used in `pybx` to calculate anchor boxes, among others.","output-file":"utils.html","title":"Utilities"},"containsRefs":false,"markdown":"\n\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nGenerate (`x_min`, `y_min`) corners.\n"},"formats":{"html":{"execute":{"fig-width":7,"fig-height":5,"fig-format":"retina","fig-dpi":96,"df-print":"default","error":false,"eval":true,"cache":null,"freeze":false,"echo":true,"output":true,"warning":true,"include":true,"keep-md":false,"keep-ipynb":false,"ipynb":null,"enabled":false,"daemon":null,"daemon-restart":false,"debug":false,"ipynb-filters":[],"engine":"jupyter"},"render":{"keep-tex":false,"keep-source":false,"keep-hidden":false,"prefer-html":false,"output-divs":true,"output-ext":"html","fig-align":"default","fig-pos":null,"fig-env":null,"code-fold":"none","code-overflow":"scroll","code-link":false,"code-line-numbers":false,"code-tools":false,"tbl-colwidths":"auto","merge-includes":true,"latex-auto-mk":true,"latex-auto-install":true,"latex-clean":true,"latex-max-runs":10,"latex-makeindex":"makeindex","latex-makeindex-opts":[],"latex-tlmgr-opts":[],"latex-input-paths":[],"latex-output-dir":null,"link-external-icon":false,"link-external-newwindow":false,"self-contained-math":false,"format-resources":[]},"pandoc":{"standalone":true,"wrap":"none","default-image-extension":"png","to":"html","css":["styles.css"],"toc":true,"output-file":"utils.html"},"language":{},"metadata":{"lang":"en","fig-responsive":true,"quarto-version":"1.2.184","theme":"cosmo","description":"Utility functions used in `pybx` to calculate anchor boxes, among others.","title":"Utilities"},"extensions":{"book":{"multiFile":true}}}}}
1 change: 1 addition & 0 deletions _proc/.quarto/idx/03_ops.ipynb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"Operations","markdown":{"yaml":{"description":"Operations with bounding box coordinates.","output-file":"ops.html","title":"Operations"},"containsRefs":false,"markdown":"\n\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n"},"formats":{"html":{"execute":{"fig-width":7,"fig-height":5,"fig-format":"retina","fig-dpi":96,"df-print":"default","error":false,"eval":true,"cache":null,"freeze":false,"echo":true,"output":true,"warning":true,"include":true,"keep-md":false,"keep-ipynb":false,"ipynb":null,"enabled":false,"daemon":null,"daemon-restart":false,"debug":false,"ipynb-filters":[],"engine":"jupyter"},"render":{"keep-tex":false,"keep-source":false,"keep-hidden":false,"prefer-html":false,"output-divs":true,"output-ext":"html","fig-align":"default","fig-pos":null,"fig-env":null,"code-fold":"none","code-overflow":"scroll","code-link":false,"code-line-numbers":false,"code-tools":false,"tbl-colwidths":"auto","merge-includes":true,"latex-auto-mk":true,"latex-auto-install":true,"latex-clean":true,"latex-max-runs":10,"latex-makeindex":"makeindex","latex-makeindex-opts":[],"latex-tlmgr-opts":[],"latex-input-paths":[],"latex-output-dir":null,"link-external-icon":false,"link-external-newwindow":false,"self-contained-math":false,"format-resources":[]},"pandoc":{"standalone":true,"wrap":"none","default-image-extension":"png","to":"html","css":["styles.css"],"toc":true,"output-file":"ops.html"},"language":{},"metadata":{"lang":"en","fig-responsive":true,"quarto-version":"1.2.184","theme":"cosmo","description":"Operations with bounding box coordinates.","title":"Operations"},"extensions":{"book":{"multiFile":true}}}}}
1 change: 1 addition & 0 deletions _proc/.quarto/idx/04_sample.ipynb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"Samples","markdown":{"yaml":{"description":"Methods to generate sample images (random noise) and load an image from disk.","output-file":"sample.html","title":"Samples"},"containsRefs":false,"markdown":"\n\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nRescale the annotations to match the new image size. Can individually process dicts.\n\nProcesses lists of dicts\n\nAlso works with lists with labels.\n"},"formats":{"html":{"execute":{"fig-width":7,"fig-height":5,"fig-format":"retina","fig-dpi":96,"df-print":"default","error":false,"eval":true,"cache":null,"freeze":false,"echo":true,"output":true,"warning":true,"include":true,"keep-md":false,"keep-ipynb":false,"ipynb":null,"enabled":false,"daemon":null,"daemon-restart":false,"debug":false,"ipynb-filters":[],"engine":"jupyter"},"render":{"keep-tex":false,"keep-source":false,"keep-hidden":false,"prefer-html":false,"output-divs":true,"output-ext":"html","fig-align":"default","fig-pos":null,"fig-env":null,"code-fold":"none","code-overflow":"scroll","code-link":false,"code-line-numbers":false,"code-tools":false,"tbl-colwidths":"auto","merge-includes":true,"latex-auto-mk":true,"latex-auto-install":true,"latex-clean":true,"latex-max-runs":10,"latex-makeindex":"makeindex","latex-makeindex-opts":[],"latex-tlmgr-opts":[],"latex-input-paths":[],"latex-output-dir":null,"link-external-icon":false,"link-external-newwindow":false,"self-contained-math":false,"format-resources":[]},"pandoc":{"standalone":true,"wrap":"none","default-image-extension":"png","to":"html","css":["styles.css"],"toc":true,"output-file":"sample.html"},"language":{},"metadata":{"lang":"en","fig-responsive":true,"quarto-version":"1.2.184","theme":"cosmo","description":"Methods to generate sample images (random noise) and load an image from disk.","title":"Samples"},"extensions":{"book":{"multiFile":true}}}}}
1 change: 1 addition & 0 deletions _proc/.quarto/idx/05_vis.ipynb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"Visualizations","markdown":{"yaml":{"description":"The `vis` module of `pybx` can be used to visualize these \"stacks\"","output-file":"vis.html","title":"Visualizations"},"headingText":"Loading from disk","containsRefs":false,"markdown":"\n\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nLoad a sample image from the data directory `../data/image.jpg` and resize to `(200, 200)`. Original image size is `(256, 256)`.\n\n`im` is the image of a clock and a frame, \n`ann` are the annotations for the image in json format, \n`lgt` are logits (activations from a layer) which can be displayed on top of the image, \n`clr` is a dict representing the colors to use for the different annotation keys.\n\nStore the annotations as a [`MultiBx`](https://thatgeeman.github.io/pybx/basics.html#multibx) object.\n\nDrawing random box by passing coordinates as a list.\n\nDrawing random box by passing coordinates as a list along with label.\n\nTo display the calculated anchor boxes or any other type of bounding\nboxes, `pybx` offers the `vis.VisBx` class.\nFirst, `vis.VisBx` initializes all the params for the image\nand loads its annotations (if available).\nUpon calling the `show()` method on the instantiated \n[`VisBx`](https://thatgeeman.github.io/pybx/vis.html#visbx) object with our \npredicted annotations or anchor boxes, everything \ngets displayed.\n\n### Display image array (default behaviour)\n\nTo display an image array (shape of `W, H, C`) directly, instead of \nloading from disk, pass an `ndarray`\nto the `image_arr` argument. If available, also provide the\n`annots` in any supported format. Displaying calculated anchors with a random image:\n\n### Load image and show annots\n\nDisplaying calculated anchors with a sample image. The original annotations are also rescaled to match the `image_sz`.\n\n### Customize colors\n\nTo customize the box colors, pass a dict `color` with the annotation name as key and color as value. In the example below an anchor box color is changed to red using its label `a_3x3_1.0_3` along with the annotations provided read from file.\n"},"formats":{"html":{"execute":{"fig-width":7,"fig-height":5,"fig-format":"retina","fig-dpi":96,"df-print":"default","error":false,"eval":true,"cache":null,"freeze":false,"echo":true,"output":true,"warning":true,"include":true,"keep-md":false,"keep-ipynb":false,"ipynb":null,"enabled":false,"daemon":null,"daemon-restart":false,"debug":false,"ipynb-filters":[],"engine":"jupyter"},"render":{"keep-tex":false,"keep-source":false,"keep-hidden":false,"prefer-html":false,"output-divs":true,"output-ext":"html","fig-align":"default","fig-pos":null,"fig-env":null,"code-fold":"none","code-overflow":"scroll","code-link":false,"code-line-numbers":false,"code-tools":false,"tbl-colwidths":"auto","merge-includes":true,"latex-auto-mk":true,"latex-auto-install":true,"latex-clean":true,"latex-max-runs":10,"latex-makeindex":"makeindex","latex-makeindex-opts":[],"latex-tlmgr-opts":[],"latex-input-paths":[],"latex-output-dir":null,"link-external-icon":false,"link-external-newwindow":false,"self-contained-math":false,"format-resources":[]},"pandoc":{"standalone":true,"wrap":"none","default-image-extension":"png","to":"html","css":["styles.css"],"toc":true,"output-file":"vis.html"},"language":{},"metadata":{"lang":"en","fig-responsive":true,"quarto-version":"1.2.184","theme":"cosmo","description":"The `vis` module of `pybx` can be used to visualize these \"stacks\"","title":"Visualizations"},"extensions":{"book":{"multiFile":true}}}}}
Loading

0 comments on commit 8448958

Please sign in to comment.