Skip to content
View amarnathreddy0201's full-sized avatar
♥️
Focusing
♥️
Focusing
  • Bengaluru
  • 14:54 (UTC -12:00)

Block or report amarnathreddy0201

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Maximum 250 characters. Please don’t include any personal information such as legal names or email addresses. Markdown is supported. This note will only be visible to you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
amarnathreddy0201/README.md

Hi there 👋

if u have any issue with pip conflicting use below commands

  1. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  2. python get-pip.py

pip install robotframework-selenium2library

For Django preparation: pip install virtualenvwrapper-win mkvirtualenv myproject workon myproject pip install django django-admin startproject "projectname" #Name of the project django-admin startapp "app name" or python manage.py startapp appname

python manage.py showmigrations python manage.py migrate python manage.py makemigrations (model in sql format)python manage.py sqlmigrate meetings 0001(Follow this :- python manage.py "this is belongs to sqllite migrations" "This is app names in our project" "in our app check the migrations and give starting name") if above command not working first make the migrations(makemigrations) python manage.py migrate(it will put data in sqlite) python manage.py createsuperuser

Virtual env for different python versions.

  • windows:

    • py -3.11 -m venv pyenv_3.11

    • Ex :- py python_version -m venv your_venv_name.

    python3.11 -m pip install ultralytics

  • Linux:

    • python3 -m venv pyven_3.11

pip install --user pipenv

pipenv install django

logging files

import logging logging.basicConfig(level=logging.INFO, filename='sample.log', format='%(asctime)s - %(name)s - %(levelname)s - %(message)s - %(filename)s - %(lineno)d') logger = logging.getLogger(name) logger.info("print")

CPP

  1. Boost continuous sending data .

  2. https://stackoverflow.com/questions/72293309/boost-post-request-continuously-cpp

  3. https://github.com/lagadic/visp/blob/master/cmake/FindPylon.cmake pypylon cmake

  4. Opencv include in cmake : https://gist.github.com/UnaNancyOwen/9d25d9ef66b163e0667b4b3bf3962f8a

  5. Spdlog : https://github.com/gabime/spdlog/blob/v1.x/CMakeLists.txt

This is forlearning AWS

  1. Check the table exist or not : https://stackoverflow.com/questions/42485616/how-to-check-if-dynamodb-table-exists#:~:text=You%20can%20use%20the%20ListTables,you%20request%20doesn't%20exist.

fastapi with lambda(windows)

  1. pip freeze>requirements.txt
  2. pip install -t dependencies -r requirements.txt
  3. Compress-Archive -Path .\dependencies -DestinationPath .\lambda_function.zip
  4. Compress-Archive -Path .\main.py -DestinationPath .\lambda_function.zip -Update

YOLO models

Classification Detection Segmentation Kind

yolov8n-cls.pt yolov8n.pt yolov8n-seg.pt Nano

yolov8s-cls.pt yolov8s.pt yolov8s-seg.pt Small

yolov8m-cls.pt yolov8m.pt yolov8m-seg.pt Medium

yolov8l-cls.pt yolov8l.pt yolov8l-seg.pt Large

yolov8x-cls.pt yolov8x.pt yolov8x-seg.pt Huge

Creating a Python virtual environment in Linux**

  1. pip is not in your system : sudo apt-get install python-pip

  2. pip install virtualenv

  3. Create a virtual environment now, $ virtualenv virtualenv_name

  4. virtualenv -p /usr/bin/python3 virtualenv_name

  5. source virtualenv_name/bin/activate

  6. deactivate

Creating Python virtualenv in Windows

  1. pip install virtualenv

  2. python -m venv myenv

  3. myenv\Scripts\activate

  4. deactivate

Docker to build and run

  • $ docker pull mysql:8.2

  • $ docker images

  • $ docker run --name test-mysql -e MYSQL_ROOT_PASSWORD=strong_password -d mysql

  • $ docker exec -it container_name bash // Check your docker website.

    • ex : docker exec -it test-mysql bash
  • $ mysql -u root -p // Type this command it will show downside text

  • Enter password: ...

  • mysql>

  • docker run -e MYSQL_ROOT_PASSWORD=your_password -p 3306:3306 mysql:8.0.36-1.el8

    • example : docker run -e MYSQL_ROOT_PASSWORD=your_password -p 3306:3306 mysql:8.0

Docker for running the docker fastapi

docker run --name nervous_kowalevski -d fastapi-app-simple:latest

Build the Docker image: Once you have your Dockerfile and application files ready, navigate to the directory containing these files and run the following command to build the Docker image:

  • docker build -t my-image .

    Replace my-image with the desired name for your image.

    Run a Docker container: After successfully building the Docker image, you can run a container using the following command:

  • docker run -d --name my-container -p 8080:80 my-image

Docker commands

  1. stop the docker : sudo docker stop count-web-application-container

  2. remove the docker : sudo docker rm count-web-application-container

  3. For clear : docker system prune -a

  4. For checking logs : docker logs count-web-application-container

for pushing to docker hub

  1. For checking log files : docker exec container_id_or_name cat /path/to/log/file

  2. docker tag count-web-application(name of the image) dockerhub/name

  3. docker push dockerhub/name

  4. docker images

  5. sudo docker rmi 5323383c00e8(pid of image)

  6. For docker logs : sudo docker logs container-name

Note : name is application name.

Pull the docker image:

  1. sudo docker pull dockerhub/name:latest

  2. sudo docker run -d --name container-name -e AWS_ACCESS_KEY_ID=access_key_id -e AWS_SECRET_ACCESS_KEY=access_key -e AWS_DEFAULT_REGION=ap-south-1 -p 8001:8001 dockerhub/name

Docker commands for removing container and image

  • For ec2 instance removing and new container: stop the container : sudo docker stop count-web-application-container

  • remove the docker : sudo docker rm count-web-application-container Check the id of image : sudo docker images remove the image : sudo docker rmi 0d051dca991e(id of the image)

python 3.11 in ec2 instance commands

MEmory checking : df -h

  1. sudo apt update

  2. sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev
    libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev
    xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git

  3. wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz

  4. tar -xf Python-3.11.0.tgz

  5. cd Python-3.11.0

  6. ./configure --enable-optimizations

  7. make -j 8 # Adjust the number according to the number of CPU cores

  8. sudo make altinstall

  9. python3.11 -m venv myenv

  10. source myenv/bin/activate

For ip address finding

  1. lsof -i :8000

  2. lsof -i -P -n | grep LISTEN

Simple docker

    #Use the official Python image
    FROM python:3.11.5
    
    # Install necessary system dependencies including libgl1-mesa-glx
    RUN apt-get update && apt-get install -y libgl1-mesa-glx
    
    # Set the working directory in the container
    WORKDIR /app
    
    # Copy the dependencies file to the working directory
    COPY requirements.txt .
    
    # Install REQUIREMENTS
    RUN pip install --upgrade pip && \
      pip install -r requirements.txt && \
      pip uninstall -y fastapi && \
      pip install fastapi==0.97.0 && \
      pip uninstall -y fastapi-users && \
      pip install fastapi-users==12.1.2 && \
      pip uninstall -y fastapi-users-db-beanie && \
      pip install fastapi-users-db-beanie==3.0.0 && \
      pip uninstall -y fastapi-users-db-mongodb && \
      pip install fastapi-users-db-mongodb==1.1.0 && \
      pip uninstall -y jwt PyJWT && \
      pip install PyJWT && \
      pip uninstall -y motor &&\
      pip install motor==3.4.0
        
    
    # Copy the content of the local src directory to the working directory
    COPY . /app
    
    # Command to run the FastAPI application with Uvicorn
    CMD ["uvicorn","api1:app","--host","0.0.0.0","--port","8001"]

For docker installation in ec2

  1. sudo apt update

  2. sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

  3. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

  4. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

  5. sudo apt update

  6. sudo apt install -y docker-ce docker-ce-cli containerd.io

  7. sudo systemctl start docker

  8. sudo systemctl enable docker

  9. docker --version

Command for docker in ec2

echo "Running a new container from the latest image..."

Run a new container from the latest image with a specific name

  • docker run -d --name fastapi-app-simple-container -e AWS_ACCESS_KEY_ID= tour_access_key_id -e AWS_SECRET_ACCESS_KEY=your_access_key -e AWS_DEFAULT_REGION=ap-south-1 -p 8000:8000 amarnathreddysurapureddy0201/fastapi-app-simple:latest

    1. amarnathreddysurapureddy0201 is user name

    2. fastapi-app-simple:latest is image

    3. Container : fastapi-app-simple-container

Yolo training

  • !yolo task=detect mode=train model=yolov8s.pt data= "/data.yaml" epochs=1000 imgsz=640 batch=4 patience=150 save=True save_period=25 plots=True device=0

Interview Questions

1) How yolo works?

  • The basic behind idea behind yolo is to divide the i/p image into a grid of cellsand , for each cell, predict the probabilities of the presence of object and bounding box coordinates of the object.

  • Inputting an image: The image is resized to 448x448, then passed through a CNN to extract features

  • Dividing the image into a grid: The grid size can be 13x13 or 19x19, with each cell containing 5 boxes

  • Predicting bounding boxes and class probabilities: Each cell predicts a set of bounding boxes and class probabilities

  • Removing overlapping guesses: YOLO uses non-maximum suppression to remove any guesses that overlap with other guesses

  • Outputting the remaining guesses: YOLO outputs the remaining guesses as rectangles and object labels

2) Object detection vs segmentation

  • Finding the object and location of the object.

  • Fine-grained information

  • Object detection: Focuses on identifying and localizing specific objects within an image or video. It involves finding bounding boxes around objects and classifying them.

  • Segmentation: Focuses on dividing an image into meaningful regions and assigning class labels to each pixel. It provides fine-grained information about object boundaries and regions.

3) Different types of filters:

  • Smoothing filters:

    • Gaussian filter: This filter applies a two-dimensional Gaussian function to the neighborhood pixels to smoothen the image. The greater the standard deviation of the Gaussian distribution, the greater the blur will be.

    • Median filter: This filter replaces each pixel value with the median of the neighboring pixels. It is effective in reducing the salt and pepper noise from the images.

  • Sharpening filters

    • Laplacian filter: This filter convolves over the image based on the principle of the Laplace transform. It calculates the image matrix's second-order derivative and highlights its edges and details by emphasizing regions of rapid intensity changes.
  • Edge detection filters:

    • Sobel filter: It detects the edges by calculating the horizontal and vertical derivatives of the image and then combining them.

      • Sobel function in opencv is used to perform edge detection on an image. it computes the gradient of the image intensity at each pixel, which can be used to detect edges or sharp changes in intensity. Sobel edge detection typically involves convolving the image with a Sobel kernel in the both the horizontal and vertical directions to compute the gradient magnitude and direction.
    • Robert filter: It detects the edges by calculating and combining derivatives of both the image diagonals.

  • Thresholding filters:

    • Binary threshold filter: This filter converts a greyscaled image into a binary image by setting pixel values above a threshold to white and values below the threshold to black.

    • Adaptive threshold filter: It is similar to the binary threshold filter, but it determines its threshold based on the local neighborhood of each pixel.

  • Morphological filters:

    • Dilation filter: This filter expands the boundaries of regions in an image by replacing each pixel with a maximum value in its neighborhood. It helps fill gaps, join broken lines, and enlarge objects.

    • Erosion filter: This filter shrinks the boundaries of regions by replacing each pixel with the minimum value with its neighborhood. It helps remove noise, separates connected objects, and reduces object size.

  • The anisotropic diffusion filter (ADF) is a technique used in image processing and computer vision to reduce image noise while preserving image content.

  • The Bilateral Filter is a non-linear, edge-preserving smoothing filter that is commonly used in Computer Vision as a simple noise-reduction stage in a pipeline.

  • Morphological operations include dilation, erosion, opening, closing, and boundary extraction. For example, dilation can expand image pixels or add pixels on object boundaries, while erosion can shrink the image pixels or remove pixels on object boundaries. Compound operations often combine dilation and erosion, such as closing, which performs dilation and then erosion, or opening, which performs erosion and then dilation.

