Skip to content

Commit

Permalink
Updated tempKeypoint.py
Browse files Browse the repository at this point in the history
Description:
- Removed large and cache files πŸ“‚
- Added a loadbar βŒ›
- Added gitignore πŸ₯Έ
  • Loading branch information
HlexNC committed Jul 6, 2023
1 parent faf5102 commit ee40931
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 74,436 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Large File Storage ###
./Yolov8/yolov8n-pose.pt
./Yolov8/yolov8n-seg.pt
./Yolov8/yolov8n.pt
*.csv
*.mp4

### Python Files ###
Yolov8/.idea/
__pycache__/

### VS Code ###
.vscode/
74,375 changes: 0 additions & 74,375 deletions Yolov8/keypoints_output.csv

Large diffs are not rendered by default.

65 changes: 32 additions & 33 deletions Yolov8/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
absl-py==1.4.0
appnope @ file:///home/conda/feedstock_root/build_artifacts/appnope_1649077682618/work
asttokens @ file:///home/conda/feedstock_root/build_artifacts/asttokens_1670263926556/work
backcall @ file:///home/conda/feedstock_root/build_artifacts/backcall_1592338393461/work
backports.functools-lru-cache @ file:///home/conda/feedstock_root/build_artifacts/backports.functools_lru_cache_1618230623929/work
appnope
asttokens
backcall
backports.functools-lru-cache
beautifulsoup4==4.12.2
cachetools==5.3.0
certifi==2022.12.7
charset-normalizer==3.1.0
contourpy==1.0.7
cycler==0.11.0
debugpy @ file:///Users/builder/miniconda3/envs/prefect/conda-bld/debugpy_1637092214173/work
decorator @ file:///home/conda/feedstock_root/build_artifacts/decorator_1641555617451/work
dlib==19.24.1
debugpy
decorator
easydict==1.10
entrypoints @ file:///home/conda/feedstock_root/build_artifacts/entrypoints_1643888246732/work
executing @ file:///home/conda/feedstock_root/build_artifacts/executing_1667317341051/work
entrypoints
executing
filelock==3.12.0
filterpy==1.4.5
fonttools==4.39.3
Expand All @@ -28,60 +27,60 @@ idna==3.4
imageio==2.28.1
importlib-metadata==6.6.0
importlib-resources==5.12.0
ipykernel @ file:///Users/runner/miniforge3/conda-bld/ipykernel_1655369698656/work
ipython @ file:///Users/runner/miniforge3/conda-bld/ipython_1683226209954/work
jedi @ file:///home/conda/feedstock_root/build_artifacts/jedi_1669134318875/work
ipykernel
ipython
jedi
Jinja2==3.1.2
jupyter-client @ file:///home/conda/feedstock_root/build_artifacts/jupyter_client_1654730843242/work
jupyter_core @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_d1sy1hlz9t/croot/jupyter_core_1679906585151/work
jupyter-client
jupyter_core
kiwisolver==1.4.4
lap==0.4.0
lazy_loader==0.2
Markdown==3.4.3
MarkupSafe==2.1.2
matplotlib==3.7.1
matplotlib-inline @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-inline_1660814786464/work
matplotlib-inline
mpmath==1.3.0
nest-asyncio @ file:///home/conda/feedstock_root/build_artifacts/nest-asyncio_1664684991461/work
nest-asyncio
networkx==3.1
numpy==1.23.1
oauthlib==3.2.2
onnx==1.14.0
opencv-python==4.7.0.72
packaging @ file:///home/conda/feedstock_root/build_artifacts/packaging_1681337016113/work
packaging
pafy==0.5.5
pandas==2.0.1
parso @ file:///home/conda/feedstock_root/build_artifacts/parso_1638334955874/work
pexpect @ file:///home/conda/feedstock_root/build_artifacts/pexpect_1667297516076/work
pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1602536217715/work
parso
pexpect
pickleshare
Pillow==9.5.0
platformdirs @ file:///home/conda/feedstock_root/build_artifacts/platformdirs_1683850015520/work
prompt-toolkit @ file:///home/conda/feedstock_root/build_artifacts/prompt-toolkit_1677600924538/work
platformdirs
prompt-toolkit
protobuf==4.23.0
psutil==5.9.5
ptyprocess @ file:///home/conda/feedstock_root/build_artifacts/ptyprocess_1609419310487/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl
pure-eval @ file:///home/conda/feedstock_root/build_artifacts/pure_eval_1642875951954/work
ptyprocess
pure-eval
pyasn1==0.5.0
pyasn1-modules==0.3.0
Pygments @ file:///home/conda/feedstock_root/build_artifacts/pygments_1681904169130/work
Pygments
pyparsing==3.0.9
PySocks==1.7.1
python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/python-dateutil_1626286286081/work
python-dateutil
pytz==2023.3
PyWavelets==1.4.1
PyYAML==6.0
pyzmq @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_a7d9jpero7/croot/pyzmq_1682697648735/work
pyzmq
requests==2.29.0
requests-oauthlib==1.3.1
rsa==4.9
scikit-image==0.20.0
scipy==1.9.1
seaborn==0.12.2
sentry-sdk==1.21.1
six @ file:///home/conda/feedstock_root/build_artifacts/six_1620240208055/work
six
smmap==5.0.0
soupsieve==2.4.1
stack-data @ file:///home/conda/feedstock_root/build_artifacts/stack_data_1669632077133/work
stack-data
sympy==1.11.1
tensorboard==2.13.0
tensorboard-data-server==0.7.0
Expand All @@ -90,14 +89,14 @@ tifffile==2023.4.12
torch==2.0.0
torchaudio==2.0.1
torchvision==0.15.1
tornado @ file:///Users/runner/miniforge3/conda-bld/tornado_1625488956802/work
tornado
tqdm==4.65.0
traitlets @ file:///home/conda/feedstock_root/build_artifacts/traitlets_1675110562325/work
typing_extensions @ file:///home/conda/feedstock_root/build_artifacts/typing_extensions_1678559861143/work
traitlets
typing_extensions
tzdata==2023.3
ultralytics==8.0.99
urllib3==1.26.15
wcwidth @ file:///home/conda/feedstock_root/build_artifacts/wcwidth_1673864653149/work
wcwidth
Werkzeug==2.3.4
youtube-dl==2020.12.2
zipp==3.15.0
79 changes: 51 additions & 28 deletions Yolov8/tempKeypoint.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import csv
from ultralytics import YOLO
from ast import literal_eval
from utils import loadbar, count_lines

