Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,77 +2,13 @@ import numpy as np
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
import time
|
4 |
|
|
|
5 |
from tensorflow import keras
|
6 |
from tensorflow.keras import layers
|
7 |
app = FastAPI()
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
num_classes = 9
|
12 |
-
input_shape = (28, 28, 3)
|
13 |
-
batch_size = 1000
|
14 |
-
epochs = 1
|
15 |
-
|
16 |
-
# Define baseline model
|
17 |
-
def baseline_model():
|
18 |
-
|
19 |
-
# Create model
|
20 |
-
model = keras.Sequential(
|
21 |
-
[
|
22 |
-
keras.Input(shape=input_shape),
|
23 |
-
layers.Conv2D(64, kernel_size=(3, 3), activation="relu"),
|
24 |
-
layers.Conv2D(128, kernel_size=(3, 3), activation="relu"),
|
25 |
-
layers.Flatten(),
|
26 |
-
layers.Dropout(0.5),
|
27 |
-
layers.Dense(num_classes, activation="softmax"),
|
28 |
-
]
|
29 |
-
)
|
30 |
-
model.summary()
|
31 |
-
|
32 |
-
# Compile model
|
33 |
-
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
|
34 |
-
|
35 |
-
return model
|
36 |
-
|
37 |
-
# Load Data
|
38 |
-
path = './pathmnist.npz'
|
39 |
-
with np.load(path) as data:
|
40 |
-
x_train = data['train_images']
|
41 |
-
y_train = data['train_labels']
|
42 |
-
x_test = data['test_images']
|
43 |
-
y_test = data['test_labels']
|
44 |
-
x_val = data['val_images']
|
45 |
-
y_val = data['val_labels']
|
46 |
-
|
47 |
-
# Show DataSet Images
|
48 |
-
for image in x_train:
|
49 |
-
plt.imshow(image)
|
50 |
-
plt.show()
|
51 |
-
break
|
52 |
-
|
53 |
-
# Normalize images to the [0, 1] range
|
54 |
-
x_train = x_train.astype("float32") / 255
|
55 |
-
x_test = x_test.astype("float32") / 255
|
56 |
-
x_val = x_val.astype("float32") / 255
|
57 |
-
|
58 |
-
print("x_train shape:", x_train.shape)
|
59 |
-
print(x_train.shape[0], "train samples")
|
60 |
-
print(x_test.shape[0], "test samples")
|
61 |
-
print(x_val.shape[0], "test samples")
|
62 |
-
|
63 |
-
# Convert class vectors to binary class matrices
|
64 |
-
y_train = keras.utils.to_categorical(y_train, num_classes)
|
65 |
-
y_test = keras.utils.to_categorical(y_test, num_classes)
|
66 |
-
y_val = keras.utils.to_categorical(y_val, num_classes)
|
67 |
-
|
68 |
-
model = baseline_model()
|
69 |
-
|
70 |
-
# Fit model
|
71 |
-
#history = model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1)
|
72 |
-
inicio = time.time()
|
73 |
-
history = model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_data=(x_val, y_val))
|
74 |
-
fin = time.time()
|
75 |
-
print(fin-inicio)
|
76 |
|
77 |
@app.get("/generate")
|
78 |
def generate(x: np.array):
|
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
import time
|
4 |
|
5 |
+
from huggingface_hub import from_pretrained_keras
|
6 |
from tensorflow import keras
|
7 |
from tensorflow.keras import layers
|
8 |
app = FastAPI()
|
9 |
|
10 |
+
model = from_pretrained_keras("mat27/medmnsitPrueba")
|
11 |
+
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
@app.get("/generate")
|
14 |
def generate(x: np.array):
|