4) Different types of segmentation(Semantic vs instance segmentation):

  • Semantic segmentation : One class consider as same entity.

  • Instane segmentation : Distinguishes between different instances of the same class

  • Semantic segmentation treats all objects within a category as one entity. Instance segmentation treats multiple objects in the same class as unique individual instances. Semantic and instance segmentation have real-world applications such as: Urban planning and smart city management, Medical diagnostics and research, Autonomous vehicles and advanced driver-assistance systems (ADAS), Analyzing medical scans, and Satellite or aerial imagery.

5) How RT-DERT works?

  • Efficient Hybrid Encoder: Baidu's RT-DETR uses an efficient hybrid encoder that processes multiscale features by decoupling intra-scale interaction and cross-scale fusion. This unique Vision Transformers-based design reduces computational costs and allows for real-time object detection.

  • Efficient Hybrid Encoder: Baidu's RT-DETR uses an efficient hybrid encoder that processes multiscale features by decoupling intra-scale interaction and cross-scale fusion. This unique Vision Transformers-based design reduces computational costs and allows for real-time object detection.

  • IoU-aware Query Selection: Baidu's RT-DETR improves object query initialization by utilizing IoU-aware query selection. This allows the model to focus on the most relevant objects in the scene, enhancing the detection accuracy.

  • Adaptable Inference Speed: Baidu's RT-DETR supports flexible adjustments of inference speed by using different decoder layers without the need for retraining. This adaptability facilitates practical application in various real-time object detection scenarios.

6) Difference between low level and highlevel languages?

High-level languages are easy to understand, debug, and are widely used today. They are portable and do not depend on machines. Low-level languages, on the other hand, are machine-friendly, difficult to understand, and not portable. They are machine-dependent and not commonly used for programming today.

13) What is REST API

  • REST API stands for Representational State Transfer Application Programming Interface. It is an architectural style for designing networked applications. RESTful APIs are designed to be simple, lightweight, and scalable, making them popular for building web services and APIs.

    • Statelessness:

    • Resources and URIs:

    • HTTP Methods:

    • Representation:

    • Uniform Interface:

    • State Transfer:

  • RESTful APIs are widely used in web development for building web services, mobile applications, and IoT (Internet of Things) devices. They provide a flexible and scalable way to expose functionality over the web, allowing different clients to interact with server-side resources using standard protocols and formats.

16) how do you handle missing or corrupted data in a dataset

  • Method 1 is deleting rows or columns.

    -We usually use this method when it comes to empty cells. For example, if the majority of our data is missing for a column or for a row, we can simply delete them.

  • Method 2 is replacing the missing data with aggregated values.

    • In this case, we can calculate the aggregated value based on the rest of the values we have in the column and put the received number to the empty spot.
  • Method 3 is creating an unknown category.

    • Categorical features have a number of possible values, which gives us an opportunity to create one more category for the missing values. This way we will lower the variance by adding new information to the data. This could be used when the original information is missing or cannot be understood,
  • Method 4 is predicting missing values.

    • where we have no missing values, we can train a statistical or machine learning algorithm in order to predict the missing values. Since among the samples for which this training is performed, there are missing values, it is necessary to replace them initially using one of the simplest methods for recovering gaps. This way will give us better performance, unless, of course, a missing value should have a high variance. As always, an example. With Madan here, we don’t have any number for the experience column. If we have a bigger table, with more people with similar information — the same country, profession, and education — it is possible to calculate correctly the most possible result for the missing feature. In this case, even if we didn’t guess absolutely right.

17) What is Random seed?

  • Random seed is used to ensure that results are reproducible. This is important in data science and other fields. For example, in Python, random seed is used to generate a pseudo-random encryption key, which is an important part of computer security. Random seed also makes optimization of codes easy where random numbers are used for testing.
import random

random.seed(10)
print(random.random())

random.seed(10)
print(random.random())

18) Why YOLO ?

  • Model for real time detection.

  • Yolov1 : problem with Small objects.

  • Yolov2 : Bounding boxes + Multi class

  • Yolov3 : Pyramid n/w's

    • Different scales and resolutions
  • Yolov4 : Accuracy and speed

    • CSPDarknet53 as the backbone network, Mish activation function, and improved data augmentation.
  • Yolov5 :

  • Yolov8 :

    • Along with its versatility, YOLOv8 boasts several other innovations that make it a strong candidate for a wide range of object detection and image segmentation tasks. These include a new backbone network, anchor-free detection head, and loss function. Additionally, YOLOv8 is highly efficient and can run on a variety of hardware, from CPUs to GPUs.
  • Yolov9:

    • This model is superior to RT-DETR and YOLO-MS in terms of accuracy and efficiency, setting new standards in lightweight model performance.

19) What is Convolutional Neural Network?

  • CNN stands for Convolutional Neural Network, which is a class of deep neural networks commonly used in tasks involving visual imagery analysis, such as image classification, object detection, and image segmentation.

  • Here's a breakdown of CNNs and their components:

    • Convolutional Layers : These are the fundamental building blocks of CNNs. Convolutional layers apply convolution operations to the input data using filters (also called kernels) to extract features. The filters slide over the input data, computing dot products at each position, which helps capture spatial patterns and local dependencies in the data.

    • Pooling Layers: Pooling layers are typically inserted between convolutional layers to reduce the spatial dimensions of the feature maps while retaining the most important information. Common pooling operations include max pooling and average pooling, which downsample the input by taking the maximum or average value within each pooling region.

    • Activation Functions: Activation functions introduce non-linearity into the network, allowing CNNs to learn complex patterns and relationships in the data. Popular activation functions used in CNNs include ReLU (Rectified Linear Unit), sigmoid, and tanh.

    • Fully Connected Layers: Fully connected layers, also known as dense layers, are typically found at the end of a CNN architecture. These layers connect every neuron in one layer to every neuron in the next layer, allowing the network to learn high-level features and make predictions based on the extracted features.

    • Flattening: Before passing the output of convolutional and pooling layers to fully connected layers, the feature maps are flattened into a one-dimensional vector. This flattening operation reshapes the data into a format suitable for input to the fully connected layers.

    • CNNs are trained using backpropagation and gradient descent algorithms, where the network learns to minimize a loss function by adjusting its weights and biases during the training process. They are particularly effective in handling high-dimensional data like images due to their ability to automatically learn hierarchical representations of features directly from the raw data.

20) What is the purpose of GridSearcCV

  • GridSearchCV is a technique for finding the optimal parameter values from a given set of parameters in a grid. It's essentially a cross-validation technique. The model as well as the parameters must be entered. After extracting the best parameter values, predictions are made

    params = dict()
    
    params["C"] = (1e-6,1,10,100.0 )
    
    params["gamma"] = (1e-6,1,10,100.0)
    
    params["degree"] = (1,2,3)
    
    params["kernel"] = ['linear','poly', 'rbf', 'sigmoid']
    

21) How to change tensor variable Now let's try to change one of the elements of the changable tensor.

# Will error (requires the .assign() method)
changeable_tensor[0] = 7
changeable_tensor
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-daecfbad2415> in <cell line: 2>()
      1 # Will error (requires the .assign() method)
----> 2 changeable_tensor[0] = 7
      3 changeable_tensor

TypeError: 'ResourceVariable' object does not support item assignment
To change an element of a tf.Variable() tensor requires the assign() method.

# Won't error
changeable_tensor[0].assign(7)
changeable_tensor

22) Difference Between set, multiset, unordered_set, unordered_multiset in C++**

  • Set: Sets are associative containers that store unique elements following a specific order. Following are the properties of sets:

    • Stores the values in sorted order. Stores only unique values. Elements can only be inserted or deleted but cannot be modified. We can erase more than 1 element by giving the start iterator and end iterator position. Traversal using iterators. Sets are implemented as Binary Search Tree.
  • Multisets: Multisets are associative containers that store multiple elements having equivalent values following a specific order. Following are the properties of multisets:

    • Stores elements in sorted order.

    • It allows the storage of multiple elements.

    • We can erase more than 1 element by giving the start iterator and end iterator.

  • unordered_set: unordered_set are associative containers that store unique elements in no particular order. Following are the properties of Unordered_sets:

    • Elements can be stored in any order. ( no sorted order )

    • Stores only unique values.

    • Hash-table used to store elements.

    • We can erase only the element for which the iterator position is given.

  • Unordered_multiset: Unordered_multiset is an associative container that contains a set of non-unique elements in unsorted order. Following are the properties of Unordered_multiset:

    • Elements can be stored in any order.

    • Duplicate elements can be stored.

    • Hash-table used to store elements.

    • We can erase only the element for which the iterator position is given.

23) Map vs multimap:

  • Map stores unique key-value pairs in a sorted manner. Each key is uniquely associated with a value that may or may not be unique. A key can be inserted or deleted from a map but cannot be modified. Values assigned to keys can be changed. It is a great way for quickly accessing value using the key and it is done in O(1) time.

  • Multimap is similar to map with an addition that multiple elements can have same keys. Also, it is NOT required that the key value and mapped value pair has to be unique in this case. One important thing to note about multimap is that multimap keeps all the keys in sorted order always. These properties of multimap makes it very much useful in competitive programming.

24) Backward Pass (Backpropagation):

  • Backpropagation is the process of computing the gradient of the loss function with respect to each weight in the network, layer by layer, starting from the output layer and moving backward to the input layer. This gradient represents the direction and magnitude of change that each weight should undergo to minimize the loss function.

26) Greedy search vs Beam search:

  • Greedy search and beam search are both search algorithms used in machine learning and natural language processing (NLP) tasks. They differ in how they make decisions during the search process:

  • Greedy search Selects the single most likely option. It's simple and fast, but it only considers each position in isolation.

  • Beam search Maintains a beam of multiple candidates at each step, ranked based on their probabilities. It's more complex and computationally expensive than greedy search, but it's more accurate because it considers future steps when selecting the next word.

