Skip to content

Commit e53cfa0

Browse files
authored
Merge pull request #1 from SchwarzNeuroconLab/dev
New Feature release!
2 parents f558599 + fe432a8 commit e53cfa0

26 files changed

+2343
-30
lines changed

DeepLabStream.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
import click
1919

2020
from utils.configloader import RESOLUTION, FRAMERATE, OUT_DIR, MODEL, MULTI_CAM, STACK_FRAMES, \
21-
ANIMALS_NUMBER, STREAMS, VIDEO
21+
ANIMALS_NUMBER, STREAMS, VIDEO, IPWEBCAM
2222
from utils.poser import load_deeplabcut, get_pose, find_local_peaks_new, calculate_skeletons
2323
from utils.plotter import plot_bodyparts, plot_metadata_frame
24-
from experiments.experiments import ExampleExperiment
2524

2625

2726
def create_video_files(directory, devices, resolution, framerate, codec):
@@ -132,6 +131,13 @@ def set_camera_manager():
132131
from utils.generic import VideoManager
133132
manager = VideoManager()
134133
return manager
134+
135+
elif IPWEBCAM:
136+
from utils.generic import WebCamManager
137+
manager = WebCamManager()
138+
return manager
139+
140+
135141
else:
136142
manager_list = []
137143
# loading realsense manager, if installed
@@ -430,15 +436,8 @@ def calculate_fps(self, current_analysis_time):
430436
##################
431437
@staticmethod
432438
def set_up_experiment():
433-
import importlib
434-
from utils.configloader import EXP_NAME
435-
mod = importlib.import_module('experiments.experiments')
436-
try:
437-
experiment_class = getattr(mod, EXP_NAME)
438-
experiment = experiment_class()
439-
except AttributeError:
440-
raise ValueError(f'Experiment: {EXP_NAME} not in experiments.py.')
441-
439+
from experiments.utils.exp_setup import setup_experiment
440+
experiment = setup_experiment()
442441
return experiment
443442

