-
Notifications
You must be signed in to change notification settings - Fork 32
/
faces.js
505 lines (465 loc) · 12.8 KB
/
faces.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
import React, { Component } from 'react';
import { connect } from "react-redux";
import { Image, Header, Message, Dropdown, Divider, Card,
Container, Segment, Button, Icon, Popup, Loader,
Dimmer, Grid, Reveal, Statistic, Label, Table,
Modal } from 'semantic-ui-react';
import { fetchPeople,
addPerson ,
addPersonAndSetLabelToFace} from '../actions/peopleActions';
import { fetchFaces,
fetchLabeledFaces,
fetchInferredFaces,
deleteFaceAndFetchNext,
labelFacePerson ,
fetchFaceToLabel,
loadFaceToLabel,
labelFacePersonAndFetchNext} from '../actions/facesActions';
import VisibilitySensor from 'react-visibility-sensor'
import {Server, serverAddress} from '../api_client/apiClient'
import LazyLoad from 'react-lazyload';
export class FaceStatistics extends Component {
render() {
return (
<Statistic.Group size='mini'>
<Statistic>
<Statistic.Value>{this.props.labeledFaces.length}</Statistic.Value>
<Statistic.Label>Labelled</Statistic.Label>
</Statistic>
<Statistic>
<Statistic.Value>{this.props.inferredFaces.length}</Statistic.Value>
<Statistic.Label>Inferred</Statistic.Label>
</Statistic>
</Statistic.Group>
)
}
}
export class EditableFaceIcon extends Component {
state = {}
handleShow = () => this.setState({ active: true })
handleHide = () => this.setState({ active: false })
handleClick = () => this.props.dispatch(loadFaceToLabel(this.props.face))
render() {
const { active } = this.state
const content = (
<Icon link color='black' name='write' onClick={this.handleClick}/>
)
return (
<LazyLoad threshold
height={60}
width={60}
placeholder={
<Image height={60} width={60} avatar
shape='rounded' src={'/unknown_user.jpg'}/>
}>
<Popup
inverted
trigger={
<Dimmer.Dimmable
as={Image}
height={60}
width={60}
avatar
dimmed={active}
shape='rounded'
dimmer={{ active, content, inverted:true}}
onMouseEnter={this.handleShow}
onMouseLeave={this.handleHide}
src={this.props.face_url}/>}
content={this.props.person_name}/>
</LazyLoad>
)
}
}
export class FaceTableLabeled extends Component{
componentWillMount() {
this.props.dispatch(fetchLabeledFaces())
}
render() {
var person_names = [... new Set(this.props.labeledFaces.map(function(face){return face.person.name}))]
var faces = this.props.labeledFaces
var mappedRows = person_names.map(function(person_name){
var thisPersonsFaces = faces.filter(function(face){
return person_name===face.person.name
})
var mappedFaceIcons = thisPersonsFaces.map(function(face){
return (
<EditableFaceIcon
key={face.id}
face={face}
person_name={face.person.name}
face_url={serverAddress+face.face_url}
face_id={face.id}/>
)
})
return (
<Table.Row key={"table-row-labeled-"+person_name}>
<Table.Cell width={3}>{person_name}</Table.Cell>
<Table.Cell>{mappedFaceIcons}</Table.Cell>
</Table.Row>
)
})
return (
<Table compact celled selectable>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Person</Table.HeaderCell>
<Table.HeaderCell>Faces</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{mappedRows}
</Table.Body>
</Table>
)
}
}
export class FaceTableInferred extends Component{
componentWillMount() {
this.props.dispatch(fetchInferredFaces())
}
render() {
var person_names = [... new Set(this.props.inferredFaces.map(function(face){return face.person.name}))]
var faces = this.props.inferredFaces
var mappedRows = person_names.map(function(person_name){
var thisPersonsFaces = faces.filter(function(face){
return person_name===face.person.name
})
var mappedFaceIcons = thisPersonsFaces.map(function(face){
return (
<EditableFaceIcon
key={face.id}
face={face}
person_name={face.person.name}
face_url={serverAddress+face.face_url}
face_id={face.id}/>
)
})
return (
<Table.Row key={"table-row-inferred-"+person_name}>
<Table.Cell width={3}>{person_name}</Table.Cell>
<Table.Cell>{mappedFaceIcons}</Table.Cell>
</Table.Row>
)
})
return (
<Table compact celled selectable >
<Table.Header>
<Table.Row>
<Table.HeaderCell>Person</Table.HeaderCell>
<Table.HeaderCell>Faces</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{mappedRows}
</Table.Body>
</Table>
)
}
}
export class FacesLabeled extends Component {
componentWillMount() {
this.props.dispatch(fetchLabeledFaces())
}
render() {
var mappedFaceCards = this.props.labeledFaces.map(function(face){
return (
<EditableFaceIcon
key={face.id}
person_name={face.person.name}
face_url={serverAddress+face.face_url}
face_id={face.id}/>
)
})
return (
<Container>
<Header dividing as='h2'>
Labeled Faces
<Label>
<Icon name='user circle outline' />{this.props.labeledFaces.length}
</Label>
</Header>
{mappedFaceCards}
</Container>
)
}
}
export class FacesInferred extends Component {
componentWillMount() {
this.props.dispatch(fetchInferredFaces())
}
render() {
var mappedFaceCards = this.props.inferredFaces.map(function(face){
return (
<EditableFaceIcon
key={face.id}
person_name={face.person.name}
face_url={serverAddress+face.face_url}
face_id={face.id}/>
)
})
return (
<Container>
<Header dividing as='h2'>
Inferred Faces
<Label>
<Icon name='user circle outline' />{this.props.inferredFaces.length}
</Label>
</Header>
{mappedFaceCards}
</Container>
)
}
}
export class FaceCards extends Component {
componentWillMount() {
this.props.dispatch(fetchFaces())
this.props.dispatch(fetchPeople())
}
render() {
var mappedFaceCards = this.props.faces.map(function(face){
return (
<FaceCard
key={face.id}
face_id={face.id}
name={face.person.name}
face_url={serverAddress+face.face_url}/>
)
})
return (
<div>
<Button>Train</Button>
<Card.Group>
{mappedFaceCards}
</Card.Group>
</div>
)
}
}
export class FaceToLabel extends Component {
componentWillMount() {
this.props.dispatch(fetchFaceToLabel())
this.props.dispatch(fetchPeople())
}
render() {
console.log(this.props)
return (
<div>
<Card.Group>
<FaceCard
card_loading={this.props.faceToLabelFetching}
key={this.props.faceToLabel.id}
face_id={this.props.faceToLabel.id}
name={"hello"}
face_url={serverAddress+this.props.faceToLabel.face_url}/>
</Card.Group>
</div>
)
}
}
export class FaceCard extends Component {
render() {
let image = null;
if (this.props.card_loading){
image = (
<div>
<Dimmer active inverted>
<Loader inverted />
</Dimmer>
<Image
floated='right'
hidden
height={50}
width={50}
shape='rounded'/>
</div>
)
}
else {
image = <Image
floated='right'
height={50}
width={50}
shape='rounded'
src={this.props.face_url} />
}
if (this.props.face_id == null){
return (
<Card fluid>
<Card.Content>
<Card.Header>
{"No more face to label!"}
<div style={{height:"28px", width:"50px"}}></div>
</Card.Header>
</Card.Content>
<Card.Content extra>
<FaceCardMenu face_id={this.props.face_id}/>
</Card.Content>
</Card>
)
}
return (
<Card fluid>
<Card.Content>
<Card.Header>
{image}
{"Who is this person?"}
</Card.Header>
</Card.Content>
<Card.Content extra>
<FaceCardMenu face_id={this.props.face_id}/>
</Card.Content>
</Card>
);
}
}
export class FaceCardMenu extends Component {
handleAddPerson = (e, {value}) => {
console.log('handing add', value, this.props.face_id)
this.props.dispatch(addPerson(value))
this.currentValue = value
}
handleChange = (e, {value}) => {
console.log('handing change')
this.currentValue = value
}
handleDeleteFace = e => {
this.props.dispatch(deleteFaceAndFetchNext(this.props.face_id))
}
handleSubmit = e => {
this.props.dispatch(labelFacePersonAndFetchNext(this.props.face_id,this.currentValue))
}
render() {
if (this.props.face_id == null){
var buttonGroup = (
<Popup
trigger={<Button
color='green'
fluid
icon='star'/>}
position="top center"
content="Woohoo!"
size="tiny"
inverted
basic/>
)
}
else {
var buttonGroup = (
<div className='ui three buttons'>
<Popup
trigger={<Button
onClick={this.handleDeleteFace}
color='red'
icon='trash'/>}
position="top center"
content="Forget this face"
size="tiny"
inverted
basic/>
<Modal
basic
trigger={
<Button
color='orange'
icon='photo'/>
}>
<Modal.Header>
<Image fluid src={'/unknown_user.jpg'}/>
</Modal.Header>
</Modal>
<Popup
trigger={<Button
onClick={this.handleSubmit}
color='green'
icon='plus'/>}
position="top center"
content="Submit label and show next face"
size="tiny"
inverted
basic/>
</div>
)
}
return (
<div>
<Dropdown
placeholder='Choose Person'
search
fluid
selection
allowAdditions
loading={this.props.personAdding || this.props.peopleFetching}
onAddItem={this.handleAddPerson}
onChange={this.handleChange}
options={this.props.people} />
<Divider/>
{buttonGroup}
</div>
)
}
}
EditableFaceIcon = connect((store)=>{
return {
faceToLabel: store.faces.faceToLabel
}
})(EditableFaceIcon)
FaceTableInferred = connect((store)=>{
return {
inferredFaces: store.faces.inferredFaces
}
})(FaceTableInferred)
FaceTableLabeled = connect((store)=>{
return {
labeledFaces: store.faces.labeledFaces,
}
})(FaceTableLabeled)
FaceStatistics = connect((store)=>{
return {
labeledFaces: store.faces.labeledFaces,
inferredFaces: store.faces.inferredFaces
}
})(FaceStatistics)
FacesLabeled = connect((store)=>{
return {
labeledFaces: store.faces.labeledFaces,
fetchingLabeledFaces: store.faces.fetchingLabeledFaces,
fetchedLabeledFaces: store.faces.fetchedLabeledFaces
}
})(FacesLabeled)
FacesInferred = connect((store)=>{
return {
inferredFaces: store.faces.inferredFaces,
fetchingInferredFaces: store.faces.fetchingInferredFaces,
fetchedInferredFaces: store.faces.fetchedInferredFaces
}
})(FacesInferred)
FaceToLabel = connect((store)=>{
return {
faceToLabel: store.faces.faceToLabel,
facesFetched:store.faces.fetched,
faceToLabelFetching: store.faces.fetchingFaceToLabel,
faceToLabelFetched: store.faces.fetchedFaceToLabel,
}
})(FaceToLabel)
FaceCards = connect((store)=>{
return {
faces: store.faces.faces,
faceToLabel: store.faces.faceToLabel,
facesFetched:store.faces.fetched
}
})(FaceCards)
FaceCard = connect((store)=>{
return {
people: store.people.people,
peopleFetching: store.people.fetching,
}
})(FaceCard)
FaceCardMenu = connect((store)=>{
return {
faceToLabel: store.faces.faceToLabel,
people: store.people.people,
peopleFetching: store.people.fetching,
personAdding: store.people.adding,
}
})(FaceCardMenu)