Aug-02-2017, 07:09 PM
Hello,
First of all, I am a total newbie by all means to python. I do know pascal (Delphi, Lazarus) but no experience of python at all.
I am using Windows 10 64bit. I have installed pyhton on my computer. I also installed numpy on my system to test below scripts.
I try to run a pyhton script that I got from a github repository. As this is being my first ever post. Forum is not allowing me to share links.
There are more than one file and more than one directory. Base directory structure is something like below:
Briefly, "pc_methods" mentioned in above error message is a directory that should be somehow imported in the initial script. But, I do not know how to do that.
Lastly, directory of pc_main includes a zero byte sized "__init__.py" file. I do not know what it does, just want to provide as much information as possible.
I do appreciate any help to get me running that script, please.
Thanks & regards,
Ertan
First of all, I am a total newbie by all means to python. I do know pascal (Delphi, Lazarus) but no experience of python at all.
I am using Windows 10 64bit. I have installed pyhton on my computer. I also installed numpy on my system to test below scripts.
I try to run a pyhton script that I got from a github repository. As this is being my first ever post. Forum is not allowing me to share links.
There are more than one file and more than one directory. Base directory structure is something like below:
C:\baby_cry_detection-master>dir
Volume in drive C has no label.
Volume Serial Number is 2E81-FCFE
Directory of C:\baby_cry_detection-master
19.04.2017 05:26 <DIR> .
19.04.2017 05:26 <DIR> ..
19.04.2017 05:26 1.072 .gitignore
19.04.2017 05:26 <DIR> data
11.05.2017 06:07 <DIR> pc_main
11.05.2017 06:07 <DIR> pc_methods
19.04.2017 05:26 1.081 README.md
19.04.2017 05:26 <DIR> rpi_main
19.04.2017 05:26 <DIR> rpi_methods
19.04.2017 05:26 1.170 run_crying_detection.sh
19.04.2017 05:26 588 setup.py
4 File(s) 3.911 bytes
7 Dir(s) 7.987.707.904 bytes free
C:\baby_cry_detection-master>I need to run several scripts before I can start using actual program. When I try to run very first script that I should be running, I get following error:C:\baby_cry_detection-master>python pc_main\train_set.py
Traceback (most recent call last):
File "pc_main\train_set.py", line 10, in <module>
from pc_methods import Reader
ModuleNotFoundError: No module named 'pc_methods'
C:\baby_cry_detection-master>train_set.py is not a big file and it includes following lines:C:\baby_cry_detection-master\pc_main>type train_set.py
# -*- coding: utf-8 -*-
import argparse
import os
import numpy as np
import logging
import re
import timeit
from pc_methods import Reader
from pc_methods.feature_engineer import FeatureEngineer
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--load_path',
default='%s/../data' % os.path.dirname(os.path.abspath(__file__)))
parser.add_argument('--save_path',
default='%s/../../output/dataset/' % os.path.dirname(os.path.abspath(__file__)))
parser.add_argument('--log_path',
default='%s/../' % os.path.dirname(os.path.abspath(__file__)))
# Arguments
args = parser.parse_args()
load_path = args.load_path
save_path = args.save_path
log_path = args.log_path
####################################################################################################################
# Set up logging
####################################################################################################################
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %I:%M:%S %p',
filename=os.path.join(log_path, 'logs_pc_methods_feat_eng.log'),
filemode='w',
level=logging.INFO)
####################################################################################################################
# READ FILES IN SUB-FOLDERS of load_path and FEATURE ENGINEERING
####################################################################################################################
# list load_path sub-folders
regex = re.compile(r'^[0-9]')
directory_list = [i for i in os.listdir(load_path) if regex.search(i)]
# initialize empty array for features
X = np.empty([1, 18])
# initialise empty array for labels
y = []
logging.info('Creating training set...')
start = timeit.default_timer()
# iteration on sub-folders
for directory in directory_list:
# Instantiate FeatureEngineer
feature_engineer = FeatureEngineer(label=directory)
file_list = os.listdir(os.path.join(load_path, directory))
# iteration on audio files in each sub-folder
for audio_file in file_list:
file_reader = Reader(os.path.join(load_path, directory, audio_file))
data, sample_rate = file_reader.read_audio_file()
avg_features, label = feature_engineer.feature_engineer(audio_data=data)
X = np.concatenate((X, avg_features), axis=0)
y.append(label)
# X.shape is (401, 18) as I'm not using indexing. First line is made of zeros and is to be removed
X = X[1:, :]
stop = timeit.default_timer()
logging.info('Time taken for reading files and feature engineering: {0}'.format(stop - start))
####################################################################################################################
# SAVE
####################################################################################################################
logging.info('Saving training set...')
# Save to numpy binary format
np.save(os.path.join(save_path, 'dataset.npy'), X)
np.save(os.path.join(save_path, 'labels.npy'), y)
logging.info('Saved! {0}'.format(os.path.join(save_path, 'dataset.npy')))
logging.info('Saved! {0}'.format(os.path.join(save_path, 'labels.npy')))
if __name__ == '__main__':
main()
C:\baby_cry_detection-master\pc_main>I have tried to contact developer, but she's using that code on Raspberry Pi and I am having problems on Windows. She tried to help, but I still cannot run the script. Our conversation is in the issues part of the repository (First post limitations, I cannot provide an url).Briefly, "pc_methods" mentioned in above error message is a directory that should be somehow imported in the initial script. But, I do not know how to do that.
Lastly, directory of pc_main includes a zero byte sized "__init__.py" file. I do not know what it does, just want to provide as much information as possible.
I do appreciate any help to get me running that script, please.
Thanks & regards,
Ertan
