Skip to main content

A package

Project description

Software Lab

Python Datascience Assignment

In this assignment we will deal with Object detection. Object detection is a very well studied task of Deep Learning, having tremendous variety of applications. You have to create a python package for transforming images and analysing their effect on the predictions of an object detector. We are providing you with a pretrained object detector, all you need to do is to call the detector on the image and get the outputs.

A python package means that one can install the package in the python environment and can import the modules in any python script, irrespective of the location of the script. Creating a python package is fairly easy, just follow the steps here.

The details of each of the files/folders are as follows:

  1. main.py: This is the main file which is to be called to execute the program. The main file calls the corresponding functions as needed while execution. The main file should call the appropriate function to prepare the dataset, then transform the images read, obtain the bounding boxes of the objects present in the image by calling the detector model, and then plot the obtained images by calling the appropriate functions from the package described below.

  2. ./my_package/model.py: This file contains the object-detection model definition. Consider it as a black-box model which takes an image (as numpy array) as input and provides the bounding box outputs and the corresponding class labels as for the input image.

 

Fig. 1. Sample Output of an Object Detector.

 
  1. ./my_package/data/dataset.py: This file contains the class Dataset that reads the provided dataset from the annotation file and provides the numpy version of the images which are to be transformed and forwarded through the model. The annotation format is provided in data/README.md

  2. ./my_package/data/transforms: This folder contains 5 files. Each of these files is responsible for performing the corresponding transformation, as follows:

a) crop.py: This file takes an image (as numpy array) as input and crops it based on the provided arguments. Declare a class CropImage() for performing the operation.

 

Fig. (a). Crop Operation.

 

b) flip.py: This file takes an image (as numpy array) as input and flips it based on the provided arguments. Declare a class FlipImage() for performing the operation.

 

Fig. (b). Flip Operation.

 

c) rotate.py: This file takes an image (as numpy array) as input and rotates it based on the provided arguments. Declare a class RotateImage() for performing the operation.

 

Fig. (c). Rotate Operation.

 

d) rescale.py: This file takes an image (as numpy array) as input and rescales it based on the provided arguments. Declare a class RotateImage() for performing the operation.

 

Fig. (d). Rescale Operation.

 

e) blur.py: This file takes an image (as numpy array) as input and applies a gaussian blur to it based on the provided arguments. Declare a class GaussBlurImage() for performing the operation.

 

Fig. (e). Blur Operation.

 
  1. ./my_package/analysis/visualize.py: This file defines a function that draws the image with the predicted bounding boxes (with the corresponding labels) on the image and saves them in the specified output folder.

  2. setup.py: Use this file for constructing the package my_package.

Coding Task [30 marks]

Note: For handling images, e.g. reading images, etc. we would recommend using PIL instead of OpenCV as OpenCV uses BGR format instead of RGB.

  1. Write the various transformations in ./my_package/data/transforms. There are five files, as already mentioned. Although these functions are easily implementable using numpy only, you may use any image processing libraries like PIL, skimage or opencv. [2x5=10 marks]

  2. Complete the Dataset class in ./my_package/data/dataset.py. This class will accept the path to the annotation file and the list of transformation classes. Ideally you should be directly using transformation classes but you may also use strings to identify the transformations. [5 marks]

  3. Write a function plot_boxes() in ./my_package/analysis/visualize.py that will draw the image with the predicted bounding boxes (with the corresponding labels) on the images and save them in the output folder specified in the argument. Please note that you need to plot only the 5 most confident bounding boxes predicted by the object detector. If the detector predicts less than 5 boxes, then plot all of them. [5 marks]

  4. Create a python package my_package. For this you need to write setup.py. It must be noted that files called ___init__.py need to be added in the hierarchy. We leave it to you to search where they should be added. Note that the user will generally not know the exact files where the classes are written. That means, he does not know that their exist a file crop.py where the class CropImage() is defined. Rather he simply knows that this class is defined in transforms. So, a good coding practice is to allow an import statement from my_package.data.transforms import CropImage. [5 marks]

  5. Write main.py where you will test the different transformations you have written on the object detector. The outputs for each of the experiments should be organized properly in the outputs folder. [5 marks]

Analysis Task [10 marks]

  1. Obtain and save the predicted bounding boxes for all the images provided in the data/imgs folder. [3 marks]

  2. Consider the image with name same as the last digit of your roll number, i.e. if your roll number is 19CS####7 then consider the image 7.jpg then plot the following using subplots in matplotlib and save them: [1x7=7 marks]

    a) The original image along with the predicted bounding boxes.

    b) Horizontally flipped original image along with the predicted bounding boxes.

    c) Blurred image (with some degree of blurring) along with the predicted bounding boxes.

    d) Twice Rescaled image (2X scaled) along with the predicted bounding boxes.

    e) Half Rescaled image (0.5X scaled) along with the predicted bounding boxes.

    f) 90 degree right rotated image along with the predicted bounding boxes.

    g) 45 degree left rotated image along with the predicted bounding boxes.

Please read the class definitions very carefully. In this assignment you do not need to code a lot, but you need to understand how to integrate several custom modules together in a clean way. More details on the arguments and the return types are provided in the corresponding files.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

my_package-19CS10039-0.0.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

my_package_19CS10039-0.0.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file my_package-19CS10039-0.0.1.tar.gz.

File metadata

  • Download URL: my_package-19CS10039-0.0.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.3

File hashes

Hashes for my_package-19CS10039-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1ad14639b0dcfe4113004e088cca4c172bce7a39a5c979f4402e836ba43110a9
MD5 ed435fc9c5803c78819564d12c16d00f
BLAKE2b-256 4ee5982b621fdd2b3f1e2b66fdad2d1a967f82ff8ae39d68c49d068661292723

See more details on using hashes here.

File details

Details for the file my_package_19CS10039-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: my_package_19CS10039-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.3

File hashes

Hashes for my_package_19CS10039-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c3c791e217321ee1045b2b12a68285b3f6249f05b0cc03e47a787ef02836876
MD5 99c4e5c6947c2442a58f17a08711bddb
BLAKE2b-256 8ea963e4efbde405122eb6b53ad13052c18e8f0a38c5465b8c395c391677a172

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page