Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new model, more debug code #15

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ README.md
data/
.DS_Store
build/
__pychache__
__pychache__/
.idea
37 changes: 22 additions & 15 deletions collectmeterdigits/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,40 @@

def main():
parser = argparse.ArgumentParser()
parser.add_argument('--collect', help='collect all images. The edgeAI meter server name must be set')
parser.add_argument('--collect',
help='collect all images. The edgeAI meter server name must be set')
parser.add_argument('--days', type=int, default=3, help='count of days back to read. (default: 3)')
parser.add_argument('--labeling', default='', help='labelpath if you want label the images')
parser.add_argument('--keepdownloads', action='store_true', help='Normally all downloaded data will be deleted. If set it keeps the images.')
parser.add_argument('--nodownload', action='store_true', help='Do not download pictures. Only remove duplicates and labeling.')
parser.add_argument('--keepdownloads', action='store_true',
help='Normally all downloaded data will be deleted. If set it keeps the images.')
parser.add_argument('--nodownload', action='store_true',
help='Do not download pictures. Only remove duplicates and labeling.')
parser.add_argument('--startlabel', type=float, default=0.0, help='only images >= startlabel. (default: all)')
parser.add_argument('--savedublicates', action='store_true', help='Save the dublicates in an intermediate subdirectory in raw_images.')
parser.add_argument('--labelfile', default=None, help='file with list of image urls if you want label specific images.')
parser.add_argument('--savedublicates', action='store_true',
help='Save the dublicates in an intermediate subdirectory in raw_images.')
parser.add_argument('--labelfile', default=None,
help='file with list of image urls if you want label specific images.')
parser.add_argument('--model', default=None, help='model file path if a external model should be used')

# print help message if no argument is given
if len(sys.argv)==1:
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)

args = parser.parse_args()
if (args.model!=None):

if args.model is not None:
glob.model_path = args.model
if (args.labeling==''):
if (args.labelfile != None):
label(args.labeling, args.startlabel, args.labelfile)

if args.labeling == '':
if args.labelfile is not None:
label(args.labeling, args.startlabel, args.labelfile)
else:
collect(args.collect, args.days, keepolddata=args.keepdownloads, download=not args.nodownload, startlabel=args.startlabel)
collect(args.collect, args.days, keepolddata=args.keepdownloads, download=not args.nodownload,
startlabel=args.startlabel)
else:
label(args.labeling, args.startlabel)
label(args.labeling, args.startlabel)


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion collectmeterdigits/glob.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
interpreter=None
model_path = None
model_path: None = None
Binary file not shown.
21 changes: 12 additions & 9 deletions collectmeterdigits/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
from collectmeterdigits import glob

interpreter=None
internal_model_path = pkg_resources.resource_filename('collectmeterdigits', 'models/dig-class100-s2_20220905-213051_q.tflite')
internal_model_path = pkg_resources.resource_filename('collectmeterdigits', 'models/dig-class100-0160_s2_q.tflite')

def load_interpreter(model_path):
global interpreter
if (not has_tflite_runtime or glob.model_path=="off" ):
print("No model used.")

print('modelpath=', model_path)

if not has_tflite_runtime:
print('no tflite')
return
print("Use model: " + model_path)
if (glob.model_path=="off"):
if "off" == glob.model_path:
print('model_path=off')
return
interpreter = tflite.Interpreter(model_path=model_path)
return interpreter
Expand All @@ -30,11 +34,10 @@ def load_interpreter(model_path):
def predict( image):
global interpreter

if (has_tflite_runtime and not glob.model_path=="off" ):

if interpreter==None:
if glob.model_path==None:
glob.model_path=internal_model_path
if has_tflite_runtime and not glob.model_path == "off":
if interpreter is None:
if glob.model_path is None:
glob.model_path = internal_model_path
load_interpreter(glob.model_path)
# if tflite can not be loaded
if interpreter == None:
Expand Down