prakrutpatel commited on
Commit
6d0cb0a
·
1 Parent(s): c2cecc6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -18,6 +18,22 @@ from PIL import Image
18
  from IPython.display import display
19
  import io
20
  import pathlib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  RoboflowAPI = os.environ['RoboflowAPI']
23
  RoboflowCocoAPI = os.environ['RoboflowCocoAPI']
@@ -419,8 +435,11 @@ def segment(image):
419
  buf.seek(0)
420
  img = Image.open(buf)
421
  return img
422
- examples = os.listdir('../../Examples')
423
- examples = ['../../Examples/' + item for item in examples]
424
- title="Context R-CNN"
425
- description=f'<p class="has-line-data" data-line-start="0" data-line-end="1">Gradio demo for <strong>Context R-CNN</strong>: <a href="https://arxiv.org/abs/1912.03538">[Paper]</a>.</p><p class="has-line-data" data-line-start="2" data-line-end="3">Context R-CNN is an object detection algorithm that uses contextual features to improve object detection. It is based on Faster R-CNN, but it adds a module that can incorporate contextual features from surrounding frames. This allows Context R-CNN to better identify objects that are partially obscured or that are moving quickly.</p><p class="has-line-data" data-line-start="4" data-line-end="5">The contextual features are stored in a memory bank, which is built up over time as the camera captures images. The memory bank is indexed using an attention mechanism, which allows Context R-CNN to focus on the most relevant contextual features for each object.</p><p class="has-line-data" data-line-start="6" data-line-end="7">Context R-CNN has been shown to improve object detection performance on a variety of datasets, including camera trap data and traffic camera data. It is a promising approach for improving object detection in static monitoring cameras, where the sampling rate is low and the objects may exhibit long-term behavior.</p><p class="has-line-data" data-line-start="8" data-line-end="9">This application of Context R-CNN demonstrates its potential for use in camera trap images of Gopher Tortoises in the wild. It also shows how Context R-CNN can improve object detection performance over existing Faster R-CNN implementations. Both models of R-CNN were trained on the exact same datasets for best comparison. Context R-CNN improves upon Faster R-CNN by building a contextual memory bank, such contextual information can include the position of other objects in the scene, the motion of the objects, and the time of day. The contextual feature matrix used by Context R-CNN model was build using Faster R-CNN model.</p><p class="has-line-data" data-line-start="11" data-line-end="12"><strong>The examples images provided in this demo were not used to train or test the models.</strong></p><p class="has-line-data" data-line-start="13" data-line-end="14">Note: The model requires the date taken attribute to be present in the metadata of the uploaded images in order to process them correctly.</p>'
426
- gr.Interface(fn=segment, inputs = "file",outputs = "image" ,title=title, description=description ,examples=examples,enable_queue=True).launch()
 
 
 
 
18
  from IPython.display import display
19
  import io
20
  import pathlib
21
+ import logging
22
+
23
+ # Create a logging instance
24
+ logger = logging.getLogger('my_application')
25
+ logger.setLevel(logging.INFO) # you can set this to be DEBUG, INFO, ERROR
26
+
27
+ # Assign a file-handler to that instance
28
+ fh = logging.FileHandler("error.txt")
29
+ fh.setLevel(logging.INFO) # again, you can set this differently
30
+
31
+ # Format your logs (optional)
32
+ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
33
+ fh.setFormatter(formatter) # This will set the format to the file handler
34
+
35
+ # Add the handler to your logging instance
36
+ logger.addHandler(fh)
37
 
38
  RoboflowAPI = os.environ['RoboflowAPI']
39
  RoboflowCocoAPI = os.environ['RoboflowCocoAPI']
 
435
  buf.seek(0)
436
  img = Image.open(buf)
437
  return img
438
+ try:
439
+ examples = os.listdir('../../Examples')
440
+ examples = ['../../Examples/' + item for item in examples]
441
+ title="Context R-CNN"
442
+ description=f'<p class="has-line-data" data-line-start="0" data-line-end="1">Gradio demo for <strong>Context R-CNN</strong>: <a href="https://arxiv.org/abs/1912.03538">[Paper]</a>.</p><p class="has-line-data" data-line-start="2" data-line-end="3">Context R-CNN is an object detection algorithm that uses contextual features to improve object detection. It is based on Faster R-CNN, but it adds a module that can incorporate contextual features from surrounding frames. This allows Context R-CNN to better identify objects that are partially obscured or that are moving quickly.</p><p class="has-line-data" data-line-start="4" data-line-end="5">The contextual features are stored in a memory bank, which is built up over time as the camera captures images. The memory bank is indexed using an attention mechanism, which allows Context R-CNN to focus on the most relevant contextual features for each object.</p><p class="has-line-data" data-line-start="6" data-line-end="7">Context R-CNN has been shown to improve object detection performance on a variety of datasets, including camera trap data and traffic camera data. It is a promising approach for improving object detection in static monitoring cameras, where the sampling rate is low and the objects may exhibit long-term behavior.</p><p class="has-line-data" data-line-start="8" data-line-end="9">This application of Context R-CNN demonstrates its potential for use in camera trap images of Gopher Tortoises in the wild. It also shows how Context R-CNN can improve object detection performance over existing Faster R-CNN implementations. Both models of R-CNN were trained on the exact same datasets for best comparison. Context R-CNN improves upon Faster R-CNN by building a contextual memory bank, such contextual information can include the position of other objects in the scene, the motion of the objects, and the time of day. The contextual feature matrix used by Context R-CNN model was build using Faster R-CNN model.</p><p class="has-line-data" data-line-start="11" data-line-end="12"><strong>The examples images provided in this demo were not used to train or test the models.</strong></p><p class="has-line-data" data-line-start="13" data-line-end="14">Note: The model requires the date taken attribute to be present in the metadata of the uploaded images in order to process them correctly.</p>'
443
+ gr.Interface(fn=segment, inputs = "file",outputs = "image" ,title=title, description=description ,examples=examples,enable_queue=True).launch()
444
+ except Exception as e:
445
+ logger.exception(e)