From a83454b4f99887e4fa068d22bf40b7305b97ec63 Mon Sep 17 00:00:00 2001 From: CHAITANYA KODAVALI Date: Thu, 28 Oct 2021 22:47:15 +0530 Subject: [PATCH 1/3] sorted existing matrices and improved performance --- C++/Algorithms/sorting.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 C++/Algorithms/sorting.cpp diff --git a/C++/Algorithms/sorting.cpp b/C++/Algorithms/sorting.cpp new file mode 100644 index 00000000..f0dbd560 --- /dev/null +++ b/C++/Algorithms/sorting.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; +void selectionSort(int a[], int n) { + int i, j, min, temp; + for (i = 0; i < n - 1; i++) { + min = i; + for (j = i + 1; j < n; j++) + if (a[j] < a[min]) + min = j; + temp = a[i]; + a[i] = a[min]; + a[min] = temp; + } +} +int main() { + int a[] = { 22, 91, 35, 78, 10, 8, 75, 99, 1, 67 }; + int n = sizeof(a)/ sizeof(a[0]); + int i; + cout<<"Given array is:"< Date: Thu, 28 Oct 2021 23:09:16 +0530 Subject: [PATCH 2/3] Enhanced integrity check for Database schema --- .../Divide-and-Conquer/Intergrity.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Java/Algorithms/Divide-and-Conquer/Intergrity.java diff --git a/Java/Algorithms/Divide-and-Conquer/Intergrity.java b/Java/Algorithms/Divide-and-Conquer/Intergrity.java new file mode 100644 index 00000000..cd0a865d --- /dev/null +++ b/Java/Algorithms/Divide-and-Conquer/Intergrity.java @@ -0,0 +1,53 @@ +// Java program to calculate SHA-1 hash value + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class GFG { + public static String encryptThisString(String input) + { + try { + // getInstance() method is called with algorithm SHA-1 + MessageDigest md = MessageDigest.getInstance("SHA-1"); + + // digest() method is called + // to calculate message digest of the input string + // returned as array of byte + byte[] messageDigest = md.digest(input.getBytes()); + + // Convert byte array into signum representation + BigInteger no = new BigInteger(1, messageDigest); + + // Convert message digest into hex value + String hashtext = no.toString(16); + + // Add preceding 0s to make it 32 bit + while (hashtext.length() < 32) { + hashtext = "0" + hashtext; + } + + // return the HashText + return hashtext; + } + + // For specifying wrong message digest algorithms + catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } + + // Driver code + public static void main(String args[]) throws + NoSuchAlgorithmException + { + + System.out.println("HashCode Generated by SHA-1 for: "); + + String s1 = "GeeksForGeeks"; + System.out.println("\n" + s1 + " : " + encryptThisString(s1)); + + String s2 = "hello world"; + System.out.println("\n" + s2 + " : " + encryptThisString(s2)); + } +} From d9f0302b37f3b73c4ca0909d0f798ff4eb429639 Mon Sep 17 00:00:00 2001 From: CHAITANYA KODAVALI Date: Thu, 28 Oct 2021 23:16:26 +0530 Subject: [PATCH 3/3] Reduced time complexity using Deep Learning --- .../Dynamic-Programming/faster_cnn.py | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Python/Algorithms/Dynamic-Programming/faster_cnn.py diff --git a/Python/Algorithms/Dynamic-Programming/faster_cnn.py b/Python/Algorithms/Dynamic-Programming/faster_cnn.py new file mode 100644 index 00000000..ace3d27c --- /dev/null +++ b/Python/Algorithms/Dynamic-Programming/faster_cnn.py @@ -0,0 +1,85 @@ +import os.path + +import cv2 +import numpy as np +import requests +import torchvision +import torchvision.transforms as transforms + +print("Faster R-CNN object detection") + +# COCO dataset class names +classes = [ + 'background', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', + 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'street sign', + 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', + 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'hat', 'backpack', + 'umbrella', 'shoe', 'eye glasses', 'handbag', 'tie', 'suitcase', 'frisbee', + 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', + 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'plate', 'wine glass', + 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', + 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', + 'couch', 'potted plant', 'bed', 'mirror', 'dining table', 'window', 'desk', + 'toilet', 'door', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', + 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'blender', 'book', + 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush', 'hair brush'] + +# Download object detection image +image_file = 'source_2.png' +if not os.path.isfile(image_file): + url = "https://github.com/ivan-vasilev/advanced-deep-learning-with-python/blob/master/chapter04-detection-segmentation/source_2.png" + r = requests.get(url) + with open(image_file, 'wb') as f: + f.write(r.content) + +# load the pytorch model +model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True) + +# set the model in evaluation mode +model.eval() + +# read the image file +img = cv2.imread(image_file) + +# transform the input to tensor +transform = transforms.Compose([transforms.ToPILImage(), transforms.ToTensor()]) +nn_input = transform(img) +output = model([nn_input]) + +# random color for each class +colors = np.random.uniform(0, 255, size=(len(classes), 3)) + +# iterate over the network output for all boxes +for box, box_class, score in zip(output[0]['boxes'].detach().numpy(), + output[0]['labels'].detach().numpy(), + output[0]['scores'].detach().numpy()): + + # filter the boxes by score + if score > 0.5: + # transform bounding box format + box = [(box[0], box[1]), (box[2], box[3])] + + # select class color + color = colors[box_class] + + # extract class name + class_name = classes[box_class] + + # draw the bounding box + cv2.rectangle(img=img, + pt1=box[0], + pt2=box[1], + color=color, + thickness=2) + + # display the box class label + cv2.putText(img=img, + text=class_name, + org=box[0], + fontFace=cv2.FONT_HERSHEY_SIMPLEX, + fontScale=1, + color=color, + thickness=2) + +cv2.imshow("Object detection", img) +cv2.waitKey()