Skip to content

Commit

Permalink
update 0 predictions in tweetynet, fix error messages (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
sprestrelski authored Jun 30, 2023
1 parent b3e3e43 commit 4b27fa6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions PyHa/IsoAutio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ def generate_automated_labels_tweetynet(
except KeyboardInterrupt:
exit("Keyboard interrupt")
except BaseException:
checkVerbose("Failed to load" + audio_file, isolation_parameters)
checkVerbose("Failed to load " + audio_file, isolation_parameters)
continue

# Resample the audio if it isn't the normalized sample rate
Expand All @@ -1084,7 +1084,7 @@ def generate_automated_labels_tweetynet(
except KeyboardInterrupt:
exit("Keyboard interrupt")
except:
checkVerbose("Failed to Downsample" + audio_file, isolation_parameters)
checkVerbose("Failed to Downsample " + audio_file, isolation_parameters)

# convert stereo to mono if needed
# Might want to compare to just taking the first set of data.
Expand All @@ -1097,7 +1097,8 @@ def generate_automated_labels_tweetynet(
except KeyboardInterrupt:
exit("Keyboard interrupt")
except BaseException as e:
checkVerbose("Error in detection, skipping" + audio_file, isolation_parameters)
checkVerbose("Error in detection, skipping " + audio_file, isolation_parameters)
print(e)
continue

try:
Expand Down Expand Up @@ -1129,9 +1130,8 @@ def generate_automated_labels_tweetynet(
except KeyboardInterrupt:
exit("Keyboard interrupt")
except BaseException as e:

checkVerbose("Error in isolating bird calls from" + audio_file, isolation_parameters)

checkVerbose("Error in isolating bird calls from " + audio_file, isolation_parameters)
print(e)
continue
# Quick fix to indexing
annotations.reset_index(inplace=True, drop=True)
Expand Down
4 changes: 4 additions & 0 deletions PyHa/tweetynet_package/tweetynet/Load_data_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,13 @@ def predictions_to_kaleidoscope(predictions, SIGNAL, audio_dir, audio_file, manu
intermediary_df = pd.DataFrame({"OFFSET": offset, "DURATION": duration})
kaleidoscope_df = []

if offset.shape[0] == 0:
raise BaseException("No birds were detected!!")

if offset.iloc[0] != 0:
kaleidoscope_df.append(pd.DataFrame({"OFFSET": [0], "DURATION": [offset.iloc[0]]}))
kaleidoscope_df.append(intermediary_df[intermediary_df["DURATION"] >= 2*time_bin_seconds])

if offset.iloc[-1] < predictions.iloc[-1]["time_bins"]:
kaleidoscope_df.append(pd.DataFrame({"OFFSET": [offset.iloc[-1]], "DURATION": [predictions.iloc[-1]["time_bins"] +
predictions.iloc[1]["time_bins"]]}))
Expand Down
2 changes: 1 addition & 1 deletion PyHa/tweetynet_package/tweetynet/TweetyNetModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def predict(self, test_dataset, model_weights=None, norm=False):
self.model.eval()
local_score = []
dataiter = iter(test_data_loader)
_, label, uid = dataiter.next()
_, label, uid = next(dataiter)
time_bin = float(window_size)/label.shape[1]
st_time = np.array([time_bin*n for n in range(label.shape[1])])

Expand Down

0 comments on commit 4b27fa6

Please sign in to comment.