{ "cells": [ { "cell_type": "code", "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2018-09-30T11:54:23.398548Z", "start_time": "2018-09-30T11:54:23.169238Z" } }, "outputs": [ { "data": { "text/plain": [ "array([ 0.75, 0.9 , 0.85, 0.35, -0.8 , -0.6 , 0.8 , 0.8 ])" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import h5py\n", "from sklearn.model_selection import train_test_split\n", "\n", "#now load this dataset \n", "h5f = h5py.File('./datasets/s8_sio2tio2_v2.h5','r')\n", "X = h5f['sizes'][:]\n", "Y = h5f['spectrum'][:]\n", "\n", "\n", "#create a train - test split of the dataset\n", "x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.4, random_state=42)\n", "\n", "# normalize inputs \n", "x_test = (x_test - 50)/20 \n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2018-09-30T11:45:01.118397Z", "start_time": "2018-09-30T11:44:59.855736Z" } }, "outputs": [], "source": [ "import numpy as np\n", "import mxnet as mx\n", "\n", "# Step1: Load the model in MXNet\n", "\n", "# Use the same prefix and epoch parameters we used in save_mxnet_model API.\n", "sym, arg_params, aux_params = mx.model.load_checkpoint(prefix='my_mod', epoch=0)\n", "\n", "# We use the data_names and data_shapes returned by save_mxnet_model API.\n", "mod = mx.mod.Module(symbol=sym, \n", " data_names=['/input_12'], \n", " context=mx.gpu(1), \n", " label_names=None)\n", "mod.bind(for_training=False, \n", " data_shapes=[('/input_12', (1,8))], \n", " label_shapes=mod._label_shapes)\n", "mod.set_params(arg_params, aux_params, allow_missing=True) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2018-09-30T11:47:00.407910Z", "start_time": "2018-09-30T11:47:00.306416Z" } }, "outputs": [ { "data": { "text/plain": [ "gpu(1)" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "size = np.random.randint(30, 71, (1,8))\n", "#spec_ac = snlay.calc_spectrum(size, mats, lams)\n", "size = (size - 50.0)/20.0\n", "#size = np.expand_dims(size, axis = 0)\n", "size.shape\n", "#res1 = model.predict(size)\n", "#data_iter = mx.io.NDArrayIter(size, None, 1)\n", "for icv in np.arange(1000):\n", " res2 = mod.predict(size)\n", "res2.context" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2018-09-30T11:42:00.611085Z", "start_time": "2018-09-30T11:42:00.601881Z" } }, "outputs": [ { "data": { "text/plain": [ "\n", "[[0. 0. 0. 0.]\n", " [0. 0. 0. 0.]\n", " [0. 0. 0. 0.]]\n", "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import mxnet as mx\n", "from mxnet import nd\n", "mx.random.seed(1)\n", "x = nd.empty((3, 4), ctx=mx.gpu(0))\n", "x" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.6" } }, "nbformat": 4, "nbformat_minor": 2 }