27) Super Resolution in OpenCV:

  • Overview: FSRCNN is an optimized and faster variant of the SRCNN model. It employs a deep neural network with a smaller filter size and fewer parameters, making it faster while still providing good image quality.

  • https://learnopencv.com/super-resolution-in-opencv/

  • Super-resolution refers to the process of upscaling or improving the details of the image. Follow this blog to learn the options for Super Resolution in OpenCV. When increasing the dimensions of an image, the extra pixels need to be interpolated somehow. Basic image processing techniques do not give good results as they do not take the surroundings in context while scaling up. Deep learning and, more recently, GANs come to the rescue here and provide much better results.

  • Simply enlarging an image through conventional methods often results in a blurry or pixelated appearance.

    • Resnet architecture

    • Residual Blocks are skip-connection blocks that learn residual functions with reference to the layer inputs, instead of learning unreferenced functions. They were introduced as part of the ResNet architecture.

    • Different techniques:

      • EDSR : Enhanced deep resdiual network. it is slower than FSRCNN.
      • FSRCNN :
      • LapSRN : Same results as FSRCNN.
      • ESPCN : Same speed as FSRCNN , giving less count than fsrcnn.
    • Methods:

      • Interpolation-Based Methods:

        • Nearest-Neighbor Interpolation: Simplest method, copying the nearest pixel value to upscale. This often results in blocky images.

        • Bilinear Interpolation: Uses a weighted average of the four nearest pixels, resulting in smoother images but still with some blurring.

        • Bicubic Interpolation: Considers 16 nearest pixels for a more refined result, reducing blurring compared to bilinear interpolation.

      • Reconstruction-Based Methods:

        • These methods assume a mathematical model to reconstruct a high-resolution image from a low-resolution one, often involving optimization techniques.

        • Example: Solving for the HR image that, when downsampled, closely matches the LR image while maintaining plausible detail and smoothness.

      • Learning-Based Methods:

        • Single-Image Super-Resolution (SISR): Enhances a single low-resolution image using a pre-trained model.

        • Multi-Image Super-Resolution: Combines information from multiple low-resolution images of the same scene to produce a higher-resolution image.

        • Deep Learning Models: Utilize neural networks trained on large datasets of LR-HR image pairs to predict high-resolution details.

29) A (typical) architecture of a convolutional neural network

  • A convolutional layer is the main building block of a CNN. It contains a set of filters (or kernels), parameters of which are to be learned throughout the training. The size of the filters is usually smaller than the actual image. Each filter convolves with the image and creates an activation map.

  • A hidden layer in a neural network is a layer of neurons that is neither the input nor output layer. The term "hidden" refers to the fact that these layers are not directly observable and are responsible for the depth of neural networks, allowing them to process complex data representations.

  • The purpose of the pooling layers is to reduce the dimensions of the hidden layer by combining the outputs of neuron clusters at the previous layer into a single neuron in the next layer

The "2D" means our inputs are two dimensional (height and width), even though they have 3 colour channels, the convolutions are run on each channel invididually. filters - these are the number of "feature extractors" that will be moving over our images. kernel_size - the size of our filters, for example, a kernel_size of (3, 3) (or just 3) will mean each filter will have the size 3x3, meaning it will look at a space of 3x3 pixels each time. The smaller the kernel, the more fine-grained features it will extract. stride - the number of pixels a filter will move across as it covers the image. A stride of 1 means the filter moves across each pixel 1 by 1. A stride of 2 means it moves 2 pixels at a time. padding - this can be either 'same' or 'valid', 'same' adds zeros the to outside of the image so the resulting output of the convolutional layer is the same as the input, where as 'valid' (default) cuts off excess pixels where the filter doesn't fit (e.g. 224 pixels wide divided by a kernel size of 3 (224/3 = 74.6) means a single pixel will get cut off the end.

stride = ((n-f)/s)+1

n1 X n2 =>  (((n1-f)/s)+1) * (((n2-f)/s)+1)
n - input image size
f - filter size
s - stride size

example : 6 X 7 image size , filter(f=2) and stride is 3

	(((6-2)/3)+1) * (((7-2)/3)+1)

stride + padding : f=2 and stride =3

n1 X n2 =>  (((n1-f+2p)/s)+1) * (((n2-f+2p)/s)+1)

(((n1-2+2p)/3)+1) * (((n2-2+2p)/3)+1)

The Adam optimizer, short for “Adaptive Moment Estimation,” is an iterative optimization algorithm used to minimize the loss function during the training of neural networks. Adam can be looked at as a combination of RMSprop and Stochastic Gradient Descent with momentum

35) Solid priniciples of Python

**- Single Responsibility Principle**

	Only for one purpose.

**- Open-Closed Principle**

36) Confussion matrix**

	Posi        Negative
      ---------------------------------

Positive | | FP | Preecesion = (TP/(TP+FP)) | TP | |

	  ---------------------------------

Negative | | | | FN | TN |

	  ---------------------------------
   
   Recall = TP/(TP+FN)

Accuracy = (TP+TN)/(TP+TN+FP+FN)

37) What is grdent descent:

  • Gradient descent is an optimization algorithm used to minimize the loss function in machine learning and neural networks. It is a method for finding the minimum of a function by iteratively moving towards the steepest descent, as defined by the negative of the gradient.

    • Loss Function:

      The loss function (or cost function) measures the difference between the predicted values and the actual target values. The goal of training a neural network is to minimize this loss function.

    • Gradient:

      The gradient is a vector of partial derivatives of the loss function with respect to each parameter (weights and biases) of the model. It points in the direction of the steepest increase in the loss function.

    • The gradient descent algorithm involves the following steps:

      • Initialization, Compute the Loss, Compute the Gradient, Update Parameters and Repeat

38) when gradient descent occurs forward propagation or backwards propagation

  • Gradient descent primarily occurs during backpropagation in the context of training neural networks. Here's a brief overview of the process:

  • Backward Propagation (Backpropagation):

    • The calculated error from forward propagation is propagated back through the network.

    • Gradients of the loss function with respect to the weights and biases are computed using the chain rule of calculus.

    • These gradients indicate how much the weights and biases need to be adjusted to reduce the error.

    • Therefore, while forward propagation is about calculating the output and the loss, gradient descent (the optimization step) takes place during backpropagation, where the gradients are used to update the model's parameters.

39) How to reduce gradient decent:

  • Reducing or optimizing the gradient descent process can involve several strategies to improve the efficiency and effectiveness of training a neural network. Here are some key techniques:

    • Learning Rate Adjustment:

    • Gradient Clipping:

    • Batch Normalization:

      Batch normalization normalizes the input to each layer so that they have a mean of zero and a variance of one

    • Momentum

    • Optimization Algorithms:

    • Regularization Techniques:

      Regularization is a technique used in ML to prevent overfitting by adding a penalty term to the loss fn that penalizes large coefficients in the model. This penalty encourages the model to favor simpler solutions and helps prevent it from fitting the noise in the training data too closely. Common regularization techniques include L1 regularization(Lasso) and L2 regularization(Ridge).

      • L1 regularization adds the absolute value of the coefficient as a penalty term.

      • L2 regularization adds the squared magnitude of the coefficient as a penalty term.

      • Randomly selected neurons are ignored during training L1/L2 Regularization.

      • Regularization is a technique used in machine learning to prevent overfitting, which occurs when a model learns the training data too well, capturing noise and fluctuations rather than the underlying pattern. Regularization adds additional constraints or penalties to the model to ensure it generalizes better to unseen data.

      • Here are the most common regularization techniques:

        • Lasso(L1 regularization).

        • Ridge(L2 regularization).

    • Proper Initialization:

    • Mini-Batch Gradient Descent:

    • Data Augmentation and Preprocessing:

    • Early Stopping:

44) Gridsearchcv vs randomsearcv

  • Both GridSearchCV and RandomSearchCV are techniques used in machine learning for hyperparameter tuning, which is the process of finding the best hyperparameters for a machine learning model.

-GridSearchCV:

- Slow, High computational power, Detecting for every combination of parameters, Not feasible for high-dimensional hyperparameter spaces, results same.
  • Randomsearchcv:

    • Fixed no.of hyperparameters combinations, high efficiency, less computational power.
  • Choosing between GridSearchCV and RandomSearchCV depends on the specific needs of your project. If you have a small hyperparameter space and want to ensure finding the best parameters, GridSearchCV is the way to go. If you have a large hyperparameter space or limited computational resources, RandomSearchCV is typically more efficient and can still yield good results.

45) Machine learning Deep learning

  • Enables m/c to take decisions on their own. based on past data.

  • Enables m/c's to take decesions with the help of artificial neural n/w's.

  • Needs only small amount of data.

  • Needs a large amount of training data.

  • Works well on low-end systems.

  • Needs high end s/m to work.

  • Most features need to identified in advanced and manually coded.

  • learns features from the data provided.

  • The Problem is divided into parts and solved individually and then combined.

  • The problem is solved in an end-to-end manner.

46) Supervised learning is a machine learning technique that involves teaching a computer to perform tasks or make decisions by analyzingdata and predicting outcomes. It's a widely used approach in business, with applications in many industries. Here are some examples:**

  • Finance: Supervised learning helps detect fraudulent transactions, predict stock prices, and assess creditworthiness.

  • Marketing: It helps personalize marketing campaigns, predict customer churn, and score leads.

  • Sales: It helps improve dynamic pricing models.

  • Customer service: It helps create chatbots that provide real-time recommendations and on-demand help.

  • Security: It helps identify suspicious transactions and prevent fraud.

  • Image recognition: It helps computers recognize objects in images.

  • Spam detection: It helps identify and prevent spam emails.

  • Healthcare: It helps clinicians make diagnoses and choose treatment options.

  • Manufacturing: It helps with quality control.

47) Applications Where Precision is More Valuable than Recall**

  • Spam Detection: In email spam detection, it's crucial to minimize the number of legitimate emails marked as spam (false positives). High precision ensures that the emails classified as spam are indeed spam, even if some spam emails are missed (lower recall).

  • Medical Diagnosis: In medical testing, particularly when screening for a serious but not immediately life-threatening condition, it might be more important to ensure that a positive result is truly indicative of the condition. For instance, a diagnostic test for a rare condition should have high precision to avoid unnecessary stress and further invasive testing on healthy patients.

  • Fraud Detection: In financial transactions, identifying fraudulent activities should have high precision to prevent normal transactions from being flagged as fraudulent. False positives could inconvenience customers and lead to a loss of trust in the financial institution.

  • Search Engines and Recommendation Systems: In these applications, it is often more important that the returned results are highly relevant (high precision), even if it means some relevant results are missed (lower recall). Users typically prefer highly accurate results rather than sifting through numerous irrelevant ones.

  • Legal Document Review: In e-discovery and legal document review, it's essential that the documents identified as relevant are indeed relevant to avoid legal risks and inefficiencies. High precision is preferred to ensure that the relevant documents are identified correctly.

  • Advertising: In targeted advertising, ensuring that the ads shown are highly relevant to the user (high precision) can improve user experience and engagement, even if it means some potential customers are not shown the ad (lower recall).

48) There are several types of segmentation in machine learning (ML), including image segmentation, market segmentation, and user segmentation:

  • Image segmentation

      A process that involves labeling pixels in an image:
      
          - Instance segmentation: Assigns a unique label to each pixel to differentiate between different instances of the same class
      
          - Panoptic segmentation: A combination of semantic and instance segmentation that labels each pixel with a class label and identifies each object instance in the image
      
          - DBSCAN clustering: Groups pixels into clusters based on their density.
    
  • Market segmentation

    • A process that involves grouping buyers based on characteristics that may influence their behavior:

    • Behavioral segmentation: Based directly on consumer behavior

    • Geographic segmentation: Groups buyers by physical location, which can influence buying habits due to climate or resource access

    • Demographic segmentation: Segments customers based on demographic factors, such as characteristics of a person or population

    • Psychographic segmentation: Studies consumers based on their mental attributes, such as interests, values, lifestyle, income, and beliefs

  • User segmentation

    • A process that involves segmenting customers based on characteristics:

    • Supervised segmentation: Involves the marketer establishing predefined rules, and machine learning organizes the data according to those rules

