sign-detection-gesture/file_upload_doc.md
2025-12-22 11:30:58 -08:00

15 lines
2.6 KiB
Markdown

## File Upload
The Sign Detection can also be applied to pre masked image that can be applied and get the sign that is depicted in the image. This can be useful when a series of images are prepared that can be used to teach or use images of a dataset for prediction.
- **/upload**: is the URL that is used to display the input form to upload the image file and then display the prediction that is passed onto the upload view.
- **Models.py**: The Model is created using the _ImageField_ used to display the input field that can only take image formats such as the JPEG and PNG and cannot be false.
- **Forms.py**: The form is created using the model above along with the save method in the forms class to receive the image and predict the letter from the Tensorflow model. When the Object is created the Form is created from the fields in the model mentioned.
- **sav()**: Is used to respond once the Image is uploaded to the web application. The response object from the request to the controller can be used to call this function of the Form Object. Once the function is invoked. The Keras model is imported from the project directory that is pre compiled to provide prediction for the given image. The Image that is saved is taken from the main directory and converted into the Numpy array with 3 channels. Since, the Image that is uploaded is already pre-processed. The array is given to the model and the prediction is returned from the Keras model.
- **gesture_view**: The controller displays the HTML page _upload_. The Form object is created and passed onto the context of the page. The Django Template is used to represent the form in the form of tags that is displayed as a paragraph within the page. The page additionally consists of an upload button to represent the submit button. Once the POST request is sent. The conditional statement is used to differentiate between GET and POST request. Once the prediction is obtained from the _sav_ instead of the form object the prediction character is sent which is displayed to the user with conditional tags in Django Template.
- **predictor**: is given the prediction from the trained model as the only argument. The image that is previously stored by from the _sav()_ is converted into the Numpy array. The image array is fed into the Tensorflow machine learning model of the _.h5_ format. This is performed with the help of Keras package and the function of _load_model_ defined by the package. Based on the output from the Model the letter can be predicted from a case-switch style conditionals where the indexing of the classifier_resultant array is used to specify the letter of the alphabet is predicted which is returned.