include("aux_func.jl") using PlotlyJS: savefig using Statistics using PlotlyJS using Random #= Obtain energy data =# #mni_folder_1 = "ini_exp_data/" mni_folder_100 = "exp_100_epochs/"; cif_folder_100 = "CIFAR_100_epoch/"; mni_folder_acc = "data_bounded/"; cif_folder_acc = "CIFAR_acc_bound/"; mni_folder_wat = "data_budget/"; cif_folder_wat = "CIFAR_energy_bound/"; mni_folder_est = "early_stop_res/"; cif_folder_est = "CIFAR_early_stop/"; bayes_model = "bayes"; freq_model = "freq"; w_type = "watt"; e_type = "exp"; #= Load GPU data =# mni_100_bay_ene = getgpudata(mni_folder_100, bayes_model, w_type, "eo"); mni_100_fre_ene = getgpudata(mni_folder_100, freq_model, w_type, "eo"); cif_100_bay_ene = getgpudata(cif_folder_100, bayes_model, w_type, "eo"); cif_100_fre_ene = getgpudata(cif_folder_100, freq_model, w_type, "eo"); #= Define CPU paths =# cif = "cifar"; mni = "mnist"; bay = "bayes"; wat = "cpu_watts"; frq = "freq"; ram = "ram_use"; _100 = "100"; acc = "acc"; es = "es"; wbud = "wbud"; #= Load CPU data =# bay_cif_100_ene = readcpudata(cif, bay, wat, _100); bay_mni_100_ene = readcpudata(mni, bay, wat, _100); frq_cif_100_ene = readcpudata(cif, frq, wat, _100); frq_mni_100_ene = readcpudata(mni, frq, wat, _100); for s = 1:5 bay_cif_100_ene[s] = round.(getcpuwatt(bay_cif_100_ene[s])) bay_mni_100_ene[s] = round.(getcpuwatt(bay_mni_100_ene[s])) frq_cif_100_ene[s] = round.(getcpuwatt(frq_cif_100_ene[s])) frq_mni_100_ene[s] = round.(getcpuwatt(frq_mni_100_ene[s])) end for s = 1:5 mni_100_bay_ene[s]["Ene"] = vcat(mni_100_bay_ene[s]["Ene"], bay_mni_100_ene[s]) mni_100_fre_ene[s]["Ene"] = vcat(mni_100_fre_ene[s]["Ene"], frq_mni_100_ene[s]) cif_100_bay_ene[s]["Ene"] = vcat(cif_100_bay_ene[s]["Ene"], bay_cif_100_ene[s]) cif_100_fre_ene[s]["Ene"] = vcat(cif_100_fre_ene[s]["Ene"], frq_cif_100_ene[s]) end ene_data = Dict("mni" => Dict("bay" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "fre" => Dict(1 => [],2 => [],3 => [],4 => [],5 => [])), "cif" => Dict("bay" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "fre" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []))) #ene_data = Dict("mni" => Dict("bay" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0), # "fre" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0)), # "cif" => Dict("bay" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0), # "fre" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0))) for s = 1:5 ene_data["mni"]["bay"][s] = sum.(join_vectors(resize1(makechunks(shuffle(mni_100_bay_ene[s]["Ene"]), 100))[1:50])) ene_data["mni"]["fre"][s] = sum.(join_vectors(resize1(makechunks(shuffle(mni_100_fre_ene[s]["Ene"]), 100))[1:50])) ene_data["cif"]["bay"][s] = sum.(join_vectors(resize1(makechunks(shuffle(cif_100_bay_ene[s]["Ene"]), 100))[1:50])) ene_data["cif"]["fre"][s] = sum.(join_vectors(resize1(makechunks(shuffle(cif_100_fre_ene[s]["Ene"]), 100))[1:50])) end #for s = 1:5 # ene_data["mni"]["bay"][s] = sum(mni_100_bay_ene[s]["Ene"]) / 100 # ene_data["mni"]["fre"][s] = sum(mni_100_fre_ene[s]["Ene"]) / 100 # ene_data["cif"]["bay"][s] = sum(cif_100_bay_ene[s]["Ene"]) / 100 # ene_data["cif"]["fre"][s] = sum(cif_100_fre_ene[s]["Ene"]) / 100 #end #= Load Accuracy data =# mni_100_bay_exp = getgpudata(mni_folder_100, bayes_model, e_type, "eo"); mni_100_fre_exp = getgpudata(mni_folder_100, freq_model, e_type, "eo"); cif_100_bay_exp = getgpudata(cif_folder_100, bayes_model, e_type, "eo"); cif_100_fre_exp = getgpudata(cif_folder_100, freq_model, e_type, "eo"); for i = 1:5 mni_100_bay_exp[i] = expdatatodict(mni_100_bay_exp[i]) mni_100_fre_exp[i] = expdatatodict(mni_100_fre_exp[i]) cif_100_bay_exp[i] = expdatatodict(cif_100_bay_exp[i]) cif_100_fre_exp[i] = expdatatodict(cif_100_fre_exp[i]) end original_vectors = Dict("LeNet" => Dict("MNIST" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "CIFAR" => Dict(1 => [],2 => [],3 => [],4 => [],5 => [])), "BCNN" => Dict("MNIST" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "CIFAR" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []))) for i in 1:5 original_vectors["LeNet"]["MNIST"][i] = (mni_100_fre_exp[i]["acc"][1:50] ./ ene_data["mni"]["fre"][i]) * 100 original_vectors["BCNN"]["MNIST"][i] = (mni_100_bay_exp[i]["acc"][1:50] ./ ene_data["mni"]["bay"][i]) * 100 original_vectors["LeNet"]["CIFAR"][i] = (cif_100_fre_exp[i]["acc"][1:50] ./ ene_data["cif"]["fre"][i]) * 100 original_vectors["BCNN"]["CIFAR"][i] = (cif_100_bay_exp[i]["acc"][1:50] ./ ene_data["cif"]["bay"][i]) * 100 end en_plot = plot( [ scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["MNIST"][1], name = "LeNet 1", marker = attr(symbol = 4, color = "rgb(211,120,000)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["MNIST"][2], name = "LeNet 2", marker = attr(symbol = 17, color = "rgb(255,170,017)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["MNIST"][3], name = "LeNet 3", marker = attr(symbol = 2, color = "rgb(255,187,034)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["MNIST"][4], name = "LeNet 4", marker = attr(symbol = 0, color = "rgb(255,204,051)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["MNIST"][5], name = "LeNet 5", marker = attr(symbol = 4, color = "rgb(255,195,001)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["MNIST"][1], name = "BCNN 1", marker = attr(symbol = 4, color = "rgb(055,033,240)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["MNIST"][2], name = "BCNN 2", marker = attr(symbol = 4, color = "rgb(018,094,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["MNIST"][3], name = "BCNN 3", marker = attr(symbol = 4, color = "rgb(018,126,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["MNIST"][4], name = "BCNN 4", marker = attr(symbol = 4, color = "rgb(018,150,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["MNIST"][5], name = "BCNN 5", marker = attr(symbol = 4, color = "rgb(018,167,219)", line_width = 1.0), ), ], Layout( mode = "overlay", xaxis_tickangle = -45, yaxis_title_text = "Efficency", xaxis_title_text = "Epoch"; opacity = 0.9, #xaxis_range = [-1, 5], #xaxis_type = "category", ), ) savefig(en_plot, "mnist_efficiency_epoch.png") en_plot = plot( [ scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["CIFAR"][1], name = "LeNet 1", marker = attr(symbol = 4, color = "rgb(211,120,000)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["CIFAR"][2], name = "LeNet 2", marker = attr(symbol = 17, color = "rgb(255,170,017)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["CIFAR"][3], name = "LeNet 3", marker = attr(symbol = 2, color = "rgb(255,187,034)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["CIFAR"][4], name = "LeNet 4", marker = attr(symbol = 0, color = "rgb(255,204,051)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["LeNet"]["CIFAR"][5], name = "LeNet 5", marker = attr(symbol = 4, color = "rgb(255,195,001)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["CIFAR"][1], name = "BCNN 1", marker = attr(symbol = 4, color = "rgb(055,033,240)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["CIFAR"][2], name = "BCNN 2", marker = attr(symbol = 4, color = "rgb(018,094,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["CIFAR"][3], name = "BCNN 3", marker = attr(symbol = 4, color = "rgb(018,126,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["CIFAR"][4], name = "BCNN 4", marker = attr(symbol = 4, color = "rgb(018,150,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = original_vectors["BCNN"]["CIFAR"][5], name = "BCNN 5", marker = attr(symbol = 4, color = "rgb(018,167,219)", line_width = 1.0), ), ], Layout( mode = "overlay", xaxis_tickangle = -45, yaxis_title_text = "Efficency", xaxis_title_text = "Epoch"; opacity = 0.9, #xaxis_range = [-1, 5], #xaxis_type = "category", ), ) savefig(en_plot, "cifar_efficiency_epoch.png")