Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMSI - analyzer output fix #190

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/tutorial/3/3b.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ elements_in:
- Youtube
analyse:
- name: Frames
config:
in_parallel: false
- name: KerasPretrained
config:
in_parallel: false
Expand Down
21 changes: 15 additions & 6 deletions docs/tutorial/3/3c.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
folder: media/demo_official/3c
#Where on our computer do we want to store the media?
folder: media/teargas_mexico_2022
select:
#Which media platforms do we want to search?
name: Youtube
config:
#What are our search parameters?
search_term: tear gas + mexico
uploaded_before: "2018-11-30T00:00:00Z"
uploaded_after: "2018-11-15T00:00:00Z"
uploaded_before: "2022-11-30T00:00:00Z"
uploaded_after: "2022-11-20T00:00:00Z"
analyse:
#Once we have a video, we process it by splitting it into images,
#one for each frame
- name: Frames
#We don't want to analyze successive frames that are very similar,
# so we deduplicate these
- name: ImageDedup
config:
threshold: 3
method: dhash
#We're now ready to run the image classification process over each frame.
#In this example, we'll use Resnet, an image classification model pretrained
# on the publicly available Imagenet database
- name: KerasPretrained
config:
model: ResNet50
#We're interested in detecting anything with the "tear gas" label
labels:
- tank
- rifle
- military uniform
- tear gas
19 changes: 19 additions & 0 deletions docs/tutorial/3/3d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
folder: media/demo_official/3d
select:
name: Local
config:
source: media/demo_official/3c/youtube/derived/Frames
analyse:
- name: ImageDedup
config:
threshold: 3
method: dhash
- name: KerasPretrained
config:
model: ResNet50
labels:
- tear gas canister
- tear gas
- tank
- rifle
- military uniform
Empty file added labeladj.yaml
Empty file.
79 changes: 79 additions & 0 deletions results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
import json
import sys

def get_video_meta(video_id, keras_pretrained_path):
"""Fetch the video title, upload date, and view count from the meta.json file."""
meta_file_path = os.path.join(keras_pretrained_path, 'data', video_id, 'meta.json')
with open(meta_file_path, 'r') as meta_file:
meta_data = json.load(meta_file)
title = meta_data.get('title', 'N/A')
upload_date = meta_data.get('upload_date', 'N/A')
view_count = meta_data.get('view_count', 'N/A')
return title, upload_date, view_count

def main(keras_pretrained_path):
# Dictionary to store the results
labels_dict = {}

# Iterate through the folders inside the 'derived' directory
for video_id in os.listdir(keras_pretrained_path):
video_path = os.path.join(keras_pretrained_path, video_id)

# Check if it's a directory (i.e., a video ID folder)
if os.path.isdir(video_path):
# Path to the preds.json file for the current video
preds_file_path = os.path.join(video_path, 'preds.json')

# Check if the preds.json file exists
if os.path.exists(preds_file_path):
with open(preds_file_path, 'r') as file:
content = file.read()

# Check if the file is empty
if content:
# Parse the JSON content
preds_data = json.loads(content)

# Iterate through the labels and their data
for label, data in preds_data.get('labels', {}).items():
frames = data.get('frames', [])
scores = data.get('scores', [])

# Compile the frames and their corresponding scores
frame_scores = [{"frame": frame, "score": score} for frame, score in zip(frames, scores)]

# Get video metadata
title, upload_date, view_count = get_video_meta(video_id, keras_pretrained_path)

# Append the video info to the label's list
if label not in labels_dict:
labels_dict[label] = []
labels_dict[label].append({
"video_id": video_id,
"video_title": title,
"upload_date": upload_date,
"view_count": view_count,
"frame_scores": frame_scores
})

