This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tokenizer = Tokenizer(num_words=10000) | |
tokenizer.fit_on_texts(df['review']) | |
vector = tokenizer.texts_to_sequences(df['review']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.fit(x_train,Y_train,batch_size=50,epochs=20,verbose=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |