Professional Documents
Culture Documents
ipynb - Colaboratory
cv2_imshow(img1)
img1.shape
(256, 256, 3)
import pandas as pd
import numpy as np
print(img1.shape[0],img1.shape[1])
256 256
reshapeddata=img1.reshape(256,256*3)
reshapeddata
https://colab.research.google.com/drive/12r2kLFDkDe3rkkn6xfiaVVPjgbxxNcZP#scrollTo=g033tHSHj1n4&printMode=true 1/5
23/03/2024, 18:10 Project code.ipynb - Colaboratory
def reshapeddata(img_rows, img_cols):
# Assuming reshapeddata() returns the necessary data
(X_train, y_train), (X_test, y_test) = reshapeddata()
# Assuming reshapeddata() provides the necessary data
X_train = X_train.reshape(X_train.shape[0], img_rows, img_cols, 1)
X_test = X_test.reshape(X_test.shape[0], img_rows, img_cols, 1)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255.0
X_test /= 255.0
return (X_train, y_train), (X_test, y_test)
X_train = X_train.reshape((X_train.shape[0], X_train.shape[1], X_train.shape[2], 1))
X_test = X_test.reshape((X_test.shape[0],X_test.shape[1],X_test.shape[2],1))
print(X_train.shape)
print(X_test.shape)
X_train=X_train/255
X_test=X_test/255
type(reshapeddata)
function
model=Sequential()
model.add(Conv2D(32,(3,3),activation='relu',input_shape=(28,28,1)))
model.add(MaxPool2D(2,2))
model.add(Flatten())
model.add(Dense(100,activation='relu'))
model.add(Dense(10,activation='softmax'))
model.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
import tensorflow as tf
from tensorflow.keras import layers
https://colab.research.google.com/drive/12r2kLFDkDe3rkkn6xfiaVVPjgbxxNcZP#scrollTo=g033tHSHj1n4&printMode=true 2/5
23/03/2024, 18:10 Project code.ipynb - Colaboratory
def shuffle_unit(inputs, in_channels, out_channels, strides, groups):
shortcut = inputs
# Channel shuffle
x = channel_shuffle(x, groups)
# Depthwise convolution
x = layers.DepthwiseConv2D(3, strides=strides, padding='same', use_bias=False)(x)
x = layers.BatchNormalization()(x)
if strides == 2:
shortcut = layers.AveragePooling2D(pool_size=3, strides=2, padding='same')(shortcut)
shortcut = tf.keras.layers.Concatenate(axis=-1)([shortcut, tf.zeros_like(shortcut)])
x = layers.GlobalAveragePooling2D()(x)
x = layers.Dense(num_classes, activation='softmax')(x)
# Add a convolution layer to the input with the smaller number of channels
x = layers.Conv2D(240, kernel_size=1, strides=1, padding='same')(x)
# Now, the shapes of the two inputs will be the same and the error will be resolved.
model = tf.keras.Model(inputs, x)
return model
<matplotlib.image.AxesImage at 0x7ed3cc140ac0>
https://colab.research.google.com/drive/12r2kLFDkDe3rkkn6xfiaVVPjgbxxNcZP#scrollTo=g033tHSHj1n4&printMode=true 3/5
23/03/2024, 18:10 Project code.ipynb - Colaboratory
from albumentations.augmentations.transforms import Solarize
transform = Solarize(threshold=70, p=1.0)
augmented_image = transform(image=img1)['image']
plt.figure(figsize=(4, 4))
plt.axis('off')
plt.imshow(augmented_image)
<matplotlib.image.AxesImage at 0x7ed3cc3dcee0>
<matplotlib.image.AxesImage at 0x7ed3cc46fdf0>
<matplotlib.image.AxesImage at 0x7ed3cc0d6cb0>
https://colab.research.google.com/drive/12r2kLFDkDe3rkkn6xfiaVVPjgbxxNcZP#scrollTo=g033tHSHj1n4&printMode=true 4/5
23/03/2024, 18:10 Project code.ipynb - Colaboratory
from albumentations.augmentations.transforms import Solarize
transform = Solarize(threshold=70, p=1.0)
augmented_image = transform(image=img4)['image']
plt.figure(figsize=(4, 4))
plt.axis('off')
plt.imshow(augmented_image)
<matplotlib.image.AxesImage at 0x7ed3cc1f80a0>
https://colab.research.google.com/drive/12r2kLFDkDe3rkkn6xfiaVVPjgbxxNcZP#scrollTo=g033tHSHj1n4&printMode=true 5/5