444443
def start_experiment(self):
@@ -519,9 +518,9 @@ def create_dataframes(self):
519518
Outputting dataframes to csv
520519
"""
521520
for num, camera in enumerate(self._data_output):
521+
print("Saving database for device {}".format(camera))
522522
df = pd.DataFrame(self._data_output[camera])
523523
df.index.name = 'Frame'
524-
print("Saving database for device {}".format(camera))
525524
df.to_csv(OUT_DIR + '/DataOutput{}'.format(camera) + '-' + time.strftime('%d%m%Y-%H%M%S') + '.csv', sep=';')
526525
print("Database saved")
527526

@@ -530,8 +529,10 @@ def create_dataframes(self):
530529
######
531530
@staticmethod
532531
def greetings():
532+
from utils.configloader import EXP_NAME, EXP_ORIGIN
533533
print("This is DeepLabStream")
534534
print("Developed by: Jens Schweihoff and Matvey Loshakov")
535+
print(f'Initializing {EXP_ORIGIN.lower()} experiment: {EXP_NAME}...')
535536

536537
def get_camera_manager(self):
537538
return self._camera_manager

Readme.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@ DeepLabStreams core feature is the real-time analysis using any type of camera-b
2525

2626
### 2. [How to use DLStream GUI](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/How-to-use-DLStream)
2727

28-
### 3. [Introduction to experiments](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/Introduction)
28+
### 3. Check out our [Out-of-the-Box](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/Out-Of-The-Box:-Overview)
2929

30-
### 4. [Design your first experiment](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/My-first-experiment)
30+
### 4. [Design an Out-of-the-Box Experiment](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/Out-Of-The-Box:-Design-Experiments)
3131

32-
### 5. [Adapting an existing experiment to your own needs](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/Adapting-an-existing-experiment-to-your-own-needs)
32+
### What's underneath?:
3333

34-
#### Check out our [Out-of-the-Box](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/Out-Of-The-Box:-What-Triggers-are-available%3F) section to get a good idea, what DLStream has in stock for your own experiments!
34+
### 5. [Introduction to experiments](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/Introduction)
35+
36+
### For advanced users:
37+
38+
### 6. [Design your first experiment](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/My-first-experiment)
39+
40+
### 7. [Adapting an existing experiment to your own needs](https://github.com/SchwarzNeuroconLab/DeepLabStream/wiki/Adapting-an-existing-experiment-to-your-own-needs)
41+
42+
3543

3644
### How to use DeepLabStream
3745

@@ -52,7 +60,7 @@ To start working with DeepLabStream, press the `Start Stream` button. It will ac
5260
After that you can `Start Analysis` to start DeepLabCut and receive a pose estimations for each frame, or, additionally, you can `Start Recording` to record a
5361
video of the current feed (visible in the stream window). You will see your current video timestamp (counted in frames) and FPS after you pressed the `Start Analysis` button.
5462

55-
![Analisys](https://user-images.githubusercontent.com/44863941/91173049-7ac34580-e6dd-11ea-80b6-ad56cb9cf22c.png)
63+
![Analysis](https://user-images.githubusercontent.com/44863941/91173049-7ac34580-e6dd-11ea-80b6-ad56cb9cf22c.png)
5664

5765
As you can see, we track three points that represent three body parts of the mouse - nose, neck and tail root.
5866
Every single frame where the animal was tracked is outputted to the dataframe, which would create a .csv file after the analysis is finished.

design_experiment.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
from experiments.utils.exp_setup import DlStreamConfigWriter
2+
import click
3+
4+
@click.command()
5+
@click.option('--default', 'default', is_flag=True)
6+
def design_experiment(default):
7+
config = DlStreamConfigWriter()
8+
input_dict = dict(EXPERIMENT = None,
9+
TRIGGER = None,
10+
PROCESS = None,
11+
STIMULATION = None)
12+
13+
def get_input(input_name):
14+
click.echo(f'Choosing {input_name}... \n Available {input_name}s are: ' + ', '.join(config.get_available_module_names(input_name)))
15+
input_value = click.prompt(f'Enter a base {input_name} module',type=str)
16+
while not config.check_if_default_exists(input_value,input_name):
17+
click.echo(f'{input_name} {input_value} does not exists.')
18+
input_value = click.prompt(f'Enter a base {input_name} module',type=str)
19+
return input_value
20+
"""Experiment"""
21+
22+
input_value = get_input('EXPERIMENT')
23+
input_dict['EXPERIMENT'] = input_value
24+
if input_value == 'BaseOptogeneticExperiment':
25+
input_dict['STIMULATION'] = 'BaseStimulation'
26+
input_dict['PROCESS'] = 'BaseProtocolProcess'
27+
28+
elif input_value == 'BaseTrialExperiment':
29+
click.echo(f'Available Triggers are: ' + ', '.join(config.get_available_module_names('TRIGGER')))
30+
click.echo('Note, that you cannot select the same Trigger as selected in TRIGGER.')
31+
32+
input_value = click.prompt(f'Enter TRIAL_TRIGGER for BaseTrialExperiment', type=str)
33+
while not config.check_if_default_exists(input_value, 'TRIGGER'):
34+
click.echo(f'TRIGGER {input_value} does not exists.')
35+
input_value = click.prompt(f'Enter a base TRIGGER module', type=str)
36+
37+
input_dict['TRIAL_TRIGGER'] = input_value
38+
click.echo(f'TRIAL_TRIGGER for BaseTrialExperiment set to {input_value}.')
39+
40+
"""TRIGGER"""
41+
42+
input_value = get_input('TRIGGER')
43+
input_dict['TRIGGER'] = input_value
44+
45+
46+
"""Process"""
47+
48+
if input_dict['PROCESS'] is None:
49+
input_value = get_input('PROCESS')
50+
input_dict['PROCESS'] = input_value
51+
52+
"""STIMULATION"""
53+
if input_dict['STIMULATION'] is None:
54+
input_value = get_input('STIMULATION')
55+
input_dict['STIMULATION'] = input_value
56+
57+
"""Setting Process Type"""
58+
59+
if input_dict['EXPERIMENT'] == 'BaseTrialExperiment':
60+
input_dict['PROCESS_TYPE'] = 'trial'
61+
elif input_dict['STIMULATION'] == 'BaseStimulation':
62+
input_dict['PROCESS_TYPE'] = 'switch'
63+
elif input_dict['STIMULATION'] == 'ScreenStimulation' or input_dict['STIMULATION'] == 'RewardDispenser':
64+
input_dict['PROCESS_TYPE'] = 'supply'
65+
66+
67+
if input_dict['EXPERIMENT'] == 'BaseTrialExperiment':
68+
config.import_default(experiment_name=input_dict['EXPERIMENT'], trigger_name=input_dict['TRIGGER'],
69+
process_name=input_dict['PROCESS'], stimulation_name=input_dict['STIMULATION'],
70+
trial_trigger_name=input_dict['TRIAL_TRIGGER'])
71+
72+
else:
73+
config.import_default(experiment_name=input_dict['EXPERIMENT'], trigger_name=input_dict['TRIGGER'],
74+
process_name=input_dict['PROCESS'], stimulation_name=input_dict['STIMULATION'])
75+
76+
if 'PROCESS_TYPE' in input_dict.keys():
77+
config._change_parameter(module_name=input_dict['PROCESS'],parameter_name='TYPE',
78+
parameter_value=input_dict['PROCESS_TYPE'])
79+
80+
81+
if click.confirm('Do you want to set parameters as well (Not recommended)? \n Note, that you can change them in the created file later.'):
82+
current_config = config.get_current_config()
83+
ignore_list = ['EXPERIMENT', 'BaseProtocolProcess']
84+
inner_ignore_list = ['EXPERIMENTER', 'PROCESS', 'STIMULATION', 'TRIGGER', 'DEBUG']
85+
try:
86+
for module in current_config.keys():
87+
parameter_dict = config.get_parameters(module)
88+
if module not in ignore_list:
89+
for input_key in parameter_dict.keys():
90+
if input_key not in inner_ignore_list:
91+
click.echo(f'Default {input_key} is: ' + str(parameter_dict[input_key]))
92+
input_value = click.prompt(f'Enter new value: ',type=str)
93+
config._change_parameter(module_name=module,parameter_name=input_key,
94+
parameter_value=input_value)
95+
except:
96+
click.echo('Failed to set individual parameters. Please change them later in the config file...')
97+
else:
98+
click.echo('Skipping parameters. Experiment config will be created with default values...')
99+
"""Finish up"""
100+
# Name of experimentor
101+
experimenter = click.prompt('Enter an experimenter name',type=str)
102+
click.echo(f'Experimenter set to {experimenter}.')
103+
config.set_experimenter(experimenter)
104+
105+
click.echo('Current modules are:\n BaseExperiment: {}\n Trigger: {}\n Process: {} \n Stimulation: {}'.format(
106+
input_dict['EXPERIMENT'],
107+
input_dict['TRIGGER'],
108+
input_dict['PROCESS'],
109+
input_dict['STIMULATION']))
110+
111+
112+
if click.confirm('Do you want to continue?'):
113+
config.write_ini()
114+
click.echo('Config was created. It can be found in experiments/configs')
115+
116+
117+
if __name__ == '__main__':
118+
design_experiment()

docs/design_experiment_gif.gif

472 KB
Loading

experiments/base/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)