Commit 61e9ad4d authored by Niels-Oliver Walkowski's avatar Niels-Oliver Walkowski
Browse files

ref(cls): Reformat code with black

parent 665c6629
......@@ -2,13 +2,14 @@
# -*- coding: utf-8 -*-
from dvt.core import DataExtraction, FrameInput
from dvt.abstract import FrameAnnotator
from dvt.utils import _proc_frame_list
from skimage.color import rgb2lab, lab2lch
import numpy as np
import pandas as pd
from numpy import histogram, mean, percentile
from numpy import histogram, mean, percentile, flatnonzero, isin
import ray
......@@ -17,6 +18,7 @@ from collections import defaultdict
from .corpus import Corpus
# TODO fps muss noch implementiert werden
def time2framenr(time, fps=4):
"""counts the frame index for a given timestamp
......@@ -146,7 +148,7 @@ def load_data(path):
class LchAnnotatorRay(FrameAnnotator):
name = 'lch'
name = "lch"
def __init__(self, **kwargs):
......@@ -200,9 +202,27 @@ class LchAnnotatorRay(FrameAnnotator):
lum_q2, chr_q2, hue_q2 = percentile(lch, 75, axis=0)
lum_q3, chr_q3, hue_q3 = percentile(lch, 75, axis=0)
lum_mean, chr_mean, hue_mean = mean(lch, axis=0)
# TODO Count of Outliers https://medium.com/datadriveninvestor/finding-outliers-in-dataset-using-python-efc3fce6ce32
return [f, lum_hist, lum_q1, lum_q2, lum_q3, lum_mean, chr_hist, chr_q1, chr_q2, chr_q3, chr_mean, hue_hist, hue_q1, hue_q2, hue_q3, hue_mean]
# TODO Count of Outliers https://medium.com/datadriveninvestor/
# finding-outliers-in-dataset-using-python-efc3fce6ce32
return [
f,
lum_hist,
lum_q1,
lum_q2,
lum_q3,
lum_mean,
chr_hist,
chr_q1,
chr_q2,
chr_q3,
chr_mean,
hue_hist,
hue_q1,
hue_q2,
hue_q3,
hue_mean,
]
def annotate(self, batch):
......@@ -214,29 +234,37 @@ class LchAnnotatorRay(FrameAnnotator):
ray_data = list()
# batch.fname und bnum bieten Info zu genauer Frame Nummer
futures = [self._count_lch.remote(batch.img[f, :, :, :], batch.fnames[f]) for f in frames] # img[i], weil auf gar keinen Fall für jeden Task der gesamte batch mitgegeben werden darf, sonst läuft der Speicher voll.
futures = [
self._count_lch.remote(batch.img[f, :, :, :], batch.fnames[f])
for f in frames
]
ray_data.append(ray.get(futures))
data = list(zip(*ray_data[0])) # [0], weil das eigentliche Ergebnis irgendwie 2 Listen enthält
output = {'frame': data[0],
'luminance_hist': data[1],
'luminance_q1': data[2],
'luminance_q2': data[3],
'luminance_q3': data[4],
'luminance_mean': data[5],
'chroma_hist': data[1],
'chroma_q1': data[2],
'chroma_q2': data[3],
'chroma_q3': data[4],
'chroma_mean': data[5],
'hue_hist': data[1],
'hue_q1': data[2],
'hue_q2': data[3],
'hue_q3': data[4],
'hue_mean': data[5]}
# Sicherstellen, dass nach jedem Lauf Speicher frei gegeben wird (ob das wirklich was macht ist unklar)
data = list(
zip(*ray_data[0])
) # [0], weil das eigentliche Ergebnis irgendwie 2 Listen enthält
output = {
"frame": data[0],
"luminance_hist": data[1],
"luminance_q1": data[2],
"luminance_q2": data[3],
"luminance_q3": data[4],
"luminance_mean": data[5],
"chroma_hist": data[1],
"chroma_q1": data[2],
"chroma_q2": data[3],
"chroma_q3": data[4],
"chroma_mean": data[5],
"hue_hist": data[1],
"hue_q1": data[2],
"hue_q2": data[3],
"hue_q3": data[4],
"hue_mean": data[5],
}
# Sicherstellen, dass nach jedem Lauf Speicher frei gegeben wird (ob
# das wirklich was macht ist unklar)
del futures
del ray_data
del data
......@@ -252,16 +280,20 @@ def get_lch_data(file, freq=10, bsize=256, max_batch=None):
file : str
The path of the video file
freq : int, optional
The frequency by which frames are taken into account for the analysis, by default 10
The frequency by which frames are taken into account for the analysis,
by default 10
bsize : int, optional
The size of the batch of frames that is passed to each parallel analysis task, by default 256
The size of the batch of frames that is passed to each parallel
analysis task, by default 256
max_batch : int, optional
Sets a limit to the number of batches that are analyzed, by default None
Sets a limit to the number of batches that are analyzed,
by default None
Returns
-------
pandas.DataFrame
A DataFrame containing the frame number histogram and quantiles for each Lch channel.
A DataFrame containing the frame number histogram and quantiles for
each Lch channel.
"""
# freq in Abhängigkeit von fps (3 Frames bei 30 fps)
......@@ -273,7 +305,7 @@ def get_lch_data(file, freq=10, bsize=256, max_batch=None):
ray.shutdown()
return extractor.get_data()['lch']
return extractor.get_data()["lch"]
# TODO fps Hilfsfunktion
\ No newline at end of file
# TODO fps Hilfsfunktion
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment