Skip to content

Commit

Permalink
Set utf8 mode to output file
Browse files Browse the repository at this point in the history
  • Loading branch information
abars committed Jan 6, 2019
1 parent d97e506 commit 3400600
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions estimate_age.py 100644 → 100755
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ----------------------------------------------
# Predict age
# ----------------------------------------------
Expand All @@ -8,13 +11,14 @@
import os
import caffe
import glob
import codecs

# ----------------------------------------------
# MODE
# ----------------------------------------------

DATASET_ROOT_PATH="/Volumes/TB4/Keras/"
DATASET_SUB_PATH="Dataset/vggface2/"
DATASET_SUB_PATH="dataset/vggface2/"

# ----------------------------------------------
# Argument
Expand All @@ -24,17 +28,17 @@

if len(sys.argv) >= 1:
if len(sys.argv) >= 2:
DATASET_ROOT_PATH=sys.argv[3]
DATASET_ROOT_PATH=sys.argv[1]
if len(sys.argv) >= 3:
if sys.argv[4]=="gpu":
if sys.argv[2]=="gpu":
caffe.set_mode_gpu()
else:
if(sys.argv[4]=="cpu"):
if(sys.argv[2]=="cpu"):
None
else:
print("argv[4] must be gpu or cpu")
print("argv[2] must be gpu or cpu")
else:
print("usage: python calculate_age.py [datasetroot(optional)] [gpu/cpu(optional)]")
print("usage: python estimate_age.py [datasetroot(optional)] [gpu/cpu(optional)]")
sys.exit(1)

# ----------------------------------------------
Expand Down Expand Up @@ -70,7 +74,7 @@ def calc_age(image):
# FileList
# ----------------------------------------------

lines=open(DATASET_ROOT_PATH+DATASET_SUB_PATH+"identity_meta.csv").readlines()
lines=codecs.open(DATASET_ROOT_PATH+DATASET_SUB_PATH+"identity_meta.csv", 'r', 'utf-8').readlines()

OUTPUT_PATH=DATASET_ROOT_PATH+DATASET_SUB_PATH+"identity_meta_with_estimated_age.csv"
if(os.path.exists(OUTPUT_PATH)):
Expand All @@ -87,7 +91,7 @@ def calc_age(image):

DEBUG_MODE=0 #If 1, Age estimate from one image

with open(OUTPUT_PATH, mode='w') as f:
with codecs.open(OUTPUT_PATH, 'w', 'utf-8') as f:
cnt=0
for line in lines:
obj=line.split(", ")
Expand All @@ -108,6 +112,7 @@ def calc_age(image):
path2=DATASET_ROOT_PATH+DATASET_SUB_PATH+"test/"+path
else:
path2=DATASET_ROOT_PATH+DATASET_SUB_PATH+"train/"+path
print("target folder : "+path2)
age_sum=0
age_cnt=0
for image_path in glob.glob(path2+"/*.jpg"):
Expand Down

0 comments on commit 3400600

Please sign in to comment.