49) Activation functions**

  • For capturing complex pattern

  • Sigmoid function:

      S(x)= {1}/{1+e^{-x}}
    
    	Range (0,1)
    
      Vanishing gradent
    
  • tanh :

      ((e**x −e ** −x)/(e **x + e **−x))
    
      range : (-1,1)
    
      vanishing gradent
    
  • relu:

      S(x) = max(0,1)
    
      range : (0,inf)
    
      mitigate vanishing gradent
    
      dead neurons 
    
  • leaky - relu:

      range = (-inf,inf)
    
      S(x) = max(0.01x,x)
    
      prevent dead neurons
    
      Computational over head
    
  • Softmax:

      Used in the o/p layer of classification n/w's to represent possibilites.
    

50) Loss functions/cost functions

  • As mentioned, loss functions help gauge how a machine learning model is performing with its given data, and how well it’s able to predict an expected outcome. Many machine learning algorithms use loss functions in the optimization process during training to evaluate and improve its output accuracy. Also, by minimizing a chosen loss function during optimization, this can help determine the best model parameters needed for given data.

-measures how well a machine learning model performs.

  • Regression loss:

    • Mean squared error:

    i- Mean Absolute error:

    ii- Huber Loss:

  • Classification loss:

    • Binary cross entropy:

    i- Categorical cross entropy:

    ii- Sparse categorical cross entropy:

  • Specialized loss functions:

    • Kullback-leibler

    i- Hinge loss

    ii- cosine similarity

    iv) Dice loss:

51) GAN(generative Adversarial Network)

  • Unsupervised learning, 2 neural network(discriminator and a generator), image synthesis, style transfer, text-to-image.

    • Generative

    i- Adversarial

    ii- Networks

  • Type of gan's:

    • Vanilla GAN(Stochastic gradent descent)

    i- Conditional GAN()

    ii- Deep Convolution GAN

    iv) Laplace Pyramid GAN

    v) Super resolution GAN

52)How would you approach developing a solution for synchronising data from multiple cameras? What challenges might you face, and how would you overcome them?**

  • Running multiple cameras : With the help of threads we will run the cameras. parallel operations.

  • Frame capture and storing : Capturing frames and attach time stamp with microseconds precision. Save frames in buffer to manage timing.

  • Data alignment and preprocessing : Process the frames based on time stamps. Process frames in parallel to reduce latency.

  • Storage and Management : Design a storage system that can handle synchronized data streams. Implement robust error handling to deal with data loss or corruption.

  • latency: Use time-stamped frames and buffer data to account for latency variations. Implement Quality of Service to prioritize synchronization data.

  • Frame rates and resolution: Down sample or up sample frames to match the target synchronization rate. Use image processing techniques to align frames spatially.

  • Overhead processing : parallel processing like GPU. will run the application.

  • Corruption of frames : Implement error detection and correction mechanisms.

53) HSV vs RGB:

  • RGB: Uses Red, Green, and Blue channels. Common for image display and basic processing. Not always intuitive for color-based tasks.

  • HSV: Uses Hue, Saturation, and Value channels. Better for color segmentation and analysis. More robust to lighting changes and perceptually intuitive.

  • Hue: Represents the type of color (e.g., red, green, blue). It is an angle on the color wheel, ranging from 0 to 360 degrees, where each angle corresponds to a specific color.

  • Saturation: Represents the intensity or purity of the color. It ranges from 0 to 100%, where 0% is a shade of gray and 100% is the most vivid version of the color.

  • Value: Represents the brightness or lightness of the color. It ranges from 0 to 100%, where 0% is completely black (no light) and 100% is the brightest and most intense color.

  • Practical Example in Computer Vision :

    • Color Detection:

      • RGB: Detecting a red object might involve checking if the red channel is significantly higher than the green and blue channels.

      • HSV: Detecting a red object would involve looking for a specific range of hue values that correspond to red, often making the task simpler and more robust to lighting changes.

    • Image Segmentation:

      • RGB: Segmenting an image by color can be complex because similar colors can have very different RGB values.

      • HSV: Segmentation can be easier and more accurate because the hue channel can be used to directly identify regions of specific colors.

54) Bias-Variance Trade-off**

  • The bias-variance trade-off is the balance between the complexity of the model and its ability to generalize to new data. The goal is to find a model that minimizes both bias and variance, thus achieving low overall error.

    • Underfitting (High Bias and Low Variance): The model is too simple to capture the underlying patterns in the data, resulting in high error on both the training and test sets.

    • Overfitting (Low Bias and High Variance): The model is too complex and captures the noise in the training data, resulting in low training error but high test error.

    • Optimal Model (Balanced Bias and Variance): The model captures the underlying patterns in the data well without being overly complex. This results in low training and test error.

  • Techniques to Manage Bias and Variance

    • Increase Model Complexity: Adding more features, using more complex algorithms, or adding layers to neural networks can reduce bias.

    • Regularization: Techniques like L1 (Lasso) and L2 (Ridge) regularization can help reduce variance by penalizing complex models.

    • Cross-Validation: Using cross-validation can help in selecting models and hyperparameters that generalize well to new data.

    d)Ensemble Methods: Techniques like bagging (e.g., Random Forest) and boosting (e.g., AdaBoost) combine multiple models to balance bias and variance.

    e) Collecting More Data: More training data can help in reducing variance by providing more examples for the model to learn from.

55) what is compiler

In computing, a compiler is a computer program that translates computer code written in one programming language into another language.

56) AI Compiler

An AI compiler translates an ML model into multi-level IRs in upper and lower layers. The upper layer is focused on hardware-independent but framework-related transformations and optimizations. The lower layer is responsible for hardware-related optimizations, code generation, and compilation.

The good news is that ML compilers can significantly improve the efficiency of large-scale model serving. Then came a lot of ML compilers: Apache TVM, NVIDIA TensorRT, ONNX Runtime, LLVM, Google MLIR, TensorFlow XLA, Meta Glow, PyTorch nvFuser, and Intel PlaidML and OpenVINO.

In general, the upper layer takes an ML model generated by an ML framework (e.g., PyTorch) as input and converts the model into a computational graph representation (i.e., graph IR). The lower layer transforms the high-level IR from the upper layer into low-level IR and performs hardware-related optimizations.

57) Approaches to Enhancing RAG Beyond LLM Capabilities

Imagine AI that learns and adapts in real-time, seamlessly integrating vast knowledge for precise, context-aware responses. This is becoming reality with retrieval-augmented generation (RAG)!

- Query Rewriting

- Multi-Query RAG for Comprehensive Information Retrieval

- Advance RAG with Multi-Hop Retrieval

- Integrate Tool Use into RAG Systems

- 6 Ways for Optimizing RAG Performance

    - Well-organized & Clearly Formatted Data

    - Presence of Contextual Metadata

    - Data Quality

    - Granularity of Data Segmentation

    e) Prompt Quality

    f) Human Involvement

58) Encoder - decoder

Generative : i/p -> transalation and summerization

**59) Encoder

- Sentense classification.

- Named entity recognition.

**60) Decoder **

- text generation

- 

61)Vectorization

Vectorization in machine learning is the process of converting data into numbers that represent a point or sequence of points in a vector space. This process is used before feeding data into a machine learning model. Vectors can represent input data, such as bias and weight, or output from a machine learning model, such as a predicted class.

62 Interpolation Methods:

INTER_NEAREST:

    This method uses the nearest neighbor pixel value for the interpolated pixel. It's the fastest method but produces the least smooth results.

INTER_LINEAR:

    This is the default interpolation method in OpenCV. It performs bilinear interpolation, which calculates the pixel value based on a weighted average of the 4 nearest pixels. It offers a good balance between speed and quality.

INTER_AREA:

    This method is primarily used for downsampling (resizing to a smaller size). It calculates the pixel value by sampling the area covered by the interpolated pixel in the original image. This helps to avoid aliasing artifacts.

INTER_CUBIC:

    This method uses bicubic interpolation, which considers a 4x4 neighborhood of pixels to calculate the interpolated value. It produces smoother results than bilinear interpolation but is slower.

INTER_LANCZOS4:

    This method uses Lanczos resampling with a 4x4 kernel. It provides even smoother results than bicubic interpolation but is computationally more expensive.

Choosing the Right Interpolation:

    For upsampling (resizing to a larger size): INTER_LINEAR or INTER_CUBIC are good choices, depending on the desired trade-off between speed and quality.

    For downsampling (resizing to a smaller size): INTER_AREA is often the best choice to avoid aliasing(Distribuance).

    For real-time applications: INTER_NEAREST or INTER_LINEAR might be necessary due to their speed.

63 Problems with Normal Pointers

- Some Issues with normal pointers in C++ are as follows:

    Memory Leaks: This occurs when memory is repeatedly allocated by a program but never freed. This leads to excessive memory consumption and eventually leads to a system crash. 

    Dangling Pointers: A dangling pointer is a pointer that occurs at the time when the object is de-allocated from memory without modifying the value of the pointer.

    Wild Pointers: Wild pointers are pointers that are declared and allocated memory but the pointer is never initialized to point to any valid object or address.

    Data Inconsistency: Data inconsistency occurs when some data is stored in memory but is not updated in a consistent manner.

    Buffer Overflow: When a pointer is used to write data to a memory address that is outside of the allocated memory block. This leads to the corruption of data which can be exploited by malicious attackers.

64) What is Feature engineering

Feature Engineering is the process of creating new features or transforming existing features to improve the performance of a machine-learning model. It involves selecting relevant information from raw data and transforming it into a format that can be easily understood by a model. The goal is to improve model accuracy by providing more meaningful and relevant information.

- What are the Steps in Feature Engineering?

The steps for feature engineering vary per different Ml engineers and data scientists. Some of the common steps that are involved in most machine-learning algorithms are:

    - Data Cleansing : Data cleansing (also known as data cleaning or data scrubbing) involves identifying and removing or correcting any errors or inconsistencies in the dataset. This step is important to ensure that the data is accurate and reliable.

    i- Data Transformation

    ii- Feature Extraction

    iv) Feature Selection
        
        Feature selection involves selecting the most relevant features from the dataset for use in machine learning. This can include techniques like correlation analysis, mutual information, and stepwise regression.

    v- Feature Iteration
        Feature iteration involves refining and improving the features based on the performance of the machine learning model. This can include techniques like adding new features, removing redundant features and transforming features in different ways.

65) CNN vs DNN

DNN, or Deep Neural Network, is a type of artificial neural network with multiple hidden layers between the input and output layers.    

DNNs are capable of learning and representing complex, non-linear relationships in data. They excel at tasks such as image recognition, natural language processing, and speech recognition.

CNN, or Convolutional Neural Network, is a specialized type of DNN that is particularly well-suited for processing grid-like data, such as images. CNNs use convolutional layers to extract local features from the input, and then combine these features hierarchically to capture higher-level patterns. This makes CNNs highly effective for tasks like image classification, object detection, and semantic segmentation.

The key differences between DNNs and CNNs are:

    Architectural design: CNNs have a unique architecture with convolutional and pooling layers, whereas DNNs have a more traditional feed-forward structure with fully connected layers.

    Spatial relationships: CNNs are designed to leverage the spatial relationships in the input data, such as the relative position of pixels in an image. DNNs do not have this built-in spatial awareness.

    Parameter sharing: Convolutional layers in CNNs share parameters, which reduces the number of trainable parameters and makes the model more efficient, especially for large inputs like images.

    Applications: CNNs are particularly well-suited for computer vision tasks, while DNNs can be applied to a wider range of problems, including image recognition, natural language processing, and speech recognition.

    In summary, CNNs are a specialized type of DNN that are optimized for processing grid-like data, such as images, by leveraging the spatial relationships in the input and using a unique architectural design with convolutional and pooling layers.

