Skip to content

Commit

Permalink
update website (#1912)
Browse files Browse the repository at this point in the history
  • Loading branch information
haifeng-jin authored Mar 20, 2024
1 parent 5549d89 commit 346df97
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 68 deletions.
9 changes: 4 additions & 5 deletions docs/ipynb/export.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@
"\n",
"print(type(model)) # <class 'tensorflow.python.keras.engine.training.Model'>\n",
"\n",
"try:\n",
" model.save(\"model_autokeras\", save_format=\"tf\")\n",
"except Exception:\n",
" model.save(\"model_autokeras.h5\")\n",
"model.save(\"model_autokeras.keras\")\n",
"\n",
"\n",
"loaded_model = load_model(\"model_autokeras\", custom_objects=ak.CUSTOM_OBJECTS)\n",
"loaded_model = load_model(\n",
" \"model_autokeras.keras\", custom_objects=ak.CUSTOM_OBJECTS\n",
")\n",
"\n",
"predicted_y = loaded_model.predict(np.expand_dims(x_test, -1))\n",
"print(predicted_y)"
Expand Down
16 changes: 10 additions & 6 deletions docs/ipynb/image_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"outputs": [],
"source": [
"(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
"x_train = x_train[:100]\n",
"y_train = y_train[:100]\n",
"x_test = x_test[:100]\n",
"y_test = y_test[:100]\n",
"print(x_train.shape) # (60000, 28, 28)\n",
"print(y_train.shape) # (60000,)\n",
"print(y_train[:3]) # array([7, 2, 1], dtype=uint8)"
Expand Down Expand Up @@ -75,7 +79,7 @@
"# Initialize the image classifier.\n",
"clf = ak.ImageClassifier(overwrite=True, max_trials=1)\n",
"# Feed the image classifier with training data.\n",
"clf.fit(x_train, y_train, epochs=10)\n",
"clf.fit(x_train, y_train, epochs=1)\n",
"\n",
"\n",
"# Predict with the best model.\n",
Expand Down Expand Up @@ -112,7 +116,7 @@
" y_train,\n",
" # Split the training data and use the last 15% as validation data.\n",
" validation_split=0.15,\n",
" epochs=10,\n",
" epochs=1,\n",
")"
]
},
Expand Down Expand Up @@ -144,7 +148,7 @@
" y_train,\n",
" # Use your own validation set.\n",
" validation_data=(x_val, y_val),\n",
" epochs=10,\n",
" epochs=1,\n",
")"
]
},
Expand Down Expand Up @@ -185,7 +189,7 @@
"clf = ak.AutoModel(\n",
" inputs=input_node, outputs=output_node, overwrite=True, max_trials=1\n",
")\n",
"clf.fit(x_train, y_train, epochs=10)"
"clf.fit(x_train, y_train, epochs=1)"
]
},
{
Expand Down Expand Up @@ -219,7 +223,7 @@
"clf = ak.AutoModel(\n",
" inputs=input_node, outputs=output_node, overwrite=True, max_trials=1\n",
")\n",
"clf.fit(x_train, y_train, epochs=10)"
"clf.fit(x_train, y_train, epochs=1)"
]
},
{
Expand Down Expand Up @@ -294,7 +298,7 @@
"\n",
"clf = ak.ImageClassifier(overwrite=True, max_trials=1)\n",
"# Feed the tensorflow Dataset to the classifier.\n",
"clf.fit(train_set, epochs=10)\n",
"clf.fit(train_set, epochs=1)\n",
"# Predict with the best model.\n",
"predicted_y = clf.predict(test_set)\n",
"# Evaluate the best model with testing data.\n",
Expand Down
18 changes: 12 additions & 6 deletions docs/ipynb/image_regression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
"x_train = x_train[:100]\n",
"y_train = y_train[:100]\n",
"x_test = x_test[:100]\n",
"y_test = y_test[:100]\n",
"print(x_train.shape) # (60000, 28, 28)\n",
"print(y_train.shape) # (60000,)\n",
"print(y_train[:3]) # array([7, 2, 1], dtype=uint8)"
Expand All @@ -65,7 +67,7 @@
"source": [
"The second step is to run the ImageRegressor. It is recommended have more\n",
"trials for more complicated datasets. This is just a quick demo of MNIST, so\n",
"we set max_trials to 1. For the same reason, we set epochs to 2. You can also\n",
"we set max_trials to 1. For the same reason, we set epochs to 1. You can also\n",
"leave the epochs unspecified for an adaptive number of epochs.\n"
]
},
Expand All @@ -80,7 +82,7 @@
"# Initialize the image regressor.\n",
"reg = ak.ImageRegressor(overwrite=True, max_trials=1)\n",
"# Feed the image regressor with training data.\n",
"reg.fit(x_train, y_train, epochs=2)\n",
"reg.fit(x_train, y_train, epochs=1)\n",
"\n",
"\n",
"# Predict with the best model.\n",
Expand Down Expand Up @@ -117,7 +119,7 @@
" y_train,\n",
" # Split the training data and use the last 15% as validation data.\n",
" validation_split=0.15,\n",
" epochs=2,\n",
" epochs=1,\n",
")"
]
},
Expand Down Expand Up @@ -190,7 +192,7 @@
"reg = ak.AutoModel(\n",
" inputs=input_node, outputs=output_node, overwrite=True, max_trials=1\n",
")\n",
"reg.fit(x_train, y_train, epochs=2)"
"reg.fit(x_train, y_train, epochs=1)"
]
},
{
Expand Down Expand Up @@ -224,7 +226,7 @@
"reg = ak.AutoModel(\n",
" inputs=input_node, outputs=output_node, overwrite=True, max_trials=1\n",
")\n",
"reg.fit(x_train, y_train, epochs=2)"
"reg.fit(x_train, y_train, epochs=1)"
]
},
{
Expand Down Expand Up @@ -258,6 +260,10 @@
"outputs": [],
"source": [
"(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
"x_train = x_train[:100]\n",
"y_train = y_train[:100]\n",
"x_test = x_test[:100]\n",
"y_test = y_test[:100]\n",
"\n",
"# Reshape the images to have the channel dimension.\n",
"x_train = x_train.reshape(x_train.shape + (1,))\n",
Expand All @@ -273,7 +279,7 @@
"\n",
"reg = ak.ImageRegressor(overwrite=True, max_trials=1)\n",
"# Feed the tensorflow Dataset to the regressor.\n",
"reg.fit(train_set, epochs=2)\n",
"reg.fit(train_set, epochs=1)\n",
"# Predict with the best model.\n",
"predicted_y = reg.predict(test_set)\n",
"# Evaluate the best model with testing data.\n",
Expand Down
16 changes: 8 additions & 8 deletions docs/ipynb/load.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
},
"outputs": [],
"source": [
"batch_size = 32\n",
"batch_size = 2\n",
"img_height = 180\n",
"img_width = 180\n",
"\n",
Expand Down Expand Up @@ -137,8 +137,8 @@
"outputs": [],
"source": [
"clf = ak.ImageClassifier(overwrite=True, max_trials=1)\n",
"clf.fit(train_data, epochs=1)\n",
"print(clf.evaluate(test_data))"
"clf.fit(train_data.take(100), epochs=1)\n",
"print(clf.evaluate(test_data.take(2)))"
]
},
{
Expand Down Expand Up @@ -203,8 +203,8 @@
")\n",
"\n",
"clf = ak.TextClassifier(overwrite=True, max_trials=1)\n",
"clf.fit(train_data, epochs=2)\n",
"print(clf.evaluate(test_data))"
"clf.fit(train_data.take(2), epochs=1)\n",
"print(clf.evaluate(test_data.take(2)))"
]
},
{
Expand All @@ -225,8 +225,8 @@
},
"outputs": [],
"source": [
"N_BATCHES = 30\n",
"BATCH_SIZE = 100\n",
"N_BATCHES = 2\n",
"BATCH_SIZE = 10\n",
"\n",
"\n",
"def get_data_generator(n_batches, batch_size):\n",
Expand All @@ -247,7 +247,7 @@
" output_shapes=((32, 32, 3), tuple()),\n",
").batch(BATCH_SIZE)\n",
"\n",
"clf = ak.ImageDataClassifier(overwrite=True, max_trials=1, seed=5)\n",
"clf = ak.ImageClassifier(overwrite=True, max_trials=1, seed=5)\n",
"clf.fit(x=dataset, validation_data=dataset, batch_size=BATCH_SIZE)\n",
"print(clf.evaluate(dataset))"
]
Expand Down
19 changes: 11 additions & 8 deletions docs/ipynb/multi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
},
"outputs": [],
"source": [
"num_instances = 100\n",
"num_instances = 10\n",
"# Generate image data.\n",
"image_data = np.random.rand(num_instances, 32, 32, 3).astype(np.float32)\n",
"# Generate numerical data.\n",
Expand Down Expand Up @@ -144,7 +144,8 @@
"model.fit(\n",
" [image_data, numerical_data],\n",
" [regression_target, classification_target],\n",
" epochs=3,\n",
" epochs=1,\n",
" batch_size=3,\n",
")"
]
},
Expand Down Expand Up @@ -173,7 +174,8 @@
" [regression_target, classification_target],\n",
" # Split the training data and use the last 15% as validation data.\n",
" validation_split=0.15,\n",
" epochs=2,\n",
" epochs=1,\n",
" batch_size=3,\n",
")"
]
},
Expand All @@ -195,7 +197,7 @@
},
"outputs": [],
"source": [
"split = 20\n",
"split = 5\n",
"\n",
"image_val = image_data[split:]\n",
"numerical_val = numerical_data[split:]\n",
Expand All @@ -215,7 +217,8 @@
" [image_val, numerical_val],\n",
" [regression_val, classification_val],\n",
" ),\n",
" epochs=2,\n",
" epochs=1,\n",
" batch_size=3,\n",
")"
]
},
Expand Down Expand Up @@ -261,7 +264,7 @@
"output_node1 = ak.Merge()([output_node1, output_node2])\n",
"\n",
"input_node2 = ak.Input()\n",
"output_node2 = ak.DenseBlock()(output_node)\n",
"output_node2 = ak.DenseBlock()(input_node2)\n",
"\n",
"output_node = ak.Merge()([output_node1, output_node2])\n",
"output_node1 = ak.ClassificationHead()(output_node)\n",
Expand All @@ -282,8 +285,8 @@
"auto_model.fit(\n",
" [image_data, numerical_data],\n",
" [classification_target, regression_target],\n",
" batch_size=32,\n",
" epochs=3,\n",
" batch_size=3,\n",
" epochs=1,\n",
")"
]
},
Expand Down
31 changes: 17 additions & 14 deletions docs/ipynb/text_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
" os.path.join(IMDB_DATADIR, \"test\"), shuffle=False, categories=classes\n",
")\n",
"\n",
"x_train = np.array(train_data.data)\n",
"y_train = np.array(train_data.target)\n",
"x_test = np.array(test_data.data)\n",
"y_test = np.array(test_data.target)\n",
"x_train = np.array(train_data.data)[:100]\n",
"y_train = np.array(train_data.target)[:100]\n",
"x_test = np.array(test_data.data)[:100]\n",
"y_test = np.array(test_data.target)[:100]\n",
"\n",
"print(x_train.shape) # (25000,)\n",
"print(y_train.shape) # (25000, 1)\n",
Expand Down Expand Up @@ -100,7 +100,7 @@
" overwrite=True, max_trials=1\n",
") # It only tries 1 model as a quick demo.\n",
"# Feed the text classifier with training data.\n",
"clf.fit(x_train, y_train, epochs=2)\n",
"clf.fit(x_train, y_train, epochs=1, batch_size=2)\n",
"# Predict with the best model.\n",
"predicted_y = clf.predict(x_test)\n",
"# Evaluate the best model with testing data.\n",
Expand Down Expand Up @@ -132,6 +132,8 @@
" y_train,\n",
" # Split the training data and use the last 15% as validation data.\n",
" validation_split=0.15,\n",
" epochs=1,\n",
" batch_size=2,\n",
")"
]
},
Expand All @@ -153,17 +155,18 @@
},
"outputs": [],
"source": [
"split = 5000\n",
"split = 5\n",
"x_val = x_train[split:]\n",
"y_val = y_train[split:]\n",
"x_train = x_train[:split]\n",
"y_train = y_train[:split]\n",
"clf.fit(\n",
" x_train,\n",
" y_train,\n",
" epochs=2,\n",
" epochs=1,\n",
" # Use your own validation set.\n",
" validation_data=(x_val, y_val),\n",
" batch_size=2,\n",
")"
]
},
Expand Down Expand Up @@ -196,7 +199,7 @@
"clf = ak.AutoModel(\n",
" inputs=input_node, outputs=output_node, overwrite=True, max_trials=1\n",
")\n",
"clf.fit(x_train, y_train, epochs=2)"
"clf.fit(x_train, y_train, epochs=1, batch_size=2)"
]
},
{
Expand Down Expand Up @@ -226,17 +229,17 @@
"outputs": [],
"source": [
"train_set = tf.data.Dataset.from_tensor_slices(((x_train,), (y_train,))).batch(\n",
" 32\n",
" 2\n",
")\n",
"test_set = tf.data.Dataset.from_tensor_slices(((x_test,), (y_test,))).batch(32)\n",
"test_set = tf.data.Dataset.from_tensor_slices(((x_test,), (y_test,))).batch(2)\n",
"\n",
"clf = ak.TextClassifier(overwrite=True, max_trials=2)\n",
"clf = ak.TextClassifier(overwrite=True, max_trials=1)\n",
"# Feed the tensorflow Dataset to the classifier.\n",
"clf.fit(train_set, epochs=2)\n",
"clf.fit(train_set.take(2), epochs=1)\n",
"# Predict with the best model.\n",
"predicted_y = clf.predict(test_set)\n",
"predicted_y = clf.predict(test_set.take(2))\n",
"# Evaluate the best model with testing data.\n",
"print(clf.evaluate(test_set))"
"print(clf.evaluate(test_set.take(2)))"
]
},
{
Expand Down
Loading

0 comments on commit 346df97

Please sign in to comment.