Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
postpop committed Jan 1, 2024
1 parent 67e7ce3 commit 440e73b
Show file tree
Hide file tree
Showing 50 changed files with 7,536 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
644 changes: 644 additions & 0 deletions docs/jupyter_execute/technical/cli.ipynb

Large diffs are not rendered by default.

1,125 changes: 1,125 additions & 0 deletions docs/jupyter_execute/tutorials/colab.ipynb

Large diffs are not rendered by default.

186 changes: 186 additions & 0 deletions docs/jupyter_execute/tutorials/continue_training.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import das.utils, das.data, das.train, das.io, das.evaluate, das.predict\n",
"from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint\n",
"import flammkuchen"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load the model\n",
"Change `model_savename` - if the model is saved at `res/20220601_103543_model.h5`, then `model_savename=\"res/20220601_103543\"`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model_savename = 'res/20220601_103543'\n",
"model, params = das.utils.load_model_and_params(model_savename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load the data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = das.io.load(params['data_dir'], x_suffix=params['x_suffix'], y_suffix=params['y_suffix'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Prep the data for tensorflow"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data_gen = das.data.AudioSequence(data['train']['x'],\n",
" data['train']['y'],\n",
" shuffle=True,\n",
" **params)\n",
"val_gen = das.data.AudioSequence(data['val']['x'],\n",
" data['val']['y'],\n",
" shuffle=False,\n",
" **params)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Prep callbacks\n",
"The new model will be saved to `model_savename + \"_continued_model.h5\"`, in our example \"res/20220601_103543_continued_model.h5\"."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"das.utils.save_params(params, model_savename + \"_continued\")\n",
"\n",
"checkpoint_save_name = model_savename + \"_continued_model.h5\" # this will overwrite intermediates from previous epochs\n",
"callbacks = [\n",
" ModelCheckpoint(checkpoint_save_name, save_best_only=True, save_weights_only=False, monitor='val_loss', verbose=1),\n",
" EarlyStopping(monitor='val_loss', patience=20, verbose=1),\n",
"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fit the model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fit_hist = model.fit(\n",
" data_gen,\n",
" epochs=params['nb_epoch'],\n",
" steps_per_epoch=min(len(data_gen), 100),\n",
" verbose=params['verbose'],\n",
" validation_data=val_gen,\n",
" callbacks=callbacks,\n",
" class_weight=params['class_weights'],\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test the model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f' Re-loading last best model from {checkpoint_save_name}.')\n",
"model.load_weights(checkpoint_save_name)\n",
"\n",
"print(' Predicting.')\n",
"x_test, y_test, y_pred = das.evaluate.evaluate_probabilities(x=data['test']['x'], y=data['test']['y'], model=model, params=params)\n",
"\n",
"labels_test = das.predict.labels_from_probabilities(y_test)\n",
"labels_pred = das.predict.labels_from_probabilities(y_pred)\n",
"\n",
"print(' Evaluating.')\n",
"conf_mat, report = das.evaluate.evaluate_segments(labels_test, labels_pred, params['class_names'], report_as_dict=True)\n",
"print(conf_mat)\n",
"print(report)\n",
"\n",
"save_filename = \"{0}_results.h5\".format(model_savename + \"_continued\")\n",
"print(f' Saving to {save_filename}.')\n",
"ddd = {\n",
" # 'fit_hist': fit_hist.history,\n",
" 'confusion_matrix': conf_mat,\n",
" 'classification_report': report,\n",
" 'x_test': x_test,\n",
" 'y_test': y_test,\n",
" 'y_pred': y_pred,\n",
" 'labels_test': labels_test,\n",
" 'labels_pred': labels_pred,\n",
" 'params': params,\n",
"}\n",
"flammkuchen.save(save_filename, ddd)"
]
}
],
"metadata": {
"interpreter": {
"hash": "7ea0ec616133ead53c1908c8f6539f5c0cb9b2f78368e2bb6ab3f847e89ca400"
},
"kernelspec": {
"display_name": "Python 3.9.9 ('base')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
822 changes: 822 additions & 0 deletions docs/jupyter_execute/tutorials/evaluate_bird.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 440e73b

Please sign in to comment.