Skip to content

Commit

Permalink
updated to SDK 1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
keighrim committed Jul 24, 2023
1 parent bfd946a commit 759e758
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Containerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use the same base image version as the clams-python python library version
FROM ghcr.io/clamsproject/clams-python-opencv4-torch:1.0.7
FROM ghcr.io/clamsproject/clams-python-opencv4-torch:1.0.9
# See https://github.com/orgs/clamsproject/packages?tab=packages&q=clams-python for more base images
# IF you want to automatically publish this image to the clamsproject organization,
# 1. you should have generated this template without --no-github-actions flag
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ CLAMS app to detect digitally encoded slates in video.

General user instructions for CLAMS apps is available at [CLAMS Apps documentation](https://apps.clams.ai/clamsapp).

### Configurable runtime parameter

Although all CLAMS apps are supposed to run as *stateless* HTTP servers, some apps can configured at request time using [URL query strings](https://en.wikipedia.org/wiki/Query_string). For runtime parameter supported by this app, please visit [CLAMS App Directory](https://apps.clams.ai) and look for the app name and version.
22 changes: 10 additions & 12 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import logging
import os
import warnings
from typing import Union

import PIL
Expand All @@ -12,8 +13,6 @@
from torch.autograd import Variable
from torchvision import transforms

# logging.basicConfig(level=logging.DEBUG)


class Slatedetection(ClamsApp):

Expand All @@ -35,13 +34,14 @@ def _appmetadata(self):

def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:

logging.debug(f"loading documents with type: {DocumentTypes.VideoDocument}")
self.logger.debug(f"loading documents with type: {DocumentTypes.VideoDocument}")
new_view = mmif.new_view()
self.sign_view(new_view, parameters)
vds = mmif.get_documents_by_type(DocumentTypes.VideoDocument)
if vds:
vd = vds[0]
else:
warnings.warn("No video document found in the input MMIF.")
return mmif
# fill the params dict with the default values if not provided
conf = self.get_configuration(**parameters)
Expand All @@ -51,7 +51,7 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:
timeUnit=unit,
document=vd.id
)
logging.debug(f"running slate detection with parameters: {conf}")
self.logger.debug(f"running slate detection with parameters: {conf}")
for slate in self.run_slatedetection(vd, **conf):
start_frame, end_frame = slate
timeframe_annotation = new_view.new_annotation(AnnotationTypes.TimeFrame)
Expand All @@ -62,7 +62,7 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:

def run_slatedetection(self, vd, **parameters):
video_filename = vd.location_path()
logging.debug(f"video_filename: {video_filename}")
self.logger.debug(f"video_filename: {video_filename}")
image_transforms = transforms.Compose(
[transforms.Resize(224), transforms.ToTensor()]
)
Expand All @@ -79,7 +79,7 @@ def frame_is_slate(frame_, _threshold=parameters["threshold"]):

cap = vdh.capture(vd)
frames_to_test = vdh.sample_frames(0, parameters['stopAt'], parameters['sampleRatio'])
logging.debug(f"frames_to_test: {frames_to_test}")
self.logger.debug(f"frames_to_test: {frames_to_test}")
found_slates = []
in_slate = False
start_frame = None
Expand All @@ -89,7 +89,7 @@ def frame_is_slate(frame_, _threshold=parameters["threshold"]):
ret, frame = cap.read()
if not ret:
break
logging.debug(f"cur_frame: {cur_frame}, slate? : {frame_is_slate(frame)}")
self.logger.debug(f"cur_frame: {cur_frame}, slate? : {frame_is_slate(frame)}")
if frame_is_slate(frame):
if not in_slate:
in_slate = True
Expand All @@ -109,19 +109,17 @@ def frame_is_slate(frame_, _threshold=parameters["threshold"]):

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--port", action="store", default="5000", help="set port to listen"
)
parser.add_argument("--port", action="store", default="5000", help="set port to listen")
parser.add_argument("--production", action="store_true", help="run gunicorn server")

parsed_args = parser.parse_args()

# create the app instance
app = Slatedetection()

http_app = Restifier(app, port=int(parsed_args.port)
)
http_app = Restifier(app, port=int(parsed_args.port))
if parsed_args.production:
http_app.serve_production()
else:
app.logger.setLevel(logging.DEBUG)
http_app.run()
2 changes: 1 addition & 1 deletion metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def appmetadata() -> AppMetadata:
metadata.add_parameter(name="timeUnit",
description="Unit of time to use in output.",
type="string",
choices=["frames","seconds", "milliseconds"],
choices=["frames", "seconds", "milliseconds"],
default="frames")

metadata.add_parameter(name="sampleRatio",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
clams-python==1.0.7
clams-python==1.0.9

opencv-python==4.*
torch==1.*
Expand Down

0 comments on commit 759e758

Please sign in to comment.