Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-074
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-074
2022-074
Commits
76c59c27
Commit
76c59c27
authored
Jul 26, 2022
by
IT19165226-Arachchige I.D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compare values of models
parent
8af500f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
220 additions
and
0 deletions
+220
-0
Compare CSVs.ipynb
Compare CSVs.ipynb
+220
-0
No files found.
Compare CSVs.ipynb
0 → 100644
View file @
76c59c27
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "403e92b4",
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6e570240",
"metadata": {},
"outputs": [],
"source": [
"##writing details to the CSV\n",
"\n",
"def write_to_csv_rot_angles_diff(list_considered, storage_location):\n",
" \n",
" #creating the csv template\n",
" with open(storage_location, mode='w', newline='') as headpose_track_file:\n",
" writer = csv.writer(headpose_track_file) #, delimiter=',', quotechar='\"', quoting = csv.QUOTE_MINIMAL)\n",
" \n",
" writer.writerow(['Frame_number','Mediapipe difference','', '', '', 'MTCNN difference','', ''])\n",
" writer.writerow(['','Yaw','Pitch', 'Roll', '', 'Yaw','Pitch', 'Roll'])\n",
" \n",
" frameNo = 0\n",
" \n",
" #all_diff - record = (mediapipe, mtcnn) \n",
" \n",
" for record in list_considered:\n",
" sub_record_mediapipe = record[0]\n",
" sub_record_mtcnn = record[1]\n",
" \n",
" frameNo += 1 #increase the frame number\n",
" \n",
" #writing the record details to the file\n",
" writer.writerow([frameNo, sub_record_mediapipe[0], sub_record_mediapipe[1], sub_record_mediapipe[2], '', sub_record_mtcnn[0], sub_record_mtcnn[1], sub_record_mtcnn[2]])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "590a7c58",
"metadata": {},
"outputs": [],
"source": [
"#getting the csv values to a usable list\n",
"\n",
"def get_val(storage_location, list_to_store):\n",
" \n",
" with open(storage_location, 'r') as file:\n",
" filecontent=csv.reader(file)\n",
" for row in filecontent:\n",
" list_to_store.append(row)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "179cdd6e",
"metadata": {},
"outputs": [],
"source": [
"def find_difference(list_considered, list_to_store):\n",
" \n",
" ann_length, other_len = len(annotated_val), len(list_considered)\n",
" yaw_diff, pitch_diff, roll_diff = 0, 0, 0\n",
" \n",
" if ann_length > other_len:\n",
" length = other_len\n",
" else:\n",
" length = ann_length\n",
" \n",
" for i in range (1, length):\n",
" annotated_record = annotated_val[i]\n",
" record = list_considered[i]\n",
" \n",
" val1 = float(annotated_record[1]) - float(record[1])\n",
" val2 = float(annotated_record[2]) - float(record[2])\n",
" val3 = float(annotated_record[3]) - float(record[3])\n",
" \n",
" yaw_diff += val1\n",
" pitch_diff += val2\n",
" roll_diff += val3\n",
" \n",
" list_to_store.append((val1, val2, val3))\n",
" \n",
" return (yaw_diff / length), (pitch_diff / length), (roll_diff / length)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "73ab61c8",
"metadata": {},
"outputs": [],
"source": [
"def create_all_diff():\n",
" \n",
" len1, len2 = len(mediapipe_diff), len(mtcnn_diff)\n",
" \n",
" if len1 > len2:\n",
" length = len1\n",
" else:\n",
" length = len2\n",
" \n",
" for i in range (0, length):\n",
" if (i >= len1):\n",
" sub_record_mediapipe = ('', '', '')\n",
" else:\n",
" sub_record_mediapipe = mediapipe_diff[i]\n",
" \n",
" if (i >= len2):\n",
" sub_record_mtcnn = ('', '', '')\n",
" else:\n",
" sub_record_mtcnn = mtcnn_diff[i]\n",
" \n",
" record = (sub_record_mediapipe, sub_record_mtcnn)\n",
" \n",
" all_diff.append(record)\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "151e603d",
"metadata": {},
"outputs": [],
"source": [
"##writing details to the CSV\n",
"\n",
"def write_to_csv_mean(storage_location):\n",
" \n",
" #creating the csv template\n",
" with open(storage_location, mode='w', newline='') as headpose_track_file:\n",
" writer = csv.writer(headpose_track_file) #, delimiter=',', quotechar='\"', quoting = csv.QUOTE_MINIMAL)\n",
" \n",
" writer.writerow(['Model','Yaw', 'Pitch', 'Roll','All'])\n",
" \n",
" mp_mean = (mp_mean_yaw + mp_mean_pitch + mp_mean_roll) / 3\n",
" mtcnn_mean = (mtcnn_mean_yaw + mtcnn_mean_pitch + mtcnn_mean_roll) / 3\n",
" \n",
" #writing the record details to the file\n",
" writer.writerow(['Mediapipe', mp_mean_yaw, mp_mean_pitch, mp_mean_roll, mp_mean])\n",
" writer.writerow(['MTCNN', mtcnn_mean_yaw, mtcnn_mean_pitch, mtcnn_mean_roll, mtcnn_mean])"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "98b9306a",
"metadata": {},
"outputs": [],
"source": [
"video_name = '4_A_FT_M'\n",
"annotated_val_location = 'test_videos/eyediap/annotated_values/converted_' + video_name + '_ball_tracking.csv'\n",
"mediapipe_val_location = 'result_analysis/eyediap/' + video_name + '/' + video_name + '_raw_rotational_angles.csv'\n",
"mtcnn_val_location = 'result_analysis/mtcnn/eyediap/' + video_name + '/' + video_name + '_MP.csv'\n",
"\n",
"annotated_val, mediapipe_val, mtcnn_val, mediapipe_diff, mtcnn_diff, all_diff = [], [], [], [], [], []\n",
"mediapipe_mean, mtcnn_mean = [], []\n",
"\n",
"get_val(annotated_val_location , annotated_val)\n",
"get_val(mediapipe_val_location , mediapipe_val)\n",
"get_val(mtcnn_val_location , mtcnn_val)\n",
"\n",
"mp_mean_yaw, mp_mean_pitch, mp_mean_roll = find_difference(mediapipe_val, mediapipe_diff)\n",
"mtcnn_mean_yaw, mtcnn_mean_pitch, mtcnn_mean_roll = find_difference(mtcnn_val, mtcnn_diff)\n",
"\n",
"create_all_diff()\n",
"\n",
"#saving generated data\n",
"output_folder = 'comparison/'\n",
" #check if specified path exists, if not create it\n",
"if not (os.path.isdir(output_folder)):\n",
" os.makedirs(output_folder, mode = 0o777, exist_ok = False)\n",
"\n",
"write_to_csv_rot_angles_diff(all_diff, output_folder + video_name + '_diff.csv')\n",
"write_to_csv_mean(output_folder + video_name + '_means.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5aa669cc",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment