to do: debug existing JSON file feature

This commit is contained in:
Mikayla Dobson
2023-01-07 19:53:23 -06:00
parent c4e7e1301c
commit b1ba613468
3 changed files with 91 additions and 52 deletions

34
main.py
View File

@@ -6,36 +6,30 @@
import os, json
from config import Config
from time import time
from predict import predict
from formatresult import format_result
from keras.applications.vgg16 import VGG16
print("\n\nImage Sorting Utility\n")
print("\nImage Sorting Utility\n")
print("Script by Mikayla Dobson\n")
print("\n\n")
############################## CONFIG
print("Running app config...")
appconfig = Config()
appconfig: Config = Config()
config_file = appconfig.run()
############################## SETUP
############################## SETUP
############################## SETUP
if (config_file.get_data_path()[-1] != "/"):
config_file.set_data_path(config_file.get_data_path() + "/")
# create the target directory if it doesn't exist
if (not os.path.exists("./predictions")):
print("Did not find predictions directory, creating...\n\n")
os.makedirs("./predictions")
# receive directory path as CLI argument and get a list of all files in path
src_path = config_file.data_path
############################## SETUP
############################## SETUP
############################## SETUP
if (src_path[-1] != "/"):
src_path += "/"
files = os.listdir(src_path)
files = os.listdir(config_file.data_path)
# generate current time for use in identifying outfiles
cur_time = str(int(time()))
@@ -47,6 +41,14 @@ all_results = []
############################## ANALYSIS
############################## ANALYSIS
print("Attempting TF imports...\n\n")
from predict import predict
from formatresult import format_result
from keras.applications.vgg16 import VGG16
print("Success!")
# declare model to be used for each prediction
model = VGG16(weights='imagenet')
@@ -54,7 +56,7 @@ print("Running image analysis. This may take some time...\n\n")
# for each file in directory, append its prediction result to main list
for file in files:
result = predict(model, src_path + file)
result = predict(model, config_file.data_path + file)
if result is not None:
all_results.append({ "path": file, "prediction": result })
@@ -72,6 +74,6 @@ print("Analysis complete! Beginning sort process...\n\n")
############################## SORTING
############################## SORTING
format_result(src_path, json_path)
format_result(appconfig, json_path)
print("File sort successful! Process complete.")