Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,41 +15,38 @@ if uploaded_file is not None:
|
|
15 |
# Display the uploaded image
|
16 |
st.image(uploaded_file, caption='Uploaded Image.', use_column_width=True)
|
17 |
st.write("")
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
# Predict
|
54 |
-
prediction = 'dog' if result[0][0] == 1 else 'cat'
|
55 |
-
st.write("Prediction:", prediction)
|
|
|
15 |
# Display the uploaded image
|
16 |
st.image(uploaded_file, caption='Uploaded Image.', use_column_width=True)
|
17 |
st.write("")
|
18 |
+
train_datagen = ImageDataGenerator(rescale = 1./255,
|
19 |
+
shear_range = 0.2,
|
20 |
+
zoom_range = 0.2,
|
21 |
+
horizontal_flip = True)
|
22 |
+
training_set = train_datagen.flow_from_directory('dataset/training_set',
|
23 |
+
target_size = (64, 64),
|
24 |
+
batch_size = 32,
|
25 |
+
class_mode = 'binary')
|
26 |
+
test_datagen = ImageDataGenerator(rescale = 1./255)
|
27 |
+
test_set = test_datagen.flow_from_directory('dataset/test_set',
|
28 |
+
target_size = (64, 64),
|
29 |
+
batch_size = 32,
|
30 |
+
class_mode = 'binary')
|
31 |
+
cnn=tf.keras.models.Sequential()
|
32 |
+
cnn.add(tf.keras.layers.Conv2D(filters=32,kernel_size=3,activation='relu',input_shape=[64,64,3]))
|
33 |
+
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2,strides=2))
|
34 |
+
cnn.add(tf.keras.layers.Conv2D(filters=32,kernel_size=3,activation='relu'))
|
35 |
+
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2,strides=2))
|
36 |
+
cnn.add(tf.keras.layers.Flatten())
|
37 |
+
cnn.add(tf.keras.layers.Dense(units=128,activation='relu'))
|
38 |
+
cnn.add(tf.keras.layers.Dense(units=1,activation='sigmoid'))
|
39 |
+
cnn.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
|
40 |
+
cnn.fit(x=training_set,validation_data=test_set,epochs=25)
|
41 |
+
import numpy as np
|
42 |
+
from keras.preprocessing import image
|
43 |
+
test_image=image.load_img('dataset/single_prediction/cat_or_dog_1.jpg',target_size=(64,64))
|
44 |
+
test_image=image.img_to_array(test_image)
|
45 |
+
test_image=np.expand_dims(test_image,axis=0)
|
46 |
+
result=cnn.predict(test_image)
|
47 |
+
training_set.class_indices
|
48 |
+
if result[0][0]==1:
|
49 |
+
prediction='dog'
|
50 |
+
else:
|
51 |
+
prediction='cat'
|
52 |
+
print(prediction)
|
|
|
|
|
|