Skip to content

Commit

Permalink
Merge pull request #1 from densitydesign/first-version
Browse files Browse the repository at this point in the history
Fix managing of .csv files and parsing of bbox data
  • Loading branch information
Mitch90 authored Jan 16, 2019
2 parents d9470a8 + 23d1212 commit 7c49da9
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 56 deletions.
8 changes: 3 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,19 @@ <h1>Image tagging tool interface</h1>
</div>

<div class="input__model">
<label for="model-select">Select a Clarifai Model (three models available):</label>
<label for="model-select">Select a Clarifai Model:</label>
<select id="model-select">
<option value="aaa03c23b3724a16a56b629203edc62c">General</option>
<option value="e0be3b9d6a454f0493ac3a30784001ff">Apparel</option>
<option value="e466caa0619f444ab97497640cefc4dc">Celebrity</option>
<option value="eeed0b6733a644cea07cf4c60f87ebb7">Color</option>
<option value="c0c0ac362b03416da06ab3fa36fb58e3">Demographics</option>
<option value="a403429f2ddf4b49b307e318f00e528b">Face Detection</option>
<option value="e466caa0619f444ab97497640cefc4dc">Celebrity</option>
<option value="e0be3b9d6a454f0493ac3a30784001ff">Apparel</option>
<option value="bd367be194cf45149e75f01d59f77ba7">Food</option>
<option value="d16f390eb32cad478c7ae150069bd2c6">Moderation</option>
<option value="e9576d86d2004ed1a38ba0cf39ecb4b1">NSFW</option>
<option value="fbefb47f9fdb410e8ce14f24f54b47ff">Textures and Patterns</option>
<option value="eee28c313d69466f836ab83287a54ed9">Travel</option>
<!-- To remove, useless -->
<!-- -->
</select>
</div>

