shruti_01
(Shruti Mittal)
September 23, 2019, 10:11am
1
I have a folder with many sub-folders. Each sub-folder has many .wav files. I need to extract the label for the filename of each .wav file.
Say, if the name is 32-45 -65-44.wav, I need to get 45 as the label.
a = AudioList.from_folder(name_of_folder)
func = lambda o: int(o.split('-')[1])
a.label_from_func(func)
I am using the above code, but this is throwing error - AttributeError: 'PosixPath' object has no attribute 'split'
juvian
(julian)
September 23, 2019, 10:44pm
2
Fastai uses PosixPath from pathlib so you can’t use split on that. You can either use one of the many methods available for them or just do str(o) to get the path as a string instead.
muellerzr
(Zachary Mueller)
September 23, 2019, 10:50pm
3
Look at how Lesson 1 pets is done. There’s a label_from_re (unsure if that’s in audio) where it does exactly that
1 Like
shruti_01
(Shruti Mittal)
September 24, 2019, 12:08pm
4
hey, couldn’t find label_from_re there.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lesson 1 - What's your pet"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Welcome to lesson 1! For those of you who are using a Jupyter Notebook for the first time, you can learn about this useful tool in a tutorial we prepared specially for you; click `File`->`Open` now and click `00_notebook_tutorial.ipynb`. \n",
"\n",
"In this lesson we will build our first image classifier from scratch, and see if we can achieve world-class results. Let's dive in!\n",
"\n",
"Every notebook starts with the following three lines; they ensure that any edits to libraries you make are reloaded here automatically, and also that any charts or images displayed are shown in this notebook."
]
},
This file has been truncated. show original
rohit_gr
(Rohit Gupta)
September 24, 2019, 2:05pm
5
str(o).split('-')[1]
will work.
1 Like