Posts

Showing posts from July, 2023

2.Understanding and Using ANN : Identifying age group of an actor

  Design Artificial Neural Networks for Identifying and Classifying an actor using Kaggle Dataset. COLAB from tensorflow.keras.models import load_model from PIL import Image import numpy as np image_height = 128 image_width = 128 num_channels = 3 # Load the trained model model = load_model( '/content/drive/MyDrive/trained_model_NEW_2_2_Dataset.h5' )   # Replace 'your_trained_model.h5' with the actual file name # Read the new face image new_face_path = '/content/drive/MyDrive/2_Predict/a.jpg'   # Replace 'path_to_new_face.jpg' with the actual file path new_face = Image. open (new_face_path) #new_face.show() display(new_face) # Preprocess the image new_face = new_face.resize((image_width, image_height)) new_face = np.array(new_face) #new_face = new_face.astype('float32') / 255.0 new_face = np.expand_dims(new_face, axis= 0 )   # Add a batch dimension # Perform prediction predictions = model.predict(new_face) predicted_age_group = np.argmax(pr...

10. Demonstration of GAN with image output

 import numpy as np import matplotlib.pyplot as plt from tensorflow import keras from tensorflow.keras import layers # Generator model generator = keras.Sequential([     layers.Dense(256, input_dim=100),     layers.LeakyReLU(alpha=0.2),     layers.Dense(512),     layers.LeakyReLU(alpha=0.2),     layers.Dense(784, activation='tanh'),     layers.Reshape((28, 28, 1)) ]) # Generate random images def generate_images(num_images):     noise = np.random.normal(0, .1, (num_images, 100))     generated_images = generator.predict(noise)     generated_images = 0.5 * generated_images + 0.5     return generated_images # Generate and display images num_images = 25 generated_images = generate_images(num_images) fig, axs = plt.subplots(5, 5) cnt = 0 for i in range(5):     for j in range(5):         axs[i, j].imshow(generated_images[cnt, :, :, 0], cmap='magma')   ...

4. Predicting Sequential Data

Implement a Recurrence Neural Network for Predicting Sequential Data.   Dataset link: https://drive.google.com/drive/folders/1sJr_v80WIvfTc3FzHdB9B6M-iHDZVhkh?usp=sharing import numpy as np import pandas as pd from sklearn.preprocessing import MinMaxScaler from tensorflow.keras.models import Sequential from tensorflow.keras.layers import LSTM, Dense from sklearn.model_selection import train_test_split # Load the stock market dataset data = pd.read_csv( '/content/drive/MyDrive/A_data.csv' )   # Replace with your dataset # Extract the relevant features and target variable prices = data[ 'close' ].values.reshape( -1 , 1 ) # Normalize the data scaler = MinMaxScaler(feature_range=( 0 , 1 )) normalized_prices = scaler.fit_transform(prices) # Prepare the input-output sequences sequence_length = 10 X = [] y = [] for i in range ( len (normalized_prices) - sequence_length):     X.append(normalized_prices[i:i+sequence_length])     y.append(normalized_pri...

1..Build a Convolution Neural Network for Image Recognition.

For Jupyter (on local machine)  # Convolutional Neural Network # Installing Theano # pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git # Installing Tensorflow # Install Tensorflow from the website: https://www.tensorflow.org/versions/r0.12/get_started/os_setup.html # Installing Keras # pip install --upgrade keras # Part 1 - Building the CNN # Importing the Keras libraries and packages from keras.models import Sequential from keras.layers import Convolution2D from keras.layers import MaxPooling2D from keras.layers import Flatten from keras.layers import Dense # Initialising the CNN classifier = Sequential() # Step 1 - Convolution classifier.add(Convolution2D(32, 3, 3, input_shape = (64, 64, 3), activation = 'relu')) # Step 2 - Pooling classifier.add(MaxPooling2D(pool_size = (2, 2))) # Adding a second convolutional layer classifier.add(Convolution2D(32, 3, 3, activation = 'relu')) classifier.add(MaxPooling2D(pool_size = (2, 2))) # Step 3 - Flattening ...