66) Compile time vs Run time polymorphisms

- Compile Time Polymorphism in C++

    In compile-time polymorphism, the compiler determines which function or operation to call based on the number, types, and order of arguments. It is also called Static Polymorphism as the function calls are statically binded to its definition.

    It is further categorized into two types:

    Function Overloading

    Operator Overloading

- Run Time Polymorphism

    In run-time polymorphism, the decision of which function to call is determined at runtime based on the actual object type rather than the reference or pointer type. It is also known as Dynamic Polymorphism because the function calls are dynamically bonded at the runtime.

    Run Time Polymorphism can be exhibited by:

    Method Overriding using Virtual Functions

67) how good your in python

- I have extensive knowledge of Python and can assist with a wide range of tasks, including:

- General Programming: Writing scripts, functions, and classes.

- Data Analysis: Using libraries like Pandas, NumPy, and Matplotlib for data manipulation and visualization.

- Machine Learning & AI: Implementing models using TensorFlow, PyTorch, and scikit-learn.

e) Computer Vision: Working with OpenCV, PIL, and specialized libraries for deep learning models like YOLO.

f) Web Development: Using frameworks like Flask and FastAPI.

g) Automation: Writing scripts for automating tasks and using tools like Selenium for web automation.

h) Deployment: Setting up and deploying applications using Docker and AWS.

68) YOLOv8 vs DETR

yolo : cnn

Detr : cnn + attention.

    Hybrid encoders : 6 encoders and 6 decoders.

        Encoder : features converting into sequences of feature images.

        decoder : Prediction auxioliores + Threshold values.

        IOU query : For bounding boxes.

68)YOLOv8 Model Variants and Parameters:

- YOLOv8n (Nano)

    Parameters: ~3 million
    Purpose: Ultra-lightweight model designed for real-time performance on devices with limited computational resources like mobile devices or edge AI hardware.

i- YOLOv8s (Small)

    Parameters: ~11 million
    Purpose: Small model that provides a good balance between speed and accuracy, suitable for use cases requiring real-time inference on standard hardware.

ii- YOLOv8m (Medium)

    Parameters: ~25 million
    Purpose: Medium-sized model for applications where accuracy is more important than speed, yet still viable for near real-time inference on modern GPUs.

iv) YOLOv8l (Large)

    Parameters: ~40 million
    Purpose: Larger model for more accuracy-critical tasks, such as higher-resolution images or more complex object detection scenarios. This model requires more computational power but delivers higher accuracy.

v) YOLOv8x (Extra Large)

    Parameters: ~68 million
    Purpose: The largest model variant focused on achieving the highest possible accuracy, with a significant computational cost. Suitable for high-end GPUs or server-based inference where speed is less of a concern.

69. AI in evolution

  • AI is playing an increasingly important role in cybersecurity by enhancing the ability to detect, prevent, and respond to cyber threats. Cybersecurity involves protecting systems, networks, and data from digital attacks, and AI can improve this protection through automation, pattern recognition, and predictive analytics. Here are some ways AI helps in cybersecurity:

    • Threat Detection and Prevention:

      • Anomaly Detection: AI models can learn normal patterns of behavior within a network or system and then detect anomalies that might indicate a security breach, such as unusual login times or data transfers. Machine learning algorithms can automatically flag these deviations for further investigation.

      • Malware Detection: AI can analyze vast amounts of data to identify malware based on known patterns and behaviors. AI-powered systems can detect new, unknown malware (zero-day threats) by recognizing suspicious patterns that traditional signature-based systems might miss.

    • Automated Security Responses

      • Incident Response: AI-driven systems can automate responses to certain types of attacks, such as isolating infected systems or blocking malicious traffic. This can greatly reduce response time and minimize damage. Intrusion Detection Systems (IDS) and Intrusion

      • Prevention Systems (IPS): AI can be integrated into IDS/IPS to enhance their ability to detect and respond to network intrusions in real-time. AI can help in making decisions about which actions to take automatically, such as blocking traffic from a suspicious IP address.

    • Behavioral Analysis

      • User and Entity Behavior Analytics (UEBA): AI can analyze user behavior to identify deviations from normal activities that might indicate compromised accounts or insider threats. For example, if a user suddenly accesses large amounts of sensitive data or logs in from an unusual location, AI can trigger an alert.

      • Adaptive Authentication: AI can help with dynamic, context-aware authentication. If an authentication attempt appears suspicious (e.g., coming from a new device or unusual location), AI can require additional verification steps, such as multi-factor authentication (MFA).

    • Phishing Detection

      • Email Filtering: AI can analyze email content and detect phishing attempts by identifying patterns, such as suspicious links, attachments, or sender behavior. Unlike traditional rule-based systems, AI can learn and adapt to new phishing tactics over time.

      -URL Analysis: AI models can analyze URLs and website content to identify phishing websites before users interact with them.

    • Vulnerability Management

      • Predictive Analytics for Vulnerabilities: AI can analyze data from past attacks and vulnerabilities to predict which systems or software might be at risk in the future. This can help organizations prioritize their patching efforts and proactively address potential weaknesses.

      • Automated Penetration Testing: AI can assist in simulating cyberattacks to identify potential vulnerabilities in a system before they are exploited by attackers. This helps organizations find and fix security holes more efficiently.

    • Security Operations Center (SO- Support

      • Alert Triage: AI can help security teams manage the large volume of alerts generated by security systems by prioritizing them based on severity and relevance. This reduces alert fatigue for human analysts and allows them to focus on the most critical issues.

      • Threat Intelligence Correlation: AI can analyze data from multiple threat intelligence sources and correlate it with internal security data to provide real-time insights into emerging threats.

    • Advanced Persistent Threat (APT) Detection

      • Advanced Threat Hunting: AI can help detect and mitigate APTs, which are stealthy attacks that often go undetected for long periods. By continuously monitoring and analyzing data, AI can identify subtle signs of an ongoing APT and alert security teams to take action.

      • Behavioral Analysis for APTs: AI can detect patterns of behavior that are typical of advanced persistent threats, such as lateral movement within a network or gradual data exfiltration, allowing earlier detection and containment.

    • Fraud Detection

      • Financial Systems Protection: AI is widely used in the financial sector to detect fraudulent transactions. By analyzing transaction patterns, AI can spot unusual activities that may indicate fraud, such as identity theft or unauthorized use of credit cards.

      • Real-Time Monitoring: AI-driven systems can monitor transactions and user behavior in real-time, allowing for immediate detection and response to potential fraud.

    • Deception Technology

      • AI-Enhanced Honeypots: Honeypots are systems that lure attackers into engaging with a decoy network or system, allowing security teams to study their tactics. AI can enhance honeypots by making them more dynamic and adaptive, simulating real systems more effectively to deceive attackers.

      • AI-Based Decoys: AI can be used to create decoys that mimic valuable data or systems, tricking attackers into interacting with them instead of real assets.

    • Natural Language Processing for Threat Intelligence

      • Automating Threat Intelligence Analysis: AI, through NLP (Natural Language Processing), can analyze vast amounts of unstructured data, such as threat reports, social media, and dark web communications, to identify emerging threats. It can automatically extract relevant information and generate actionable intelligence for security teams.
    • AI for Cybersecurity Analytics

      • Predictive Threat Modeling: AI can analyze past attack patterns and use predictive modeling to forecast potential future attacks. This helps organizations proactively prepare for and mitigate against specific threats.

      • Data Correlation: AI can correlate massive amounts of security data from different sources to detect hidden patterns, providing deeper insights into potential threats and vulnerabilities.

    • AI in Ethical Hacking and Red Teaming

      • Automated Penetration Testing Tools: AI can be used in ethical hacking to automatically identify vulnerabilities and potential attack vectors. AI-powered tools can simulate attacks, helping security teams strengthen their defenses.

      • Red Teaming with AI: AI can be part of red teaming exercises, where a simulated attack is conducted on a system to test its security. AI can emulate sophisticated attack techniques to challenge the defensive systems.

    • Challenges and Considerations

      • While AI offers many benefits in cybersecurity, it also presents challenges:

      • Adversarial Attacks: Cybercriminals are also leveraging AI to create more sophisticated attacks. AI models can be targeted with adversarial examples, which are specifically designed inputs that trick AI systems. False Positives: AI systems can sometimes produce false positives, flagging legitimate activities as threats. This requires careful tuning and the involvement of human analysts.

      • Data Privacy: AI systems require access to large amounts of data, raising concerns about privacy and data protection. Ensuring compliance with regulations like GDPR is essential.

      • Conclusion : AI is revolutionizing cybersecurity by automating threat detection, enhancing incident response, and providing deeper insights through advanced analytics. However, it must be used in conjunction with traditional cybersecurity measures and human expertise to be truly effective. As both AI technology and cyber threats continue to evolve, AI will play an increasingly critical role in defending against cyberattacks.

70. Running multiple streams:

  • Running multiple streams efficiently, especially in the context of real-time applications like video processing or inference tasks, requires careful optimization at various levels of your system architecture. Here’s a breakdown of strategies to handle multiple streams efficiently, even as the number of streams increases:

    • Multithreading and Parallel Processing

      • Multithreading: Use multithreading to handle each stream in a separate thread. This allows concurrent processing of multiple streams. Ensure that the threads are managed efficiently to avoid overhead and contention.

      • Thread Pooling: Instead of creating and destroying threads for each stream dynamically, use a thread pool. A thread pool reuses a set of threads to manage multiple tasks, reducing the overhead associated with thread creation.

      • Parallelism: Use parallel processing libraries or frameworks (like OpenMP, TBB, or C++ standard library concurrency) to divide tasks across multiple CPU cores.

    • GPU Acceleration

      • GPU for Parallel Processing: Offload the processing of multiple streams to the GPU, where each stream can be processed in parallel by different threads or CUDA cores. Libraries like CUDA, OpenCL, or Vulkan can be used for efficient GPU-based parallel processing.

      • Batch Processing : If possible, batch multiple frames from different streams together and process them in a single GPU call. This reduces the overhead of multiple GPU calls and leverages the massive parallelism of GPUs.

    • Efficient Data Handling

      • Memory Management: Ensure that memory usage is optimized by reusing buffers and minimizing data copying. Memory pooling and using pinned memory can reduce latency and improve throughput.

      • Data Pipelines: Use a producer-consumer model where data is processed in stages. For example, one thread can read frames, another can process them, and a third can handle output. This pipelining can smooth out bottlenecks and improve overall throughput.

    • Load Balancing

      • Dynamic Load Balancing: Implement dynamic load balancing to distribute the workload across CPU cores or GPU threads based on the current load. This ensures that no single core or thread becomes a bottleneck.

      • Affinity: Set thread affinity to specific cores to reduce context switching and improve cache utilization.

    • Asynchronous I/O

      • Use asynchronous I/O operations to handle input/output without blocking the main processing threads. This is particularly useful for reading from or writing to streams (e.g., video files, network streams).

      • Non-blocking APIs: Use non-blocking APIs for reading and writing data. For example, in networked applications, non-blocking sockets can handle multiple connections simultaneously without blocking the main thread.

    • Pipeline Optimization with GStreamer

      • GStreamer Pipelines: If using GStreamer for handling media streams, optimize your pipelines by leveraging elements like queues, tee elements, and multiqueue for parallel processing.

      • Queues: Use queues between elements in a pipeline to decouple the processing stages. This allows each stage to operate independently and improves throughput.

      • Multi-threaded Pipelines: Split the pipeline into multiple threads using the queue element or tee element, enabling parallel processing of different parts of the pipeline.

    • Hardware-Specific Optimizations

      • Use Hardware Acceleration: Leverage hardware-accelerated video decoders/encoders if available (e.g., NVENC/NVDEC on NVIDIA GPUs). This offloads the intensive task of decoding/encoding to dedicated hardware.

      • Edge Processing: For IoT or edge devices, consider processing streams locally on powerful edge devices to reduce the data that needs to be transmitted back to a central server.

    • Scaling Up

      • Cluster or Distributed Systems: If the number of streams increases significantly, consider scaling horizontally by distributing the workload across multiple machines or a cluster. Technologies like Apache Kafka for streaming data and Kubernetes for orchestrating containers can be helpful in managing large-scale stream processing.

      • Load Distribution: Implement a load balancer to distribute incoming streams evenly across multiple processing units or servers.

    • Algorithmic Optimizations

      • Model Optimization: Optimize the machine learning models used for inference on the streams (e.g., quantization, pruning, reduced precision). This reduces the computational load and allows more streams to be processed simultaneously.

      • Frame Skipping or Downscaling: For non-critical streams, consider skipping frames or reducing the resolution to lower the processing load.

    • Monitoring and Profiling

      • Continuously monitor the performance of your system to identify bottlenecks. Use profiling tools (e.g., NVIDIA Nsight, Intel VTune, or gprof) to analyze CPU/GPU usage and optimize accordingly.

      • Adaptive Streaming: Implement adaptive algorithms that adjust the processing based on available resources (e.g., reducing frame rate when the system is under heavy load).

      Example: Multithreading in C++ with OpenMP

      #include <omp.h>
      #include <vector>
      #include <iostream>
      
      void processStream(int streamI- {
          // Simulate stream processing
          std::cout << "Processing stream: " << streamID << std::endl;
      }
      
      int main() {
          int numStreams = 10;
      
          #pragma omp parallel for
          for (int i = 0; i < numStreams; ++- {
              processStream(i);
          }
      
          return 0;
      }

      This example uses OpenMP to parallelize the processing of 10 streams across multiple threads, taking advantage of multi-core processors.

  • Summary

    • Multithreading and parallel processing are critical for handling multiple streams efficiently.
    • GPU acceleration can dramatically increase throughput by processing streams in parallel on the GPU.
    • Pipeline optimization with frameworks like GStreamer and asynchronous I/O can further improve efficiency.
    • For large-scale stream processing, consider horizontal scaling and distributed systems.
  • Implementing these strategies allows you to manage an increasing number of streams effectively, ensuring that your application remains responsive and efficient as the workload grows.

71) Trade-offs in Machine learnin:

  • In machine learning, trade-offs are common when designing and deploying models. Understanding these trade-offs helps in making informed decisions based on the specific requirements and constraints of your application. Here are some of the most common trade-offs:

    • Bias-Variance Trade-off

      • Bias refers to the error introduced by approximating a real-world problem (which may be complex) by a simplified model. High bias can lead to underfitting.

      • Variance refers to the error introduced by the model's sensitivity to small fluctuations in the training data. High variance can lead to overfitting.

      • Trade-off: Models with high bias are simpler and might not capture the underlying patterns well, leading to underfitting. Models with high variance are more complex and might capture noise in the training data, leading to overfitting. The goal is to find a balance that minimizes both bias and variance.

    • Accuracy vs. Interpretability

      • Accuracy refers to how well the model performs on unseen data.

      • Interpretability refers to how easily a human can understand why the model made a particular prediction.

      • Trade-off: Complex models like deep neural networks often achieve higher accuracy but are harder to interpret. Simpler models like decision trees or linear regression are easier to interpret but might not capture all the intricacies of the data.

    • Training Time vs. Prediction Time

      • Training Time refers to how long it takes to train a model on a dataset.

      • Prediction Time refers to how long it takes for the model to make a prediction once trained.

      • Trade-off: Some models take a long time to train but can make predictions quickly (e.g., SVM with a complex kernel). Others might train quickly but have slower prediction times (e.g., k-Nearest Neighbors).

    • Model Complexity vs. Generalization

      • Model Complexity refers to how sophisticated or complex the model structure is.

      • Generalization refers to how well the model performs on new, unseen data.

      • Trade-off: A more complex model might fit the training data very well (low training error) but might not generalize to new data (high test error). Simpler models might generalize better but at the cost of slightly higher training error.

    • Recall vs. Precision

      • Recall is the ability of the model to find all the relevant cases within a dataset (sensitivity).

      • Precision is the ability of the model to only return relevant instances among all retrieved instances.

      • Trade-off: Increasing recall typically reduces precision and vice versa. For example, in medical diagnostics, you might prioritize recall to ensure no cases are missed, even if it means more false positives.

    • Computational Resources vs. Performance

      • Computational Resources refer to the amount of CPU/GPU, memory, and storage required to train and deploy a model.

      • Performance refers to how well the model performs in terms of accuracy, speed, etc.

      • Trade-off: High-performance models often require significant computational resources, which can be costly. Lightweight models might be more resource-efficient but could sacrifice some performance.

  • How to Proceed with Trade-offs:

    • Define Your Objectives: Clearly define what you prioritize (e.g., accuracy, interpretability, speed). This will guide which trade-offs are acceptable.

    • Experiment and Validate: Experiment with different models and configurations. Use cross-validation to assess the impact of different trade-offs on your model's performance.

    • Iterate Based on Feedback: Adjust your model based on feedback from testing, real-world deployment, and stakeholder input.

    • Automated Tools: Use automated machine learning (AutoML) tools to explore various model architectures and hyperparameters, optimizing for the desired trade-offs.

    • Domain Knowledge: Leverage domain knowledge to guide your choices. For example, in healthcare, prioritizing interpretability might be more important than in a recommendation system where accuracy might take precedence.

    • Balancing these trade-offs effectively can lead to a model that meets the specific needs of your application, whether it’s in terms of accuracy, speed, or resource efficiency.

72. Self attention layers##

  • Self attention has several benefits that make it important in ml and ai : long-range dependencies: self attention allows the model to capture relationship between distant elements in a sequence, enabling it to understand complex patterns and dependencies.

73. What is embedding

  • In machine learning, embedding is the process of converting real-world objects into mathematical representations that help machine learning models understand complex relationships between data. Embeddings are a critical tool for building applications like search engines, recommendation systems, chatbots, and fraud detection systems.

74. Resnet layers

  • Convolutional layers

    These layers extract features from the input image by applying filters to detect patterns, edges, and textures.

  • Residual blocks

    These blocks contain two convolutional layers, followed by a batch normalization layer and a rectified linear unit (ReLU) activation function. The output of the second convolutional layer is added to the input, and then passed through another ReLU activation function.

  • Identity block

    This block processes and transforms the features extracted by the convolutional layers.

  • Fully connected layers

    These layers make the final classification by mapping the learned features to the output classes.layer.

75) What is statistics

  • collection data

  • organizing data

  • Analysis of data

  • interpolation

  • presentation

76) What is AI Compiler

  • An "AI compiler" is a software tool that leverages artificial intelligence techniques to optimize and translate machine learning models (like those from TensorFlow or PyTorch) into efficient code for specific hardware, essentially streamlining the process of deploying AI models on different devices by automatically adjusting the code for maximum performance based on the target hardware; it essentially acts as a compiler specifically designed for machine learning models, enabling faster execution and better resource utilization across various platforms.

