Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
pjyazdian authored Feb 7, 2024
1 parent f2b6d52 commit d29472c
Show file tree
Hide file tree
Showing 6 changed files with 642 additions and 644 deletions.
122 changes: 61 additions & 61 deletions scripts/utils/Unityfier.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
"""This file converts transcript to a txt file that can be read by the unity.
This script is meant to be run separately.
This file expects JSON files. jsons_path variable must be manually changed to the appropriate directory.
The expected structure of the original JSON file is as follow:
Subtitles are expected to be contained in a JSON file with the format:
{
'alternative':
[]: # only the first element contains the following:
{
'words': [
{
'start_time': '0.100s',
'end_time': '0.500s',
'word': 'really'
},
{ <contains more of these structured elements> }
],
<other data>
}
}
Note: JSON uses double-quotes instead of single-quotes. Single quotes are used for doc-string reasons.
The files are saved in a new folder in the jsons_path directory named 'Unity'.
"""


import glob
import os
from data_utils import SubtitleWrapper

jsons_path = "/local-scratch/pjomeyaz/GENEA_DATASET/trinityspeechgesture.scss.tcd.ie/data/GENEA_Challenge_2020_data_release/Test_data/Transcripts"

json_output_path = jsons_path + "/Unity"
if not os.path.exists(json_output_path):
os.makedirs(json_output_path)


json_files = sorted(glob.glob(jsons_path + "/*.json"))


for jfile in json_files:
name = os.path.split(jfile)[1][:-5]
print(name)

subtitle = SubtitleWrapper(jfile).get()
str_subtitle = ""
for word_boundle in subtitle:
start_time = word_boundle["start_time"][:-1] # Removing 's'
end_time = word_boundle["end_time"][:-1] # Removing 's'
word = word_boundle["word"]
str_subtitle += "{},{},{}\n".format(start_time, end_time, word)

str_subtitle = str_subtitle[:-1]

file2write = open(json_output_path + "/" + name + ".txt", "w")
file2write.write(str_subtitle)
file2write.flush()
file2write.close()

print()
"""This file converts transcript to a txt file that can be read by the unity.
This script is meant to be run separately.
This file expects JSON files. jsons_path variable must be manually changed to the appropriate directory.
The expected structure of the original JSON file is as follow:
Subtitles are expected to be contained in a JSON file with the format:
{
'alternative':
[]: # only the first element contains the following:
{
'words': [
{
'start_time': '0.100s',
'end_time': '0.500s',
'word': 'really'
},
{ <contains more of these structured elements> }
],
<other data>
}
}
Note: JSON uses double-quotes instead of single-quotes. Single quotes are used for doc-string reasons.
The files are saved in a new folder in the jsons_path directory named 'Unity'.
"""


import glob
import os
from data_utils import SubtitleWrapper

jsons_path = "/local-scratch/pjomeyaz/GENEA_DATASET/trinityspeechgesture.scss.tcd.ie/data/GENEA_Challenge_2020_data_release/Test_data/Transcripts"

json_output_path = jsons_path + "/Unity"
if not os.path.exists(json_output_path):
os.makedirs(json_output_path)


json_files = sorted(glob.glob(jsons_path + "/*.json"))


for jfile in json_files:
name = os.path.split(jfile)[1][:-5]
print(name)

subtitle = SubtitleWrapper(jfile).get()
str_subtitle = ""
for word_boundle in subtitle:
start_time = word_boundle["start_time"][:-1] # Removing 's'
end_time = word_boundle["end_time"][:-1] # Removing 's'
word = word_boundle["word"]
str_subtitle += "{},{},{}\n".format(start_time, end_time, word)

str_subtitle = str_subtitle[:-1]

file2write = open(json_output_path + "/" + name + ".txt", "w")
file2write.write(str_subtitle)
file2write.flush()
file2write.close()

print()
126 changes: 63 additions & 63 deletions scripts/utils/average_meter.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
"""Class to hold average and current values (such as loss values).
Typical usage example:
l = AverageMeter('autoencoder_loss')
l.update(2.33)
"""


class AverageMeter(object):
"""Computes and stores the average and current value (such as loss values).
Attributes:
name: A string for the name for an instance of this object.
fmt: A string that acts as a formatting value during printing (ex. :f).
val: A float that is the most current value to be processed.
avg: A float average value calculated using the most recent sum and count values.
sum: A float running total that has been processed.
count: An integer count of the number of times that val has been updated.
"""

def __init__(self, name: str, fmt: str = ":f"):
"""Initialization method.
Args:
name: The string name for an instance of this object.
fmt: A string formatting value during printing (ex. :f).
"""
self.name = name
self.fmt = fmt
self.reset()

def reset(self) -> None:
"""Reset all numerical attributes in this object.
Modifies internal state of this object.
"""
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0

def update(self, val: float, n: int = 1) -> None:
"""Updates the numerical attributes in this object with the provided value and count.
Modifies internal state of this object.
Args:
val: A float value to be used to update the calculations.
n: A custom count value (default value is 1).
"""
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count

def __str__(self) -> str:
"""Print a custom formatted string with the val and avg values.
Returns:
The custom format string.
"""
fmtstr = "{name} {val" + self.fmt + "} ({avg" + self.fmt + "})"
return fmtstr.format(**self.__dict__)
"""Class to hold average and current values (such as loss values).
Typical usage example:
l = AverageMeter('autoencoder_loss')
l.update(2.33)
"""


class AverageMeter(object):
"""Computes and stores the average and current value (such as loss values).
Attributes:
name: A string for the name for an instance of this object.
fmt: A string that acts as a formatting value during printing (ex. :f).
val: A float that is the most current value to be processed.
avg: A float average value calculated using the most recent sum and count values.
sum: A float running total that has been processed.
count: An integer count of the number of times that val has been updated.
"""

def __init__(self, name: str, fmt: str = ":f"):
"""Initialization method.
Args:
name: The string name for an instance of this object.
fmt: A string formatting value during printing (ex. :f).
"""
self.name = name
self.fmt = fmt
self.reset()

def reset(self) -> None:
"""Reset all numerical attributes in this object.
Modifies internal state of this object.
"""
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0

def update(self, val: float, n: int = 1) -> None:
"""Updates the numerical attributes in this object with the provided value and count.
Modifies internal state of this object.
Args:
val: A float value to be used to update the calculations.
n: A custom count value (default value is 1).
"""
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count

def __str__(self) -> str:
"""Print a custom formatted string with the val and avg values.
Returns:
The custom format string.
"""
fmtstr = "{name} {val" + self.fmt + "} ({avg" + self.fmt + "})"
return fmtstr.format(**self.__dict__)
Loading

0 comments on commit d29472c

Please sign in to comment.