Expand Down
165 changes: 114 additions & 51 deletions js/csv-worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
onmessage = function(e) {

console.log(e)
onmessage = function (e) {

let conceptsArray = [];

Expand All @@ -12,13 +10,16 @@ onmessage = function(e) {
if (Object.keys(output['data']).length === 0 && output['data'].constructor === Object) {
conceptsArray.push({
url: imageUrl,
concept: null,
concept: 'No elements present',
confidence: null
});
} else {
let maxConfidence = 0;

for (let j = 0; j < output['data']['concepts'].length; j++) {
let concept = output['data']['concepts'][j]['name'];
let confidence = output['data']['concepts'][j]['value'];
maxConfidence = Math.max(maxConfidence, confidence);

if (+confidence >= 0.1) {
conceptsArray.push({
Expand All @@ -28,6 +29,14 @@ onmessage = function(e) {
});
}
}

if (maxConfidence < 0.1) {
conceptsArray.push({
url: imageUrl,
concept: 'No elements present',
confidence: null
});
}
}

} else {
Expand All @@ -38,27 +47,52 @@ onmessage = function(e) {
conceptsArray.push({
url: imageUrl,
celebrity: 'No celebrity present',
bbox: null,
confidence: null
confidence: null,
bbox_border_top: null,
bbox_border_bottom: null,
bbox_border_left: null,
bbox_border_right: null,
bbox_area_x: null,
bbox_area_y: null
});
} else {
for (let j = 0; j < output['data']['regions'].length; j++) {
let regions = output['data']['regions'][j];
let bbox = regions['region_info']['bounding_box'];
let maxConfidence = 0;

for (let k = 0; k < regions['data']['face']['identity']['concepts'].length; k++) {
let celebrity = regions['data']['face']['identity']['concepts'][k]['name'];
let confidence = regions['data']['face']['identity']['concepts'][k]['value'];
maxConfidence = Math.max(maxConfidence, confidence);

if (+confidence >= 0.1) {
conceptsArray.push({
url: imageUrl,
celebrity: celebrity,
bbox: bbox,
confidence: +confidence
confidence: +confidence,
bbox_border_top: Math.round(bbox.top_row * 100) + '%',
bbox_border_bottom: Math.round(bbox.bottom_row * 100) + '%',
bbox_border_left: Math.round(bbox.left_col * 100) + '%',
bbox_border_right: Math.round(bbox.right_col * 100) + '%',
bbox_area_x: Math.round(bbox.right_col * 100) - Math.round(bbox.left_col * 100) + '%',
bbox_area_y: Math.round(bbox.bottom_row * 100) - Math.round(bbox.top_row * 100) + '%'
});
}
}
if (maxConfidence < 0.1) {
conceptsArray.push({
url: imageUrl,
celebrity: 'No celebrity present',
confidence: null,
bbox_border_top: null,
bbox_border_bottom: null,
bbox_border_left: null,
bbox_border_right: null,
bbox_area_x: null,
bbox_area_y: null
});
}
}
}
break;
Expand All @@ -82,10 +116,16 @@ onmessage = function(e) {
if (Object.keys(output['data']).length === 0 && output['data'].constructor === Object) {
conceptsArray.push({
url: imageUrl,
person_present: false,
age: null,
gender: null,
multicultural: null,
bbox: null,
bbox_border_top: null,
bbox_border_bottom: null,
bbox_border_left: null,
bbox_border_right: null,
bbox_area_x: null,
bbox_area_y: null
});
} else {
for (let j = 0; j < output['data']['regions'].length; j++) {
Expand All @@ -103,47 +143,60 @@ onmessage = function(e) {
mean += (newAge * factor);
factors += factor;
}
for (let k = 0; k < faces['data']['face']['gender_appearance']['concepts'].length; k++) {
let confidence = faces['data']['face']['gender_appearance']['concepts'][k]['value'];
if (+confidence >= 0.1) {
let newGender = faces['data']['face']['gender_appearance']['concepts'][k]['name'].concat(' - ', confidence);
if (gender.length > 0) {
gender = gender.concat('|', newGender);
} else {
gender = newGender;
}
}
}
for (let k = 0; k < faces['data']['face']['multicultural_appearance']['concepts'].length; k++) {
let confidence = faces['data']['face']['multicultural_appearance']['concepts'][k]['value'];
if (+confidence >= 0.1) {
let newCulture = faces['data']['face']['multicultural_appearance']['concepts'][k]['name'].concat(' - ', confidence);
if (multicultural.length > 0) {
multicultural = multicultural.concat('|', newCulture);
} else {
multicultural = newCulture;
}
}
}

// for (let k = 0; k < faces['data']['face']['gender_appearance']['concepts'].length; k++) {
// let confidence = faces['data']['face']['gender_appearance']['concepts'][k]['value'];
// if (+confidence >= 0.1) {
// let newGender = faces['data']['face']['gender_appearance']['concepts'][k]['name'].concat(' - ', confidence);
// if (gender.length > 0) {
// gender = gender.concat('|', newGender);
// } else {
// gender = newGender;
// }
// }
// }
gender = faces['data']['face']['gender_appearance']['concepts'][0]['name'];

// for (let k = 0; k < faces['data']['face']['multicultural_appearance']['concepts'].length; k++) {
// let confidence = faces['data']['face']['multicultural_appearance']['concepts'][k]['value'];
// if (+confidence >= 0.1) {
// let newCulture = faces['data']['face']['multicultural_appearance']['concepts'][k]['name'].concat(' - ', confidence);
// if (multicultural.length > 0) {
// multicultural = multicultural.concat('|', newCulture);
// } else {
// multicultural = newCulture;
// }
// }
// }
multicultural = faces['data']['face']['multicultural_appearance']['concepts'][0]['name'];

age = Math.round(mean / factors);

conceptsArray.push({
url: imageUrl,
age: age,
gender: gender,
multicultural: multicultural,
bbox_bottom: bbox.bottom_row,
bbox_left: bbox.left_col,
bbox_right: bbox.right_col,
bbox_top: bbox.top_row,
bbox_x: bbox.right_col - bbox.left_col,
bbox_y: bbox.bottom_row - bbox.top_row
});
if (mean == 0) {
conceptsArray.push({
url: imageUrl,
person_present: false,
age: null,
gender: null,
multicultural: null,
bbox_border_top: null,
bbox_border_bottom: null,
bbox_border_left: null,
bbox_border_right: null,
bbox_area_x: null,
bbox_area_y: null
});
} else {
age = Math.round(mean / factors);

conceptsArray.push({
url: imageUrl,
person_present: true,
age: age,
gender: gender,
multicultural: multicultural,
bbox_border_top: Math.round(bbox.top_row * 100) + '%',
bbox_border_bottom: Math.round(bbox.bottom_row * 100) + '%',
bbox_border_left: Math.round(bbox.left_col * 100) + '%',
bbox_border_right: Math.round(bbox.right_col * 100) + '%',
bbox_area_x: Math.round(bbox.right_col * 100) - Math.round(bbox.left_col * 100) + '%',
bbox_area_y: Math.round(bbox.bottom_row * 100) - Math.round(bbox.top_row * 100) + '%'
});
}
}
}
break;
Expand All @@ -152,7 +205,12 @@ onmessage = function(e) {
if (Object.keys(output['data']).length === 0 && output['data'].constructor === Object) {
conceptsArray.push({
url: imageUrl,
bbox: null
bbox_border_top: null,
bbox_border_bottom: null,
bbox_border_left: null,
bbox_border_right: null,
bbox_area_x: null,
bbox_area_y: null
});
} else {
for (let j = 0; j < output['data']['regions'].length; j++) {
Expand All @@ -161,7 +219,12 @@ onmessage = function(e) {

conceptsArray.push({
url: imageUrl,
bbox: bbox
bbox_border_top: Math.round(bbox.top_row * 100) + '%',
bbox_border_bottom: Math.round(bbox.bottom_row * 100) + '%',
bbox_border_left: Math.round(bbox.left_col * 100) + '%',
bbox_border_right: Math.round(bbox.right_col * 100) + '%',
bbox_area_x: Math.round(bbox.right_col * 100) - Math.round(bbox.left_col * 100) + '%',
bbox_area_y: Math.round(bbox.bottom_row * 100) - Math.round(bbox.top_row * 100) + '%'
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ function doDrop(event) {
} else {
$dropzoneText.innerText = "This is not a csv!"
}

finalData = [];
}

$inputAPI.addEventListener('input', function(event){
Expand All @@ -206,12 +208,14 @@ $inputAPI.addEventListener('input', function(event){
apiCheck = false;
$button.classList.remove("process-ready");
}
finalData = [];
});

$select.addEventListener('change', function(event){
let modelId = event.currentTarget.selectedOptions[0].value;

updateModelDesc(modelId);
finalData = [];
});

$dropzone.addEventListener('dragover', function(event){
Expand Down

0 comments on commit 7c49da9

Please sign in to comment.