Skip to content

Reduced time complexity using Deep Learning #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions C++/Algorithms/sorting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<iostream>
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:"<<endl;
for (i = 0; i < n; i++)
cout<< a[i] <<" ";
cout<<endl;
selectionSort(a, n);
printf("\nSorted array is: \n");
for (i = 0; i < n; i++)
cout<< a[i] <<" ";
return 0;
}
53 changes: 53 additions & 0 deletions Java/Algorithms/Divide-and-Conquer/Intergrity.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
85 changes: 85 additions & 0 deletions Python/Algorithms/Dynamic-Programming/faster_cnn.py
Original file line number Diff line number Diff line change
@@ -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()