# Print the results
for label, videos in labels_dict.items():
print(f"Assigned Label: {label}")
print(f"Total Number of Videos with the Label Found: {len(videos)}")
print("Videos where label was found:")
for video in videos:
print(f" Video Title: {video['video_title']} (ID: {video['video_id']})")
print(f" Upload Date: {video['upload_date']}")
print(f" View Count: {video['view_count']}")
print(" Frames:")
for frame_score in video['frame_scores']:
print(f" Frame: {frame_score['frame']}, Score: {frame_score['score']}")
print()

if __name__ == "__main__":
if len(sys.argv) < 2:
print("Please provide the path to the Keras_Pretrained directory")
sys.exit(1)
keras_pretrained_path = sys.argv[1]
main(keras_pretrained_path)
19 changes: 19 additions & 0 deletions resumer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
folder: media/teargas_mexico_2022
select:
name: Local
config:
source: media/teargas_mexico_2022/Youtube/derived/Frames
analyse:
- name: ImageDedup
config:
threshold: 3
method: dhash
#We're now ready to run the image classification process over each frame.
#In this example, we'll use Resnet, an image classification model pretrained
# on the publicly available Imagenet database
- name: KerasPretrained
config:
model: ResNet50
#We're interested in detecting anything with the "tear gas" label
labels:
- tear gas
2 changes: 1 addition & 1 deletion src/lib/common/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def start_analysing(self):
self.disk.write_meta(
f"{self.get_selector()}/{self.name}",
{
"etype": self.out_etype.__repr__(),
"etype": "CvJson",
"config": cfg,
"stage": {"name": self.name, "module": "analyser"},
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/selectors/Youtube/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yt_dlp
import yt_dlp
import json
import re
import argparse, os, sys
Expand Down
34 changes: 34 additions & 0 deletions teargas 2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#Where on our computer do we want to store the media?
folder: media/teargas_mexico_2018
select:
#Which media platforms do we want to search?
name: Youtube
config:
#What are our search parameters?
search_term: tear gas + mexico
uploaded_after: "2018-11-25T00:00:00Z"
uploaded_before: "2018-11-26T12:00:00Z"
analyse:
#Once we have a video, we process it by splitting it into images, one for each frame
- name: Frames
#We don't want to analyze successive frames that are very similar, so we deduplicate these
- name: ImageDedup
config:
threshold: 3
method: dhash
#We're now ready to run the image classification process over each frame.
#In this example, we'll use Resnet, an image classification model pretrained on the publicly available Imagenet database
- name: KerasPretrained
config:
model: ResNet50
labels:
# We're looking for tear gas and other indicators of police force
- tear gas
- rifle
- police
- smoke
- military uniform




28 changes: 28 additions & 0 deletions ukraine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Where on our computer do we want to store the media?
folder: media/tanks_in_ukraine_july2014

# Which media platforms do we want to search?
select:
name: Youtube
config:
# What are our search parameters?
search_term: tanks + ukraine
uploaded_after: "2014-07-20T00:00:00Z"
uploaded_before: "2014-07-30T00:00:00Z"

analyse:
# Once we have a video, we process it by splitting it into images, one for each frame.
- name: Frames
# We don't want to analyze successive frames that are very similar, so we deduplicate these
- name: ImageDedup
config:
threshold: 3
method: dhash
# We're now ready to run the image classification algorithm over each frame.
# In this example, we'll use Resnet, a model pretrained on the publicly available Imagenet database.
- name: KerasPretrained
config:
model: ResNet50
# We're interested in detecting anything with the label "tank"
labels:
- "tank"
18 changes: 18 additions & 0 deletions vidtester.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
folder: media/tanks_in_ukraine_july2014
select:
name: Youtube
config:
search_term: "tanks + ukraine"
uploaded_before: "2014-7-25T00:00:00Z"
uploaded_after: "2014-7-20T00:00:00Z"
analyse:
- name: Frames
- name: ImageDedup
config:
threshold: 3
method: dhash
- name: KerasPretrained
config:
model: ResNet50
labels:
- tank