-
Notifications
You must be signed in to change notification settings - Fork 1
/
testModel_Spark.py
41 lines (28 loc) · 957 Bytes
/
testModel_Spark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import csv
from NeuralLibrary import NeuralModel
import numpy as np
import pandas as pd
import sys
from random import random
from operator import add
from pyspark.sql import SparkSession
def main():
#Create a spark session
spark = SparkSession\
.builder\
.appName("PredictTemperature")\
.getOrCreate()
# Specify which model to use
data_path="/Spark-TFLite/jena_weather_dataset_roof.csv"
# Run the model in spark session with input data
df = pd.read_csv(data_path)
df_rdd = spark.sparkContext.parallelize([df])
input_rdd = df_rdd.map(lambda i: NeuralModel("/Spark-TFLite/model_bilstm.tflite").input_data(i))
output_rdd = input_rdd.map(lambda m: NeuralModel("/Spark-TFLite/model_bilstm.tflite").run(m))
output = output_rdd.collect()
print("***********************\nOutput =\n")
for x in output:
print(x[0])
if __name__ == '__main__':
main()