77) Training Loss more than testing loss

  1. Regularization Effects

    • Regularization techniques (like dropout, L1/L2 regularization) are applied during training but not during evaluation
  2. Batch Normalization

  3. Small Training Dataset

  4. Dropout During Training

  5. Early Stopping

  6. Testing Dataset Simplicity

  7. Learning Rate Warm-Up

  8. Metric Misalignment**

78) GAN

  1. When the Generator Loss is High:

    • The generated images are of poor quality, often with unrealistic features or noise.
    • The discriminator can easily distinguish them from real images.
  2. When the Generator Loss is Low:

    • The generator produces realistic images that are hard to distinguish from real ones.
    • This often means the discriminator loss will increase.
  3. When the GAN is Balanced:

    • The generator and discriminator reach a state where both improve and challenge each other.
    • Generated images look increasingly realistic.
    • Neither the generator nor the discriminator dominates, leading to stable training.

79) Why Weight Initialization Matters

  • Weight initialization is the process of setting the starting values for a neural network’s weights before training. These weights help the network learn by adjusting them through each iteration. Poor initialization can lead to issues like:

    • Vanishing Gradient Problem: Gradients become very small, slowing down or stopping training.

    • Exploding Gradient Problem: Gradients become excessively large, leading to instability.

    • Slow Convergence: Training takes longer to reach an optimal solution.

80) Types of Weight Initialization Techniques

  • Let’s discuss the main techniques and when to use them, using simple explanations and examples.

    • Zero Initialization

      • This approach sets all weights to zero. Although simple, it’s rarely used because it causes the neurons to learn the same features, making them “indistinguishable.” In other words, the model won’t learn anything meaningful.

      • Example: Imagine each weight in the network is a gate that can adjust based on input. By setting every weight to zero, the gates remain closed and provide no unique adjustments, leading to ineffective learning.

    • Random Initialization

      • Random initialization assigns weights randomly to avoid the zero initialization problem. However, if we choose values that are too small or too large, we face other issues.

      • Small Random Weights: Initializing weights close to zero can cause gradients to vanish, especially in deep networks. This results in extremely slow training.

      • Large Random Weights: Initializing with large values can lead to the exploding gradient problem, where gradients become excessively large. This causes instability during training.

    • Xavier Initialization

      • Xavier initialization (also called Glorot initialization) aims to keep the variance of the activations constant across layers. This method assigns weights from a normal distribution with mean zero and a specific variance based on the number of neurons in each layer. Xavier initialization is particularly useful when using the sigmoid or tanh activation functions.

      • Example: Imagine the weights are distributed so that neither vanishing nor exploding gradients occur, creating a balanced learning environment for each layer.

    • He Initialization

      • He initialization is similar to Xavier but better suited for layers with ReLU activations. It scales the weights by the square root of the number of incoming neurons multiplied by 2, helping prevent the exploding gradient issue and ensuring that layers using ReLU do not “die out.”

      • Example: Think of each weight as a lever. He initialization balances these levers, giving each neuron in the network a fair chance to contribute, leading to efficient learning without saturation or instability.

81) Comparing Activation Functions with Different Initializations

  • Different activation functions like ReLU, tanh, and sigmoid behave differently depending on the weight initialization:

    • Sigmoid Activation: Sigmoid can suffer from vanishing gradients, especially when initialized with very small or large weights, leading to very slow training.

    • Tanh Activation: Similar to sigmoid, tanh can face vanishing gradients if weights are initialized too small. Xavier initialization works well here.

    • ReLU Activation: ReLU is a non-saturating function, which helps avoid vanishing gradients. However, large values in initialization can cause exploding gradients. He initialization is typically preferred for ReLU.

