How to Build a Blog with Powerful Rich-text Editor | Django Step by Step Tutorial
Beginner
2021-04-24
In this tutorial series, we build a blog with Django that has a Powerful Rich-text Edit...
Date Published: 2022-06-21
Peng Akebuon
⭐ Hello World, In this video we walk you through the process of training an Artificial Intelligence model with Tensorflow precisely a Multi-image classifier. We prepare our dataset, load it, train the model and save it. The saved model is then used by our Django web app to perform predictions i.e predicts the class of an image uploaded to the website. The training of the model is done using a simple convolutional neural network which can be easily extended. After training, the model is saved and loaded by Django in order to perform predictions from our web app
# Preparing Dataset
# temporal storage for labels and images
data=[]
labels=[]
# Cat 0
# Get the animal directory
cats = os.listdir(os.getcwd() + "/CNN/data/cat")
for x in cats:
"""
Loop through all the images in the directory
1. Convert to arrays
2. Resize the images
3. Add image to dataset
4. Add the label
"""
imag=cv2.imread(os.getcwd() + "/CNN/data/cat/" + x)
img_from_ar = Image.fromarray(imag, 'RGB')
resized_image = img_from_ar.resize((50, 50))
data.append(np.array(resized_image))
labels.append(0)
# load in animals and labels
animals=np.array(data)
labels=np.array(labels)
# save
np.save("animals",animals)
np.save("labels",labels)
# Train Model
# train through 100 times
history = model.fit(x_train, y_train, epochs=100,
validation_data=(x_test, y_test))
# perform validation and get accuracy
test_loss, test_acc = model.evaluate(x_test, y_test, verbose=2)
print(test_acc)
# save the model or brain
model.save("model.h5")
Let's Connect
🔗 LinkedIn
🔗 Twitter
🔗 Join Our Discord Server