Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

message #39

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
FROM python:2-alpine
from sklearn.model_selection import train_test_split

COPY ./requirements.txt /app/requirements.txt
def split_train_dev_test(X, y, test_size, dev_size):
# Split into train+dev and test sets first
X_temp, X_test, y_temp, y_test = train_test_split(X, y, test_size=test_size)

WORKDIR /app
# Compute actual dev size relative to the combined train+dev set
actual_dev_size = dev_size / (1 - test_size)

# Split the train+dev set into separate training and dev sets
X_train, X_dev, y_train, y_dev = train_test_split(X_temp, y_temp, test_size=actual_dev_size)

RUN apk --update add python py-pip openssl ca-certificates py-openssl wget bash linux-headers
RUN apk --update add --virtual build-dependencies libffi-dev openssl-dev python-dev py-pip build-base \
&& pip install --upgrade pip \
&& pip install --upgrade pipenv\
&& pip install --upgrade -r /app/requirements.txt\
&& apk del build-dependencies

COPY . /app

ENTRYPOINT [ "python" ]

CMD [ "hello.py" ]
return X_train, X_dev, X_test, y_train, y_dev, y_test
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Getting Started with Python on IBM Cloud


To get started, we'll take you through a sample Python Flask app, help you set up a development environment, deploy to IBM Cloud and add a Cloudant database.

The following instructions are for deploying the application as a Cloud Foundry application. To deploy as a container to **IBM Cloud Kubernetes Service** instead, [see README-kubernetes.md](README-kubernetes.md)
Expand Down
15 changes: 15 additions & 0 deletions hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,18 @@ def shutdown():

if __name__ == '__main__':
app.run(host='0.0.0.0', port=port, debug=True)





# Calculate the total number of samples
total_samples = len(train_data) + len(test_data) + len(dev_data)

# Get the image dimensions (assuming all images have the same size)
image_height, image_width = train_data[0].shape[:2] # Assuming the shape is (height, width, channels)

# Print statements
print(f"Total number of samples in the dataset: {total_samples}")
print(f"Size of the images in the dataset: {image_height}x{image_width}")

19 changes: 19 additions & 0 deletions image_resize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np
from skimage.transform import resize

def resize_images(images, size):
"""Resizes images to the given size.

Args:
images: A numpy array of images.
size: The target size of the images.

Returns:
A numpy array of resized images.
"""

resized_images = np.zeros((images.shape[0], size[0], size[1], images.shape[3]))
for i in range(images.shape[0]):
resized_images[i] = resize(images[i], size, order=3)
return resized_images

38 changes: 38 additions & 0 deletions quiz3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from flask import Flask, request, jsonify
import tensorflow as tf
import numpy as np
from PIL import Image

app = Flask(__name__)

@app.route('/predict', methods=['POST'])
def predict():
# Get the two images from the request
image1 = request.files['image1']
image2 = request.files['image2']

# Convert the images to numpy arrays
image1_array = np.array(Image.open(image1))
image2_array = np.array(Image.open(image2))

# Preprocess the images
image1_array = image1_array / 255.0
image1_array = image1_array.reshape(1, 28, 28, 1)
image2_array = image2_array / 255.0
image2_array = image2_array.reshape(1, 28, 28, 1)

# Load the trained model
model = tf.keras.models.load_model('model.h5')

# Make predictions on the images
prediction1 = model.predict(image1_array)
prediction2 = model.predict(image2_array)

# Check if the predictions are the same
if np.argmax(prediction1) == np.argmax(prediction2):
return jsonify({'is_same_digit': True})
else:
return jsonify({'is_same_digit': False})

if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)