Detectron2 run without GPU

If Detectron2 complains about wanting a GPU and finding no CUDA (because there’s none), the script can be set to CPU-only through the settings:

cfg.MODEL.DEVICE = 'cpu'

Detectron2 instances

I should read documentation more often: detectron2.structures — detectron2 0.3 documentation

  • They can be indexed as a mask:
      category_3_detections = instances[instances.pred_classes == 3]
      confident_detections = instances[instances.scores > 0.9]

In general about model outputs: Use Models — detectron2 0.3 documentation

Pytorch converting Tensor to floats

mytensor.numpy() is unsurprisingly easy.

Shapely prepared geometry operations

Shapely geometries can be processed into a state that supports more efficient batches of operations.

(The Shapely User Manual — Shapely 1.7.1 documentation)

Shapely find out if something is a multipolygon:

if joined_boxes.geom_type == 'MultiPolygon': is much cleaner than the isinstance(joined_boxes, MultiPolygon) I’ve been using!

Also - TODO - why is a Polygon that created a MultiPolygon within() it, if `within()..

Returns True if the object’s boundary and interior intersect only with the interior of the other (not its boundary or exterior).

Their boundary should touch, so shouldn’t be valid?

R-tree spatial indexing

Nice (and one of the only..) graphic explanation: R-tree Spatial Indexing with Python – Geoff Boeing

Shapely has a partial implementation: 1

Pass a list of geometry objects to the STRtree constructor to create a spatial index that you can query with another geometric object. Query-only means that once created, the STRtree is immutable.


tree = STRtree(all_geoms)
results = tree.query(query_geom)

In general if I’ll be working more with shapes I should hang out in GIS places to to absorb approaches and terminology. One of R-Tree’s use-cases is say “find restaurants inside this block” which can also be solved by blind iteration (but shouldn’t).

qutebrowser yank selection

Finally got the more familiar keybinding to work, as usual

config.bind('<Ctrl-Shift-C>', 'yank selection')`
config.bind(',y', 'yank selection')

Python dependencies list

johnnydep2 is really cool and visualizes the dependencies of something without installing them (but still downloads them!)

Trash and disk space

Found .local/share/Trash with 33Gb of ..trash in it.

Python dependencies wheel

A .whl file is just an archive, can be unzipped. The entire list of dependencies is in yourpackage.dist-info/METADATA, looks like this:

Requires-Python: >=3.6
Provides-Extra: all
Provides-Extra: dev
Requires-Dist: termcolor (>=1.1)
Requires-Dist: Pillow (>=7.1)