# Democratizing Deep Learning Applications in Earth and Climate Sciences on the Web: EarthAlHub
## 2 Materials and Methods
### Model Specification  
EarthAIHub accepts the TensorFlowjs GraphDef model format, also known as SavedModel, that can be read with the tf.loadGraphModel (...) function, as this function expects the path to the model.json file and the file is typically accompanied by several binary files, all of which are needed by the platform for proper execution. In order to ensure this, the web app expects a zip archive of all binary files and the model.json file in which the model.json is stored at the root of the zip archive at submission time. An example zip archive includes the model configuration file (i.e., model.json) and several binary files (i.e., group1-shard1o63.bin, group1-shard2o63.bin, group1-shard1o62.bin).  
EarthAIHub is designed to support two types of users; namely, model developers and model users from the earth and climate science domains. Consequently, the main task for the platform is to provide abstraction layers. In order to do so, we designed a configuration file format and specification that defines everything a user would need to run a TensorFlow.js model. The configuration file includes input format, output format, preprocessing type, preprocessing function, postprocessing type, and postprocessing function. Fields and their definitions for the config file can be seen in Tables A1-A5 in the Appendix. An example model configuration file can be seen in Figure 2.  
The example config.json file is built for a classifier model that was trained on 3-channel handwritten number images from the MNIST dataset and returns the predicted number. The model expects an input with the shape of 1 \(\times\) 1 \(\times\) 28 \(\times\) 28, but ideally, one would expect a user to submit an image to the model. Therefore, in order to facilitate that, we put img as the input type, but this design choice comes with an expense. We now need to preprocess the input that we assume to be an image that is 28 \(\times\) 28. As in the config tables in the Appendix, the image will be read from an HTML canvas and will have four channels, so in order to reduce the image to only one channel, we implement cv2.cvtColor with cv2.COLOR_BGR2 GRAY from python-OpenCV [41] in TensorFlow.js while avoiding the fourth channel and normalizing the input by dividing it by 255. Since we only dealt with tensors and our end product for the preprocess was a tensor as well, we could choose \"func/tensor-tensor\" as the preprocess type. Note that other preprocess types might well work without problems here, but our selection was a convenient one for our use case.  
Figure 1: Landing page of EarthAIHub deep learning platform.  
Furthermore, we will need to output a number that is the predicted handwritten digit from the image, so our output type should be raw. Our model outputs a vector with the shape of \(1\times 10\) that comprises the probability of each digit before the tf.softmax. Therefore, in postprocess, we run softmax over our output and then convert it to an array. Finally, we find the maximum value's index, which is the value our network has predicted, and return that. Since we chose to use TensorFlow;s tf.softmax function, it is more convenient for us to expect a tf.tensor into the postprocess function. Finally, since we output a number, we choose \"func/tensor-raw\" as the postprocessType.