-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: clean up some spacing issues in website (#1256)
- Loading branch information
1 parent
b2751eb
commit c6660d0
Showing
33 changed files
with
282 additions
and
2,420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,33 +29,33 @@ | |
"import urllib.request\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import PIL, io\n", | ||
"from PIL import Image\r\n", | ||
"\r\n", | ||
"vec_slice = udf(lambda vec, indices: (vec.toArray())[indices].tolist(), ArrayType(FloatType()))\r\n", | ||
"arg_top_k = udf(lambda vec, k: (-vec.toArray()).argsort()[:k].tolist(), ArrayType(IntegerType()))\r\n", | ||
"\r\n", | ||
"def downloadBytes(url: str):\r\n", | ||
" with urllib.request.urlopen(url) as url:\r\n", | ||
" barr = url.read()\r\n", | ||
" return barr\r\n", | ||
"\r\n", | ||
"def rotate_color_channel(bgr_image_array, height, width, nChannels):\r\n", | ||
" B, G, R, *_ = np.asarray(bgr_image_array).reshape(height, width, nChannels).T\r\n", | ||
" rgb_image_array = np.array((R, G, B)).T\r\n", | ||
" return rgb_image_array\r\n", | ||
" \r\n", | ||
"def plot_superpixels(image_rgb_array, sp_clusters, weights, green_threshold=99):\r\n", | ||
" superpixels = sp_clusters\r\n", | ||
" green_value = np.percentile(weights, green_threshold)\r\n", | ||
" img = Image.fromarray(image_rgb_array, mode='RGB').convert(\"RGBA\")\r\n", | ||
" image_array = np.asarray(img).copy()\r\n", | ||
" for (sp, v) in zip(superpixels, weights):\r\n", | ||
" if v > green_value:\r\n", | ||
" for (x, y) in sp:\r\n", | ||
" image_array[y, x, 1] = 255\r\n", | ||
" image_array[y, x, 3] = 200\r\n", | ||
" plt.clf()\r\n", | ||
" plt.imshow(image_array)\r\n", | ||
"from PIL import Image\n", | ||
"\n", | ||
"vec_slice = udf(lambda vec, indices: (vec.toArray())[indices].tolist(), ArrayType(FloatType()))\n", | ||
"arg_top_k = udf(lambda vec, k: (-vec.toArray()).argsort()[:k].tolist(), ArrayType(IntegerType()))\n", | ||
"\n", | ||
"def downloadBytes(url: str):\n", | ||
" with urllib.request.urlopen(url) as url:\n", | ||
" barr = url.read()\n", | ||
" return barr\n", | ||
"\n", | ||
"def rotate_color_channel(bgr_image_array, height, width, nChannels):\n", | ||
" B, G, R, *_ = np.asarray(bgr_image_array).reshape(height, width, nChannels).T\n", | ||
" rgb_image_array = np.array((R, G, B)).T\n", | ||
" return rgb_image_array\n", | ||
" \n", | ||
"def plot_superpixels(image_rgb_array, sp_clusters, weights, green_threshold=99):\n", | ||
" superpixels = sp_clusters\n", | ||
" green_value = np.percentile(weights, green_threshold)\n", | ||
" img = Image.fromarray(image_rgb_array, mode='RGB').convert(\"RGBA\")\n", | ||
" image_array = np.asarray(img).copy()\n", | ||
" for (sp, v) in zip(superpixels, weights):\n", | ||
" if v > green_value:\n", | ||
" for (x, y) in sp:\n", | ||
" image_array[y, x, 1] = 255\n", | ||
" image_array[y, x, 3] = 200\n", | ||
" plt.clf()\n", | ||
" plt.imshow(image_array)\n", | ||
" display()" | ||
], | ||
"outputs": [], | ||
|
@@ -74,36 +74,36 @@ | |
"cell_type": "code", | ||
"execution_count": null, | ||
"source": [ | ||
"from synapse.ml.io import *\r\n", | ||
"\r\n", | ||
"image_df = spark.read.image().load(\"wasbs://[email protected]/explainers/images/david-lusvardi-dWcUncxocQY-unsplash.jpg\")\r\n", | ||
"display(image_df)\r\n", | ||
"\r\n", | ||
"# Rotate the image array from BGR into RGB channels for visualization later.\r\n", | ||
"row = image_df.select(\"image.height\", \"image.width\", \"image.nChannels\", \"image.data\").head()\r\n", | ||
"locals().update(row.asDict())\r\n", | ||
"rgb_image_array = rotate_color_channel(data, height, width, nChannels)\r\n", | ||
"\r\n", | ||
"# Download the ONNX model\r\n", | ||
"modelPayload = downloadBytes(\"https://mmlspark.blob.core.windows.net/publicwasb/ONNXModels/resnet50-v2-7.onnx\")\r\n", | ||
"\r\n", | ||
"featurizer = (\r\n", | ||
" ImageTransformer(inputCol=\"image\", outputCol=\"features\")\r\n", | ||
" .resize(224, True)\r\n", | ||
" .centerCrop(224, 224)\r\n", | ||
" .normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], color_scale_factor = 1/255)\r\n", | ||
" .setTensorElementType(FloatType())\r\n", | ||
")\r\n", | ||
"\r\n", | ||
"onnx = (\r\n", | ||
" ONNXModel()\r\n", | ||
" .setModelPayload(modelPayload)\r\n", | ||
" .setFeedDict({\"data\": \"features\"})\r\n", | ||
" .setFetchDict({\"rawPrediction\": \"resnetv24_dense0_fwd\"})\r\n", | ||
" .setSoftMaxDict({\"rawPrediction\": \"probability\"})\r\n", | ||
" .setMiniBatchSize(1)\r\n", | ||
")\r\n", | ||
"\r\n", | ||
"from synapse.ml.io import *\n", | ||
"\n", | ||
"image_df = spark.read.image().load(\"wasbs://[email protected]/explainers/images/david-lusvardi-dWcUncxocQY-unsplash.jpg\")\n", | ||
"display(image_df)\n", | ||
"\n", | ||
"# Rotate the image array from BGR into RGB channels for visualization later.\n", | ||
"row = image_df.select(\"image.height\", \"image.width\", \"image.nChannels\", \"image.data\").head()\n", | ||
"locals().update(row.asDict())\n", | ||
"rgb_image_array = rotate_color_channel(data, height, width, nChannels)\n", | ||
"\n", | ||
"# Download the ONNX model\n", | ||
"modelPayload = downloadBytes(\"https://mmlspark.blob.core.windows.net/publicwasb/ONNXModels/resnet50-v2-7.onnx\")\n", | ||
"\n", | ||
"featurizer = (\n", | ||
" ImageTransformer(inputCol=\"image\", outputCol=\"features\")\n", | ||
" .resize(224, True)\n", | ||
" .centerCrop(224, 224)\n", | ||
" .normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], color_scale_factor = 1/255)\n", | ||
" .setTensorElementType(FloatType())\n", | ||
")\n", | ||
"\n", | ||
"onnx = (\n", | ||
" ONNXModel()\n", | ||
" .setModelPayload(modelPayload)\n", | ||
" .setFeedDict({\"data\": \"features\"})\n", | ||
" .setFetchDict({\"rawPrediction\": \"resnetv24_dense0_fwd\"})\n", | ||
" .setSoftMaxDict({\"rawPrediction\": \"probability\"})\n", | ||
" .setMiniBatchSize(1)\n", | ||
")\n", | ||
"\n", | ||
"model = Pipeline(stages=[featurizer, onnx]).fit(image_df)" | ||
], | ||
"outputs": [], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.