# Parse keypoints from CSV file
def parse_keypoints_csv(file_path):
try:
print(file_path)
with open(file_path, 'r') as file:
l = count_lines(file)
file.seek(0) # Reset file pointer

reader = csv.reader(file)
next(reader) # Skip header row

keypoints = []
for row in reader:
for i, row in enumerate(reader):
loadbar(i+1, l, prefix='Parse progress:', suffix='Parsing complete', length=50)
if row:
frame = int(row[0])
person = int(row[1])
Expand All @@ -19,44 +26,60 @@ def parse_keypoints_csv(file_path):
keypoints.append((frame, person, keypoint, x, y))

return keypoints
except StopIteration:
return []

model = YOLO("yolov8n-pose.pt")

source = "bazzar.mp4"
results = model.predict(source=source, save=False, conf=0.5, save_txt=False, show=True)

output_file = "keypoints_output.csv"
except Exception as e:
print(f"Error parsing keypoints from CSV file: {e}")

# Save keypoints to CSV file
def save_keypoints(results, output_file):
with open(output_file, 'a', newline='') as file:
writer = csv.writer(file)
for i, result in enumerate(results.xyxy):

l = len(results)
for i, result in enumerate(results):
loadbar(i+1, l, prefix='Save progress:', suffix='Save complete', length=50)
keypoints = result.keypoints
for j, person_keypoints in enumerate(keypoints):
for k, keypoint in enumerate(person_keypoints):
x, y = keypoint[:2]
writer.writerow([i, j, k, x.item(), y.item()])

# Parse the keypoints CSV file
parsed_results = parse_keypoints_csv(output_file)

separated_keypoints = {}
for frame, person, keypoint, x, y in parsed_results:
if frame not in separated_keypoints:
separated_keypoints[frame] = {}
if person not in separated_keypoints[frame]:
separated_keypoints[frame][person] = []
separated_keypoints[frame][person].append((keypoint, x, y))
# Separate the keypoints by frame and person
def separate_keypoints(keypoints):
separated_keypoints = {}
for frame, person, keypoint, x, y in keypoints:
if frame not in separated_keypoints:
separated_keypoints[frame] = {}
if person not in separated_keypoints[frame]:
separated_keypoints[frame][person] = []
separated_keypoints[frame][person].append((keypoint, x, y))
return separated_keypoints

# Display the keypoints
for frame_idx, frame_keypoints in separated_keypoints.items():
print(f"Frame {frame_idx}:")
for person_id, keypoints_list in frame_keypoints.items():
print(f"Person {person_id}:")
for keypoint_idx, (keypoint, x, y) in enumerate(keypoints_list):
print(f"Keypoint {keypoint_idx}: (x={x}, y={y})")
def display_keypoints(keypoints):
for frame_idx, frame_keypoints in keypoints.items():
print(f"Frame {frame_idx}:")
for person_id, keypoints_list in frame_keypoints.items():
print(f"Person {person_id}:")
for keypoint_idx, (keypoint, x, y) in enumerate(keypoints_list):
print(f"Keypoint {keypoint_idx}: (x={x}, y={y})")
print()
print()
print()


model = YOLO("yolov8n-pose.pt")

source = "bazzar.mp4"
output_file = "./keypoints_output.csv"

# Save or parse the keypoints to a CSV file
if input("Save or parse the keypoints? (1/2): ") == 1:
results = model.predict(source=source, save=False, conf=0.5, save_txt=False, show=True)
save_keypoints(results, output_file)
else:
parsed_results = parse_keypoints_csv(output_file)

if input("Display the keypoints? (y/n): ") == "y":
separated_keypoints = separate_keypoints(parsed_results)
display_keypoints(separated_keypoints)

print("Done!")
Binary file removed Yolov8/uni.mp4
Binary file not shown.
12 changes: 12 additions & 0 deletions Yolov8/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def loadbar(current, total, prefix='', suffix='', decimals=1, length=100, fill='β–ˆ', printEnd="\r"):
"""Prints a progress bar to the console."""
percent = ("{0:." + str(decimals) + "f}").format(100 * (current / float(total)))
filledLength = int(length * current // total)
bar = fill * filledLength + '-' * (length - filledLength)
print(f'\r{prefix} |{bar}| {percent}% {suffix}', end=printEnd)
if current == total:
print()

def count_lines(file):
"""Counts the number of lines in a file."""
return sum(1 for line in file)
Binary file removed Yolov8/yolov8n-pose.pt
Binary file not shown.
Binary file removed Yolov8/yolov8n-seg.pt
Binary file not shown.
Binary file removed Yolov8/yolov8n.pt
Binary file not shown.

0 comments on commit ee40931

Please sign in to comment.