detect_chirps
Detect chirps on a spectrogram.
Timer
A simple timer class.
Source code in chirpdetector/detect_chirps.py
__enter__()
__exit__(exc_type, exc_value, traceback)
collect_specs(conf, data, t1)
Collect the spectrograms of a dataset.
Collec a batch of sum spectrograms of a certain length (e.g. 15 seconds) for a dataset subset (e.g. of 90 seconds) depending on the power of the GPU.
Parameters
conf
:Config
The configuration object.data
:Dataset
The gridtools dataset to detect chirps on.t1
:float
The start time of the dataset.
Returns
list
The spectrograms.list
The time axes of the spectrograms.list
The frequency axes of the spectrograms.
Source code in chirpdetector/detect_chirps.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
|
convert_model_output_to_df(outputs, threshold, spec_times, spec_freqs)
Convert the model output to a dataframe.
Parameters
outputs
:torch.Tensor
The output of the model.threshold
:float
The threshold for the detections.
Returns
pandas.DataFrame
The dataframe containing the bounding boxes.numpy.ndarray
The scores of the detections.
Source code in chirpdetector/detect_chirps.py
coords_to_mpl_rectangle(boxes)
Convert normal bounding box to matplotlib.pathes.Rectangle format.
Convert box defined by corner coordinates (x1, y1, x2, y2) to box defined by lower left, width and height (x1, y1, w, h).
The corner coordinates are the model output, but the center coordinates
are needed by the matplotlib.patches.Rectangle
object for plotting.
Parameters
boxes
:numpy.ndarray
The boxes to be converted.
Returns
numpy.ndarray
The converted boxes.
Source code in chirpdetector/detect_chirps.py
cut_spec_to_frequency_limits(spec, spec_freqs, flims)
Cut off everything outside the frequency limits.
Parameters
spec
:torch.Tensor
The spectrogram.spec_freqs
:numpy.ndarray
The frequency axis of the spectrogram.flims
:tuple[float, float]
The frequency limits.
Returns
torch.Tensor
The cut spectrogram.numpy.ndarray
The cut frequency axis.
Source code in chirpdetector/detect_chirps.py
detect_chirps(conf, data)
Detect chirps on a spectrogram.
Parameters
conf
:Config
The configuration object.data
:Dataset
The gridtools dataset to detect chirps on.
Returns
None
Source code in chirpdetector/detect_chirps.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
|
detect_cli(input_path)
Terminal interface for the detection function.
Parameters
path
:str
Returns
None
Source code in chirpdetector/detect_chirps.py
float_index_interpolation(values, index_arr, data_arr)
Convert float indices to values by linear interpolation.
Interpolates a set of float indices within the given index array to obtain corresponding values from the data array using linear interpolation.
Given a set of float indices (values
), this function determines
the corresponding values in the data_arr
by linearly interpolating
between adjacent indices in the index_arr
. Linear interpolation
involves calculating weighted averages based on the fractional
parts of the float indices.
This function is useful to transform float coordinates on a spectrogram matrix to the corresponding time and frequency values. The reason for this is, that the model outputs bounding boxes in float coordinates, i.e. it does not care about the exact pixel location of the bounding box.
Parameters
values
:np.ndarray
The index value as a float that should be interpolated.index_arr
:numpy.ndarray
The array of indices on the data array.data_arr
:numpy.ndarray
The array of data.
Returns
numpy.ndarray
The interpolated value.
Raises
ValueError
If any of the input float indices (values
) are outside the range of the providedindex_arr
.
Examples
values = np.array([2.5, 3.2, 4.8]) index_arr = np.array([2, 3, 4, 5]) data_arr = np.array([10, 15, 20, 25]) result = float_index_interpolation(values, index_arr, data_arr) print(result) array([12.5, 16. , 22.5])
Source code in chirpdetector/detect_chirps.py
handle_dataframes(bbox_dfs, output_path)
Handle concatenation and saving of dataframes.
Parameters
bbox_dfs
:list[pandas.DataFrame]
The list of dataframes to concatenate.output_path
:pathlib.Path
The path to save the dataframe to.
Returns
None
Source code in chirpdetector/detect_chirps.py
pixel_bbox_to_time_frequency(bbox_df, spec_times, spec_freqs)
Convert pixel coordinates to time and frequency.
Parameters
bbox_df
:pandas.DataFrame
The dataframe containing the bounding boxes.spec_times
:numpy.ndarray
The time axis of the spectrogram.spec_freqs
:numpy.ndarray
The frequency axis of the spectrogram.
Returns
pandas.DataFrame
The dataframe with the converted bounding boxes.
Source code in chirpdetector/detect_chirps.py
plot_detections(img_tensor, output, threshold, save_path, conf)
Plot the detections on the spectrogram.
Parameters
img_tensor
:torch.Tensor
The spectrogram.output
:torch.Tensor
The output of the model.threshold
:float
The threshold for the detections.save_path
:pathlib.Path
The path to save the plot to.conf
:Config
The configuration object.
Returns
None
Source code in chirpdetector/detect_chirps.py
spec_to_image(spec)
Convert a spectrogram to an image.
Add 3 color channels, normalize to 0-1, etc.
Parameters
spec
:torch.Tensor
Returns
torch.Tensor