82) Example: How Weight Initialization Affects Model Training

  • Consider a network trained to predict a student’s package based on inputs like CGPA and IQ. Let’s see the effect of each initialization method:

    • Zero Initialization: If we set all weights to zero, the network won’t learn any meaningful pattern because each neuron will perform identically.

    • Small Random Initialization (close to zero): Using small weights with tanh or sigmoid leads to vanishing gradients. The network might learn, but it will be painfully slow.

    • Large Random Initialization: With large initial values, the gradients can explode, causing instability, especially if using tanh or sigmoid.

    • Xavier Initialization: For sigmoid or tanh, Xavier maintains balanced gradients, helping the network learn faster.

    • He Initialization: When using ReLU, He initialization keeps activations balanced across layers without the risk of saturation or vanishing gradients.

83) What is Ridge regression?

  • Ridge regression is a procedure for eliminating the bias of coefficients and reducing the mean square error by shrinking the coefficients of a model towards zero in order to solve problems of overfitting or multicollinearity that are normally associated with ordinary least squares regression.

  • Ridge regression is a statistical technique that corrects for multicollinearity in linear regression models. It's also known as L2 regularization or Tikhonov regularization. How it works

  • Ridge regression adds a penalty term to the cost function of a linear regression model. This penalty term shrinks all coefficients towards zero, without eliminating any. The result is a more complex model with more consistent results.

  • When it's useful

    • Ridge regression is useful when developing machine learning models with many parameters, especially if those parameters have high weights.

    • It's also useful when independent variables in a model are highly correlated.

  • What it's used for Ridge regression is used in many fields, including econometrics, chemistry, and engineering.

    • It can help businesses predict future purchases and make better decisions.
  • How to select the ridge parameter

    • Cross-validation is a common method for selecting the ridge parameter.

    • In cross-validation, the data is divided into subsets, and the model is trained on some subsets while being validated on the remaining ones.

  • Advantages and Disadvantages of Ridge Regression

    • Advantages:

      • Stability: Ridge regression provides more stable estimates in the presence of multicollinearity.

      • Bias-Variance Tradeoff: By introducing bias, ridge regression reduces the variance of the estimates, leading to lower MSE.

      • Interpretability: Unlike principal component regression, ridge regression retains the original predictors, making the results easier to interpret.

    • Disadvantages:

      • Bias Introduction: The introduction of bias can lead to underestimation of the true effects of the predictors.

      • Parameter Selection: Choosing the optimal ridge parameter ?k can be challenging and computationally intensive.

      • Not Suitable for Variable Selection: Ridge regression does not perform variable selection, meaning all predictors remain in the model, even those with negligible effects.

87) Why Mixed Precision?

FP16 (half precision) → faster, smaller memory but less accurate.

FP32 (single precision) → stable but slower.

Mixed precision uses FP16 where safe (matrix multiplies, conv layers) and FP32 where needed (loss, weight updates).

104) ML VS DL

- Machine Learning (ML): ML is a subset of AI where algorithms learn patterns from data to make predictions or decisions. Examples: decision trees, random forests, SVM, linear regression. It usually requires feature engineering (manual selection of input features).

- Deep Learning (DL): DL is a subset of ML that uses artificial neural networks with many layers to automatically learn complex features from raw data. It works well with large datasets and high computing power. Examples: CNNs for images, RNNs/Transformers for sequences.

105) SGD vs Adam

- The main difference is that SGD uses a single, fixed learning rate for all parameters, while Adam adaptively adjusts the learning rate for each parameter individually, using momentum and past squared gradients to improve convergence speed and efficiency. SGD is simpler and may lead to better generalization in some cases, but Adam often converges much faster, making it a popular choice for many deep learning tasks.

106) Threading in Python

import threading
import time
import random
data =[]

def square(num):
    # print(f"Square: {num*num}")
    while True:
        print("Added data : ", num)
        data.append(num)
        time.sleep(0.001)

def cube():
    # print(f"Cube: {num*num*num}")
    while True:
        remove = data.pop()
        print("Removed data : ", remove)
        time.sleep(0.001)

t1 = threading.Thread(target=square, args=(random.randint(0,1000000),))
t2 = threading.Thread(target=cube, args=())

t1.start()
t2.start()
t1.join()
t2.join()

print("Done!")

107) Deep Learning Applications

Deep learning, a subset of machine learning, is widely used for tasks involving pattern recognition, prediction, and automation. Below are some major applications across different domains.

  1. Computer Vision
  • Image Classification: Recognize objects in images (e.g., cats vs. dogs).
  • Object Detection: Detect multiple objects in an image (e.g., YOLO, Faster R-CNN).
  • Facial Recognition: Identify or verify faces in photos or videos.
  • Medical Imaging: Detect tumors or anomalies in X-rays, MRIs, CT scans.
  • Image Segmentation: Divide images into meaningful regions (e.g., for autonomous driving).
  1. Natural Language Processing (NLP)
  • Machine Translation: Translate text between languages (e.g., Google Translate).
  • Sentiment Analysis: Detect emotions or opinions from text.
  • Text Summarization: Generate summaries of long documents.
  • Chatbots & Virtual Assistants: Understand and respond to human queries.
  • Speech Recognition: Convert spoken language into text (e.g., Siri, Alexa).
  1. Autonomous Systems
  • Self-Driving Cars: Detect lanes, pedestrians, and vehicles in real time.
  • Drones & Robotics: Navigation, object avoidance, and path planning.

4. Healthcare

  • Disease Prediction: Predict diseases from patient data (e.g., diabetes, cancer).
  • Drug Discovery: Model molecular structures and predict drug interactions.
  1. Finance
  • Fraud Detection: Identify fraudulent transactions in real time.
  • Algorithmic Trading: Predict stock price movements using time-series data.
  1. Entertainment & Media
  • Content Recommendation: Suggest movies, songs, and products based on preferences.
  • Deepfakes & Image/Video Generation: Generate realistic synthetic media.
  1. Gaming & Simulation
  • AI Agents: Learn strategies in games (e.g., AlphaGo).
  • Virtual Reality: Realistic environment modeling and interaction.
  1. Cybersecurity
  • Threat Detection: Identify malware, phishing attacks, or intrusions.
  1. Manufacturing & Industry
  • Predictive Maintenance: Detect equipment failure before it happens.
  • Quality Control: Inspect products for defects using computer vision.

Note: Deep learning is most effective for tasks involving large datasets, pattern recognition, and complex decision-making where traditional algorithms fail.

108) Applications of Ml and Dl

Domain Machine Learning Applications Deep Learning Applications
Healthcare Disease prediction, medical diagnosis, drug discovery Medical imaging (X-ray, MRI), tumor detection, advanced drug modeling
Finance Fraud detection, credit scoring, algorithmic trading High-frequency trading, deep fraud detection with complex patterns
Retail & E-commerce Recommendation systems, customer segmentation, demand forecasting Personalized recommendations, image-based product search
Transportation Traffic prediction, predictive maintenance Self-driving cars, autonomous drones, lane & object detection
Manufacturing & Industry Quality control, process optimization Defect detection using images, predictive maintenance with sensor data
Natural Language Processing Sentiment analysis, chatbots, language translation Advanced chatbots, text summarization, machine translation using transformers
Cybersecurity Threat detection, anomaly detection Intrusion detection using deep networks, malware analysis
Agriculture Crop yield prediction, disease detection Disease detection using images, precision farming with drones & sensors
Entertainment & Media Content recommendation, personalization Deepfake generation, content recommendation with multimedia data
Energy Load forecasting, fault detection Predictive maintenance with sensor data, energy optimization using complex models

Note:

  • ML works well with structured/tabular data and simpler pattern recognition tasks.
  • DL excels with unstructured data like images, audio, and text, requiring large datasets and more computation.

109) What is a cross Validation?

Cross-validation is a machine learning technique for evaluating a model's performance on unseen data by repeatedly splitting the dataset into training and testing sets. It involves training the model on a subset of the data and testing it on the remaining portion, then rotating which subset is used for testing across multiple iterations. The final performance metric is typically the average of the results from all iterations, which provides a more robust and reliable estimate and helps prevent overfitting.  

110) Anagram

def compare(d1, d2):
    d1 = d1.replace(" ", "").lower()
    d2 = d2.replace(" ", "").lower()
    dic = {}
    for d in d1:
        dic[d] = dic.get(d, 0) + 1
    for d in d2:
        if d not in dic:
            print("no anagram")
            return False
        dic[d] -= 1
    if sum(dic.values()) == 0:
        print("Anagram")
        return True
    else:
        print("no anagram")
        return False

111) Worst case in Computer vision

The worst condition in computer vision occurs when the visual input is unclear or degraded — meaning the image doesn’t have enough information for the model to recognize objects correctly. Examples include low lighting, where features become too dark to detect; motion blur, where moving objects appear smeared; occlusion, when objects are partially hidden; and bad weather like fog or rain, which reduces visibility.

These conditions distort or hide important visual details such as edges and textures, leading to poor model accuracy. To handle this, we use techniques like data augmentation, domain adaptation, or sensor fusion to make models more robust.

112) Count the number of times INFO, DEBUG and ERROR.

from collections import Counter

count = Counter()

data = ["ehchc DEBUG","rvhrubv INFO", "eugcgyer INFO ecv","yy ERROR hcb","kjvtrhbvhu"]

for dat in data:
    if "DEBUG" in  dat:
        count["DEBUG"]+=1
    elif "INFO" in dat:
        count["INFO"]+=1

print(count)

🎯 Name few libraries in python for Data analysis and Scientific computation:

- Python has a rich ecosystem of libraries for data analysis and scientific computation. Some of the most important ones include:

- NumPy: It’s the foundation of scientific computing in Python. It provides support for multi-dimensional arrays and a wide range of mathematical operations. Most other data analysis libraries are built on top of NumPy.

- Pandas: This is used for data manipulation and analysis. It introduces powerful data structures like Series and DataFrame, which make handling structured data (like CSV or Excel files) very convenient.

- SciPy: Built on NumPy, it’s used for scientific and technical computing — like optimization, integration, and signal processing.

- Matplotlib and Seaborn: These are used for data visualization. Matplotlib provides low-level control to create all kinds of plots, while Seaborn simplifies the process and creates more attractive, statistical graphics.

- Scikit-learn: A machine learning library used for data mining and predictive modeling — including classification, regression, and clustering.

- Statsmodels: This is mainly for statistical analysis and hypothesis testing — often used in econometrics or regression analysis.

- SymPy: Used for symbolic mathematics — like solving equations algebraically.

- Dask: Helps scale up data analysis by enabling parallel and distributed computing with NumPy and Pandas-like syntax.

Swapping Two Variables -- Techniques

This document lists different ways to swap two variables (a and b) in programming.
Assume initially:

a = 5
b = 10

1. Using a Temporary Variable (Classic Method)

temp = a
a = b
b = temp

2. Without a Temporary Variable (Arithmetic Method)

Works for numbers, but beware of overflow in some languages!

a = a + b
b = a - b
a = a - b

3. Using Multiplication and Division

Only works if both numbers are non-zero and integers.

a = a * b
b = a / b
a = a / b

4. Using Tuple Unpacking (Python Specific)

a, b = b, a

5. Using Bitwise XOR (Works only for integers)

a = a ^ b
b = a ^ b
a = a ^ b

6. Using Functions

def swap(x, y):
    return y, x

a, b = swap(a, b)

7. Using Collections (Python-specific)

lst = [a, b]
lst.reverse()
a, b = lst

