Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Add the APIs,scripts and models to support DCGAN.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu, Chong committed Oct 31, 2017
1 parent 3b14c6f commit f9ccaa5
Show file tree
Hide file tree
Showing 12 changed files with 1,087 additions and 2 deletions.
10 changes: 10 additions & 0 deletions data/Celeb-A/celebA.txt
@@ -0,0 +1,10 @@
/Celeb-A_Cropped/000001.jpg 1
/Celeb-A_Cropped/000002.jpg 1
/Celeb-A_Cropped/000003.jpg 1
/Celeb-A_Cropped/000004.jpg 1
/Celeb-A_Cropped/000005.jpg 1
/Celeb-A_Cropped/000006.jpg 1
/Celeb-A_Cropped/000007.jpg 1
/Celeb-A_Cropped/000008.jpg 1
/Celeb-A_Cropped/000009.jpg 1
/Celeb-A_Cropped/000010.jpg 1
59 changes: 59 additions & 0 deletions data/Celeb-A/crop_celebA.py
@@ -0,0 +1,59 @@
from PIL import Image
import os
import sys

print ""
print "Prepare Celeb-A Dataset! (1. Crop the images. 2. Generate a train list file.)"
print ""
print "-------------------------------------------------------------------------------"

current_path = os.getcwd()
celebA_path = ""
celebA_cropped_path = ""
print "The current path containing this python file is: " + current_path
if len(sys.argv) == 1:
print "Please give the path of original Celeb-A dataset!"
exit(0)
elif len(sys.argv) > 1:
print "The path of original Celeb-A dataset is: " + str(sys.argv[1])
celebA_path = sys.argv[1]
celebA_cropped_path = os.path.dirname(celebA_path) + os.sep + "Cropped" #To avoid crop the generated images again if this parameter is not provided
if len(sys.argv) > 2:
print "The path of cropped Celeb-A dataset will be: " + str(sys.argv[2])
celebA_cropped_path = sys.argv[2]
else:
print "The path of cropped Celeb-A dataset will be defult, set as: " + celebA_cropped_path

if os.path.exists(celebA_cropped_path):
print "The path of cropped Celeb-A dataset exists."
else:
print "The path of cropped Celeb-A dataset doesn't exist! I will create it now!"
os.makedirs(celebA_cropped_path)
print "-------------------------------------------------------------------------------"

training_list_file = os.path.join(celebA_cropped_path, "celebA.txt")
list_file = open(training_list_file, 'w')
total_image_num = 0
x1, y1 = 30, 40
cropped_box = (x1, y1, x1 + 138, y1 + 138)

for parent,dirnames,filenames in os.walk(celebA_path):
for filename in filenames:
if filename.endswith(".jpg"):
total_image_num += 1
#print "parent is:" + parent
#print "filename is:" + filename
image_path_and_name = os.path.join(parent,filename)
print "the full name of the file is: " + image_path_and_name
input_image = Image.open(image_path_and_name)
#input_image.show()
cropped_image = input_image.crop(cropped_box)
#cropped_image.show()
scaled_cropped_image = cropped_image.resize((64, 64))
#scaled_cropped_image.show()
save_result_image_path_and_name = os.path.join(celebA_cropped_path,filename)
scaled_cropped_image.save(save_result_image_path_and_name, 'jpeg')
list_file.writelines(save_result_image_path_and_name)
list_file.writelines(" 1" + "\n") #Must add label to list file
print "There are " + str(total_image_num) + " images are finished with cropping and scaling operations!"
list_file.close()
3 changes: 3 additions & 0 deletions include/caffe/net.hpp
Expand Up @@ -326,6 +326,9 @@ class Net {
/// @brief return whether NetState state meets NetStateRule rule
static bool StateMeetsRule(const NetState& state, const NetStateRule& rule,
const string& layer_name);
inline const map<string,int>& blob_names_index() const {
return blob_names_index_;
}

protected:
// Helpers for Init.
Expand Down
1 change: 1 addition & 0 deletions include/caffe/solver.hpp
Expand Up @@ -113,6 +113,7 @@ class Solver {
}
int iter() { return iter_; }
void set_iter(int value) { iter_ = value; }
void increment_iter() { iter_++; }

// Invoked at specific points during an iteration
class Callback {
Expand Down
17 changes: 17 additions & 0 deletions models/intel_optimized_models/dcgan/data.prototxt
@@ -0,0 +1,17 @@

layer {
name: "data"
type: "ImageData"
top: "data"
top: "label"
transform_param {
mirror: true
mean_value: 104
mean_value: 117
mean_value: 123
}
image_data_param {
source: "data/Celeb-A/celebA.txt"
batch_size: 64
}
}

0 comments on commit f9ccaa5

Please sign in to comment.