CNN

Load image files and make the Convolutional Deep learnig model.




images = os.listdir(~~~path)

# image load and print
img = Image.open("PATH AND FILE").resize((?, ?))
plt.title('NAME')
plt.imshow(img)
plt.show()

# image to array and scaling
img = Image.open ("PATH AND FILE").resize((?, ?))
img = np.array(img)/255.

# after work, chage array again
list_arr =  np.array(img_list) # handle as x, y 

# or
img2 = image.img_to_array(img_origin)
img2 = img2.reshape((-1, ?, ?, 3))
img2 = preprocess_input(img2)
features = model.predict(img2)
#print(decode_predictions(features, top=3))

# Conv Model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D
model = Sequential()
model.add(Conv2D(32, kernel_size=(5,5), strides=(1,1), padding='same', activation='relu', input_shape=(?,))))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(32, activation='relu'))
model.add(Dense("NUMBER OF CASSFICATION", activation='softmax'))
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate),
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

# predict image check and Classification value 
i=1
plt.figure(figsize=(16, 8))
for img, label in zip(X_test[:4], y_test[:4]):
    pred = model.predict(img.reshape(-1,?, ?, 3))
    pred_t = np.argmax(pred)
    plt.subplot(2, 4, i)
    plt.title(f'''True Value:{label}, Pred Value: {pred_t}''')
    plt.imshow(img)
    plt.axis('off')
    i = i + 1
    

    

Comments

Popular posts from this blog

Voting Ensemble Model

Graph