Skip to content

Commit 49e619e

Browse files
Merge pull request #65 from truefoundry/md_fix_grdio_app
Updated the train mnist example to fix gradio deployment and updated truefoundry cli min version
2 parents df07098 + f2299ba commit 49e619e

File tree

7 files changed

+14
-9
lines changed

7 files changed

+14
-9
lines changed

train-and-deploy-mnist/deploy_model.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"metadata": {},
3030
"outputs": [],
3131
"source": [
32-
"%pip install -U -q \"truefoundry>=0.4.1,<0.5.0\" \"tensorflow==2.15.0\" \"matplotlib==3.8.2\""
32+
"%pip install -U -q \"truefoundry>=0.5.6,<0.6.0\" \"tensorflow==2.15.0\" \"matplotlib==3.8.2\""
3333
]
3434
},
3535
{

train-and-deploy-mnist/deploy_model/gradio_demo.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ def get_inference(img_arr):
1515
fn=get_inference,
1616
inputs="image",
1717
outputs="label",
18-
examples=[["sample_images/3.jpg"], ["sample_images/8.jpg"]],
18+
examples=[
19+
["sample_images/3.jpg"],
20+
["sample_images/8.jpg"],
21+
["sample_images/7.png"]
22+
],
1923
)
20-
2124
interface.launch(
2225
server_name="0.0.0.0",
2326
server_port=8000,

train-and-deploy-mnist/deploy_model/predict.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ def load_model(model_path: str) -> tf.keras.Model:
1111
def predict_fn(model, img_arr: np.ndarray) -> str:
1212
# Preprocess the image before passing it to the model
1313
img_arr = tf.expand_dims(img_arr, 0)
14-
img_arr = img_arr[:, :, :, 0] # Keep only the first channel (grayscale)
1514

16-
# Make predictions
15+
# Resize to (1, 28, 28, 1)
16+
resized_image = tf.image.resize(img_arr, [28, 28])
17+
img_arr = resized_image[:, :, :, 0] # Keep only the first channel (grayscale)
18+
1719
predictions = model.predict(img_arr)
1820
predicted_label = tf.argmax(predictions[0]).numpy()
1921

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
gradio==4.43.0
2-
tensorflow>=0.5.1
2+
tensorflow===2.15.0
Loading
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
matplotlib==3.8.2
22
tensorflow==2.15.0
3-
truefoundry>=0.5.1
3+
truefoundry>=0.5.6,<0.6.0

train-and-deploy-mnist/train_model.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"outputs": [],
3939
"source": [
40-
"%pip install -U -q \"truefoundry>=0.5.1\" \"tensorflow==2.15.0\" \"matplotlib==3.8.2\""
40+
"%pip install -U -q \"truefoundry>=0.5.6,<0.6.0\" \"tensorflow==2.15.0\" \"matplotlib==3.8.2\""
4141
]
4242
},
4343
{
@@ -252,7 +252,7 @@
252252
" tf.keras.layers.Dense(10, activation='softmax')\n",
253253
"])\n",
254254
"\n",
255-
"optimizer = tf.keras.optimizers.Adam(learning_rate=0.1)\n",
255+
"optimizer = tf.keras.optimizers.Adam(learning_rate=0.01)\n",
256256
"\n",
257257
"# Compile the model\n",
258258
"model.compile(optimizer=optimizer, loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n"

0 commit comments

Comments
 (0)