Notes:

  • Method 2 and 3 may cause overflow in some languages (like C/C++/Java).\
  • Method 3 doesn't work if a or b is zero.\
  • Method 4 and 7 are Python-specific tricks.\
  • Method 5 (XOR) is language-independent but works only for integers.

✨ Recommended in Python: Use Tuple Unpacking since it is clean, safe, and efficient.

🚀 Interview Explanation: Reducing Latency for AWS Instance in USA Used from India

“If my AWS instance is running in the USA and I need to access it from India, I’ll face higher latency because of geographical distance and network hops.
To mitigate this, there are several solutions depending on the use case.”

🧩 1. Deploy Closer to Users

	The first and most effective solution is to deploy the instance in an AWS region closer to India, like Mumbai (ap-south-1) or Hyderabad (ap-south-2).
	This reduces round-trip time drastically — from around 250 ms down to 30–50 ms.

🌍 2. Use AWS Global Accelerator

	If the instance must stay in the USA, I can use AWS Global Accelerator.
	It routes traffic through the AWS global edge network, minimizing hops over the public internet and improving latency by 30–60 ms.

⚡ 3. Use Amazon CloudFront (CDN)

	For static files or cached API responses, I can use Amazon CloudFront.
	It caches content in edge locations in India, so users get responses quickly without hitting the main server every time.

🧠 4. Use Caching and Replication

	I can also implement caching with ElastiCache (Redis) or use database read replicas in India to reduce data access latency for read-heavy workloads.

🧰 5. Optimize Application Requests

	At the application level, I can reduce API round trips, enable HTTP/2 or gRPC, and use asynchronous processing to hide latency from the user experience.

✅ Conclusion

	“So overall, to mitigate latency between India and a USA AWS instance, I’d either deploy closer to the user, or use AWS Global Accelerator, CloudFront, and caching strategies to minimize response time and improve performance.”

🎯 Interview Answer (Direct & Practical)

“If my production model is underfitting — meaning it’s not learning enough patterns and gives poor results — I handle it in a few steps.”

🧩 1. Check Model Complexity

	The model might be too simple for the data.
	
	I can move from a basic model (like Logistic Regression) to something more complex (like XGBoost or Neural Networks).
	
	In deep models, I may increase layers or neurons.

⚙️ 2. Reduce Regularization

	High regularization (like strong L1/L2 or high dropout) can make the model too restricted.
	
	I reduce those penalties and retune hyperparameters.

🧠 3. Add More or Better Features

	I perform feature engineering to capture hidden relationships — for example, interaction terms, temporal features, or domain-specific signals.
	
	More informative features help the model learn richer patterns.

📊 4. Retrain with More or Latest Data

	In production, underfitting often happens because data patterns change.
	
	I collect more recent data, retrain the model, or use online/incremental learning to keep it updated.

🧹 5. Check Data Quality and Drift

	I verify if input data in production differs from training data.
	
	If there’s data drift, I fix preprocessing pipelines, handle missing values, or re-align feature distributions.

🔁 6. Continuous Monitoring

	I use MLOps tools to monitor metrics like accuracy, loss, and drift.
	
	When I detect underfitting signs, I trigger a retraining pipeline automatically.

✅ Example Summary (for the interview)

“In production, if my model underfits, I make it more flexible by reducing regularization, adding better features, or using a more complex algorithm.
I also retrain with new data and monitor for data drift so the model stays accurate over time.”

“Offline learning trains the model once on a fixed dataset and retrains periodically, while online learning continuously updates the model with new incoming data.

Offline learning is simpler and stable, but online learning is better for dynamic, real-time environments.”

💬 “Can you explain A/B Testing in detail?”

🧩 1. Start with the Definition

	“A/B Testing is a statistical experiment used to compare two versions of a system — A (control) and B (variant) — to determine which performs better.
	It’s widely used in machine learning, marketing, and product development to make data-driven decisions.”
	
⚙️ 2. Explain the Process Step-by-Step

	“The process generally involves five main steps:”

	Step 1: Define the Goal

		First, I identify what metric I want to improve — for example, click-through rate, conversion rate, or model accuracy.
		
		This metric becomes the evaluation criterion for the test.

	Step 2: Create Two Versions

		Version A → current or existing version (control).
		
		Version B → new version with changes (experiment).
		
		In ML, Version B could be a new model or updated algorithm.

    Step 3: Split the Audience Randomly

		I divide the traffic or users randomly into two groups:
		
		Group A → uses the control version
		
		Group B → uses the new version
		
		Randomization ensures both groups are statistically similar, avoiding bias.

	Step 4: Measure Performance

		Both groups use the system simultaneously.
		
		I collect data on the target metric — e.g., click rate, revenue per user, or accuracy improvement.
		
		Then I perform statistical significance testing (like a t-test) to confirm whether the difference is real or just by chance.

	Step 5: Decide and Deploy

		If Version B shows statistically significant improvement, I deploy it fully to production.
		
		If not, I keep Version A or adjust and test again.

🧠 3. Give a Machine Learning Example

	“For example, let’s say I have a fraud detection model running in production.
	I develop a new version with better feature engineering.
	Instead of replacing the old one directly, I do an A/B test —
	I send 80% of transactions to the old model (A) and 20% to the new model (B), then compare metrics like precision, recall, and false positives.
	If model B consistently performs better, I promote it to full production.”

📊 4. Key Benefits

	Reduces risk before full rollout
	
	Gives statistical confidence in decisions
	
	Provides real-world performance insights

⚠️ 5. Points to Monitor

	Sample size must be large enough to ensure valid results
	
	Test duration should capture different traffic patterns
	
	Avoid overlapping experiments that can affect data integrity

✅ 6. Short Summary (End with Confidence)

	“So, A/B Testing is basically a controlled experiment that lets us compare two models or system versions using real-world data.
	It’s one of the safest and most reliable ways to validate that a new change truly improves performance before a full rollout.”

explain Feature Engineering and Feature Store

“Feature engineering is the process of transforming raw data into meaningful features that help a machine learning model learn better.
For example, from a timestamp, I can create features like day of the week, hour of the day, or weekend flag.
From numerical data, I can create ratios, moving averages, or normalized values.
These engineered features improve model performance and help capture hidden patterns.”

“A feature store, on the other hand, is a centralized system that stores, manages, and serves these features for both training and real-time inference.
It ensures that features used during training are consistent with those used in production, avoiding problems like feature drift.
For instance, in a recommendation system, we store user interaction features in the feature store so both the training model and the live serving model use the exact same data.”

“In short, feature engineering creates the features, and the feature store ensures they are reusable, consistent, and production-ready.”

What is Data Drift and Feature Drift?

Answer:

“Data drift occurs when the overall input data distribution changes over time compared to the training data, affecting model performance.
Feature drift happens when a specific feature’s distribution changes over time.
Both can reduce accuracy, so in production we monitor distributions, set alerts, and retrain models when significant drift is detected.”

Question: Can you explain how BoT-SORT works in multi-object tracking?

Answer: BoT-SORT is a multi-object tracking (MOT) algorithm that improves over ByteTrack by adding appearance features and camera motion compensation. The goal is to assign consistent IDs to objects across video frames.

Here’s how it works step by step:

1) Detection Input

It takes object detections from a detector like YOLO. Each detection includes bounding box, confidence score, and class.

2) Motion Prediction (Kalman Filter)

Each existing track predicts its next position using a Kalman filter, which models the motion of objects over time.

3) Camera Motion Compensation

If the camera itself is moving (e.g., surveillance, drone), BoT-SORT adjusts predictions using global motion estimation, so the tracker is robust in dynamic scenes.

4) Affinity Calculation (Matching Strength)

For associating detections with existing tracks, BoT-SORT combines:

IOU overlap (spatial consistency)

Appearance features from a ReID model (visual similarity)

Motion distance from the Kalman filter prediction

5) Data Association (Hungarian Algorithm)

Using the affinity matrix, it assigns detections to tracks with the Hungarian algorithm.

Unmatched detections start new tracks, while unmatched tracks may be terminated.

6) Track Update

Tracks are updated with the matched detection’s bounding box, motion state, and appearance embedding.

7) Final Output

Each object gets a unique ID, which remains consistent across frames, even under occlusion or camera movement.

Why Pydent

####Interview Explanation (Short & Clear Version)

“Pydantic is a Python library used for data validation and settings management using Python type hints. It ensures that the data you work with matches the expected types — automatically converting and validating data at runtime.”

from pydantic import BaseModel

class User(BaseModel):
    id: int
    name: str
    age: int

# Example 1: Valid input
user = User(id=1, name="Amarnath", age=25)
print(user)

# Example 2: Invalid input
user = User(id="1", name="Amarnath", age="twenty")
Feature 🧪 Pedantic 🧭 Pydantic
🧠 Main Purpose Runtime function type checking Data validation and parsing using Python type hints
🧾 What It Checks Arguments and return types of functions Data fields in models (e.g., API input, config, JSON)
🧰 How It Works Decorator @pedantic around functions Define classes by inheriting from BaseModel
🛡️ Validation Timing When a function is called When data is assigned/parsed into a model
🔄 Data Conversion Does not do type conversion Can auto-convert compatible types (e.g., "1"1)
📊 Error Handling Raises TypeError on mismatch Raises detailed ValidationError with field info
Performance Lightweight, minimal overhead More powerful but heavier
🌐 Use Cases Internal function checks, testing, ensuring type safety API request validation, configs, form inputs, structured data
🧩 Framework Integration Standalone Widely used in FastAPI, Django, and other frameworks
🆚 Analogy Like a runtime type guard for functions Like a data gatekeeper for structured inputs

LINUX Interview questions

1) How to check server down in linux.

Example : sudo systemctl status mysql

2) Kernel vs shell script

The kernel operates at the core of the system, managing hardware resources and ensuring the smooth execution of processes, while the shell acts as an interface between the user and the system, allowing commands to be issued and executed.

3) I Node in linux

In Linux, an i-node, or index node, is a data structure that stores metadata about a file or directory on the filesystem, including its type, permissions, owner, size, and the locations of its data on the disk. Each i-node is assigned a unique i-node number, which acts as an index into a table of inodes on the filesystem, allowing the operating system to quickly locate and access the file's data and metadata. You can find a file's i-node number using the ls -i or stat commands.

4) How to kill process in Linux

ps aux | grep firefox kill 12345 # Replace 12345 with the actual PID

🐳 Docker vs Virtual Machine 🖥️

A clear comparison between Docker containers and Virtual Machines (VMs) — their architecture, performance, and use cases.


🧩 Concept Overview

Feature Docker (Container) Virtual Machine (VM)
Definition Lightweight, isolated environments that share the host OS kernel. Full-fledged systems with their own OS running on a hypervisor.
Isolation Level Process-level isolation. Hardware-level isolation.
Startup Time Seconds. Minutes.
Resource Usage Lightweight (shares kernel). Heavy (each VM runs its own OS).
Portability Very portable — runs consistently across environments. Less portable due to dependency on hypervisor and guest OS.
Performance Near-native (minimal overhead). Lower performance (hypervisor overhead).
Storage Uses layered file system (e.g., OverlayFS). Uses full disk image (GBs).
Use Case Microservices, CI/CD, lightweight deployments. Full OS isolation, legacy app support, multiple OS environments.

Pinned Loading

  1. amarnathreddy0201 amarnathreddy0201 Public

    Config files for my GitHub profile.

    Jupyter Notebook