Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

vivekpadia70 vivekpadia70

🏠
Working from home
View GitHub Profile
View imdb_lstm.py
tokenizer = Tokenizer(num_words=10000)
tokenizer.fit_on_texts(df['review'])
vector = tokenizer.texts_to_sequences(df['review'])
View imdb_lstm.py
df = pd.read_csv("/home/aubergine/Downloads/imdb-dataset-of-50k-movie-reviews/IMDB Dataset.csv")
train_set = 45000
max_len_text = 2000
df['sentiment'] = df['sentiment'].replace('positive', 1)
df['sentiment'] = df['sentiment'].replace('negative', 0)
View imdb_lstm.py
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.preprocessing.text import Tokenizer
from keras.utils import to_categorical
from tensorflow.keras.preprocessing.sequence import pad_sequences
View malaria_cell_CNN.py
model.fit(x_train,Y_train,batch_size=50,epochs=20,verbose=2)
View malaria_cell_CNN.py
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
View malaria_cell_CNN.py
model=Sequential()
model.add(Conv2D(filters=32,kernel_size=2,padding="same",activation="relu",input_shape=(50,50,3)))
model.add(MaxPooling2D(pool_size=2))
model.add(Conv2D(filters=32,kernel_size=2,padding="same",activation="relu"))
model.add(MaxPooling2D(pool_size=2))
model.add(Conv2D(filters=64,kernel_size=2,padding="same",activation="relu"))
model.add(MaxPooling2D(pool_size=2))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(500,activation="relu"))
View malaria_cell_CNN.py
(x_train,x_test)=imgs[(int)(0.1*len_data):],imgs[:(int)(0.1*len_data)]
x_train = x_train.astype('float32')/255
x_test = x_test.astype('float32')/255
train_len=len(x_train)
test_len=len(x_test)
(y_train,y_test)=labels[(int)(0.1*len_data):],labels[:(int)(0.1*len_data)]
num_classes=len(np.unique(labels))
Y_train=keras.utils.to_categorical(y_train,num_classes)
Y_test=keras.utils.to_categorical(y_test,num_classes)
View malaria_cell_CNN.py
imgs=np.array(data)
labels=np.array(labels)
s=np.arange(imgs.shape[0])
np.random.shuffle(s)
imgs=imgs[s]
labels=labels[s]
num_classes=len(np.unique(labels))
len_data=len(imgs)
View malaria_cell_CNN.py
data=[]
labels=[]
Parasitized=os.listdir("~/Downloads/cell_images/Parasitized/")
for a in Parasitized:
try:
image=cv2.imread("~/Downloads/cell_images/Parasitized/"+a)
image_from_array = Image.fromarray(image, 'RGB')
size_image = image_from_array.resize((50, 50))
data.append(np.array(size_image))
View malaria_cell_CNN.py
from PIL import Image
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
import cv2
from sklearn.model_selection import train_test_split
import keras
from keras.utils import np_utils
from keras.models import Sequential
You can’t perform that action at this time.