Skip to content

Commit 2877329

Browse files
authored
Add files via upload
1 parent 3d4e336 commit 2877329

11 files changed

+1727
-0
lines changed

compression/compressrion.ipynb

+1,486
Large diffs are not rendered by default.

compression/models/netE8.model

4.28 MB
Binary file not shown.

compression/models/netG8.model

3.94 MB
Binary file not shown.

data/demo/valid_net0.png

76.9 KB
Loading

data/demo/valid_net1.png

76.2 KB
Loading

data/demo/valid_net2.png

81.9 KB
Loading

data/demo/valid_net3.png

76 KB
Loading

data/demo/valid_net4.png

77.8 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
%% script to test dataPreprocessing
2+
%% created by Fu-Jen Chu on 09/15/2016
3+
4+
close all
5+
clear
6+
7+
%parpool(4)
8+
addpath('/media/fujenchu/home3/data/grasps/')
9+
10+
11+
% generate list for splits
12+
list = [100:949 1000:1034];
13+
list_idx = randperm(length(list));
14+
train_list_idx = list_idx(length(list)/5+1:end);
15+
test_list_idx = list_idx(1:length(list)/5);
16+
train_list = list(train_list_idx);
17+
test_list = list(test_list_idx);
18+
19+
20+
for folder = 1:10
21+
display(['processing folder ' int2str(folder)])
22+
23+
imgDataDir = ['/home/fujenchu/projects/deepLearning/tensorflow-finetune-flickr-style-master/data/grasps/' sprintf('%02d',folder) '_rgd'];
24+
txtDataDir = ['/home/fujenchu/projects/deepLearning/tensorflow-finetune-flickr-style-master/data/grasps/' sprintf('%02d',folder)];
25+
26+
%imgDataOutDir = ['/home/fujenchu/projects/deepLearning/tensorflow-finetune-flickr-style-master/data/grasps/' sprintf('%02d',folder) '_Cropped320_rgd'];
27+
imgDataOutDir = '/media/fujenchu/home3/fasterrcnn_grasp/rgd_multibbs_5_5_5_tf/data/Images';
28+
annotationDataOutDir = '/media/fujenchu/home3/fasterrcnn_grasp/rgd_multibbs_5_5_5_tf/data/Annotations';
29+
imgSetTrain = '/media/fujenchu/home3/fasterrcnn_grasp/rgd_multibbs_5_5_5_tf/data/ImageSets/train.txt';
30+
imgSetTest = '/media/fujenchu/home3/fasterrcnn_grasp/rgd_multibbs_5_5_5_tf/data/ImageSets/test.txt';
31+
32+
imgFiles = dir([imgDataDir '/*.png']);
33+
txtFiles = dir([txtDataDir '/*pos.txt']);
34+
35+
logfileID = fopen('log.txt','a');
36+
mainfileID = fopen(['/home/fujenchu/projects/deepLearning/deepGraspExtensiveOffline/data/grasps/scripts/trainttt' sprintf('%02d',folder) '.txt'],'a');
37+
for idx = 1:length(imgFiles)
38+
%% display progress
39+
tic
40+
display(['processing folder: ' sprintf('%02d',folder) ', imgFiles: ' int2str(idx)])
41+
42+
%% reading data
43+
imgName = imgFiles(idx).name;
44+
[pathstr,imgname] = fileparts(imgName);
45+
46+
filenum = str2num(imgname(4:7));
47+
if(any(test_list == filenum))
48+
file_writeID = fopen(imgSetTest,'a');
49+
fprintf(file_writeID, '%s\n', [imgDataDir(1:end-3) 'Cropped320_rgd/' imgname '_preprocessed_1.png' ] );
50+
fclose(file_writeID);
51+
continue;
52+
end
53+
54+
txtName = txtFiles(idx).name;
55+
[pathstr,txtname] = fileparts(txtName);
56+
57+
img = imread([imgDataDir '/' imgname '.png']);
58+
fileID = fopen([txtDataDir '/' txtname '.txt'],'r');
59+
sizeA = [2 100];
60+
bbsIn_all = fscanf(fileID, '%f %f', sizeA);
61+
fclose(fileID);
62+
63+
%% data pre-processing
64+
[imagesOut bbsOut] = dataPreprocessing_fasterrcnn(img, bbsIn_all, 227, 5, 5);
65+
66+
% for each augmented image
67+
for i = 1:1:size(imagesOut,2)
68+
69+
% for each bbs
70+
file_writeID = fopen([annotationDataOutDir '/' imgname '_preprocessed_' int2str(i) '.txt'],'w');
71+
printCount = 0;
72+
for ibbs = 1:1:size(bbsOut{i},2)
73+
A = bbsOut{i}{ibbs};
74+
xy_ctr = sum(A,2)/4; x_ctr = xy_ctr(1); y_ctr = xy_ctr(2);
75+
width = sqrt(sum((A(:,1) - A(:,2)).^2)); height = sqrt(sum((A(:,2) - A(:,3)).^2));
76+
if(A(1,1) > A(1,2))
77+
theta = atan((A(2,2)-A(2,1))/(A(1,1)-A(1,2)));
78+
else
79+
theta = atan((A(2,1)-A(2,2))/(A(1,2)-A(1,1))); % note y is facing down
80+
end
81+
82+
% process to fasterrcnn
83+
x_min = x_ctr - width/2; x_max = x_ctr + width/2;
84+
y_min = y_ctr - height/2; y_max = y_ctr + height/2;
85+
%if(x_min < 0 || y_min < 0 || x_max > 227 || y_max > 227) display('yoooooooo'); end
86+
if((x_min < 0 && x_max < 0) || (y_min > 227 && y_max > 227) || (x_min > 227 && x_max > 227) || (y_min < 0 && y_max < 0)) display('xxxxxxxxx'); break; end
87+
cls = round((theta/pi*180+90)/10) + 1;
88+
89+
% write as lefttop rightdown, Xmin Ymin Xmax Ymax, ex: 261 109 511 705 (x水平 y垂直)
90+
fprintf(file_writeID, '%d %f %f %f %f\n', cls, x_min, y_min, x_max, y_max );
91+
printCount = printCount+1;
92+
end
93+
if(printCount == 0) fprintf(logfileID, '%s\n', [imgname '_preprocessed_' int2str(i) ]);end
94+
95+
fclose(file_writeID);
96+
imwrite(imagesOut{i}, [imgDataOutDir '/' imgname '_preprocessed_' int2str(i) '.png']);
97+
98+
% write filename to imageSet
99+
file_writeID = fopen(imgSetTrain,'a');
100+
fprintf(file_writeID, '%s\n', [imgname '_preprocessed_' int2str(i) ] );
101+
fclose(file_writeID);
102+
103+
end
104+
105+
106+
toc
107+
end
108+
fclose(mainfileID);
109+
110+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
function [imagesOut bbsOut] = dataPreprocessing( imageIn, bbsIn_all, cropSize, translationShiftNumber, roatateAngleNumber)
2+
% dataPreprocessing function perfroms
3+
% 1) croping
4+
% 2) padding
5+
% 3) rotatation
6+
% 4) shifting
7+
%
8+
% for a input image with a bbs as 4 points,
9+
% dataPreprocessing outputs a set of images with corresponding bbs.
10+
%
11+
%
12+
% Inputs:
13+
% imageIn: input image (480 by 640 by 3)
14+
% bbsIn: bounding box (2 by 4)
15+
% cropSize: output image size
16+
% shift: shifting offset
17+
% rotate: rotation angle
18+
%
19+
% Outputs:
20+
% imagesOut: output images (n images)
21+
% bbsOut: output bbs according to shift and rotation
22+
%
23+
%% created by Fu-Jen Chu on 09/15/2016
24+
25+
debug_dev = 0;
26+
debug = 0;
27+
%% show image and bbs
28+
if(debug_dev)
29+
figure(1); imshow(imageIn); hold on;
30+
x = bbsIn_all(1, [1:3]);
31+
y = bbsIn_all(2, [1:3]);
32+
plot(x,y); hold off;
33+
end
34+
35+
%% crop image and padding image
36+
% cropping to 321 by 321 from center
37+
imgCrop = imcrop(imageIn, [145 65 351 351]);
38+
39+
% padding to 501 by 501
40+
imgPadding = padarray(imgCrop, [75 75], 'replicate', 'both');
41+
42+
count = 1;
43+
for i_rotate = 1:roatateAngleNumber*translationShiftNumber*translationShiftNumber
44+
% random roatateAngle
45+
theta = randi(360)-1;
46+
%theta = 0;
47+
48+
% random translationShift
49+
dx = randi(101)-51;
50+
%dx = 0;
51+
52+
%% rotation and shifting
53+
% random translationShift
54+
dy = randi(101)-51;
55+
%dy = 0;
56+
57+
imgRotate = imrotate(imgPadding, theta);
58+
if(debug_dev)figure(2); imshow(imgRotate);end
59+
imgCropRotate = imcrop(imgRotate, [size(imgRotate,1)/2-160-dx size(imgRotate,1)/2-160-dy 320 320]);
60+
if(debug_dev)figure(3); imshow(imgCropRotate);end
61+
imgResize = imresize(imgCropRotate, [cropSize cropSize]);
62+
if(debug)figure(4); imshow(imgResize); hold on;end
63+
64+
%% modify bbs
65+
[m, n] = size(bbsIn_all);
66+
bbsNum = n/4;
67+
68+
countbbs = 1;
69+
for idx = 1:bbsNum
70+
bbsIn = bbsIn_all(:,idx*4-3:idx*4);
71+
if(sum(sum(isnan(bbsIn)))) continue; end
72+
73+
bbsInShift = bbsIn - repmat([320; 240], 1, 4);
74+
R = [cos(theta/180*pi) -sin(theta/180*pi); sin(theta/180*pi) cos(theta/180*pi)];
75+
bbsRotated = (bbsInShift'*R)';
76+
bbsInShiftBack = (bbsRotated + repmat([160; 160], 1, 4) + repmat([dx; dy], 1, 4))*cropSize/320;
77+
if(debug)
78+
figure(4)
79+
x = bbsInShiftBack(1, [1:4 1]);
80+
y = bbsInShiftBack(2, [1:4 1]);
81+
plot(x,y); hold on; pause(0.01);
82+
end
83+
bbsOut{count}{countbbs} = bbsInShiftBack;
84+
countbbs = countbbs + 1;
85+
end
86+
87+
imagesOut{count} = imgResize;
88+
count = count +1;
89+
90+
91+
end
92+
93+
94+
95+
end
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
4+
cd $DIR
5+
6+
NET=res101
7+
FILE=voc_0712_80k-110k.tgz
8+
# replace it with gs11655.sp.cs.cmu.edu if ladoga.graphics.cs.cmu.edu does not work
9+
URL=http://ladoga.graphics.cs.cmu.edu/xinleic/tf-faster-rcnn/$NET/$FILE
10+
CHECKSUM=cb32e9df553153d311cc5095b2f8c340
11+
12+
if [ -f $FILE ]; then
13+
echo "File already exists. Checking md5..."
14+
os=`uname -s`
15+
if [ "$os" = "Linux" ]; then
16+
checksum=`md5sum $FILE | awk '{ print $1 }'`
17+
elif [ "$os" = "Darwin" ]; then
18+
checksum=`cat $FILE | md5`
19+
fi
20+
if [ "$checksum" = "$CHECKSUM" ]; then
21+
echo "Checksum is correct. No need to download."
22+
exit 0
23+
else
24+
echo "Checksum is incorrect. Need to download again."
25+
fi
26+
fi
27+
28+
echo "Downloading Resnet 101 Faster R-CNN models Pret-trained on VOC 07+12 (340M)..."
29+
30+
wget $URL -O $FILE
31+
32+
echo "Unzipping..."
33+
34+
tar zxvf $FILE
35+
36+
echo "Done. Please run this command again to verify that checksum = $CHECKSUM."

0 commit comments

Comments
 (0)