Skip to content

Commit

Permalink
improved FES job logging and fixed missing README links
Browse files Browse the repository at this point in the history
  • Loading branch information
faberf committed May 17, 2024
1 parent 5b1920c commit 635eb9c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ which requires the parameter `host` with an endpoint as value.

For analysers that require a running [Feature Extraction Server](https://github.com/faberf/feature-extraction-server) (FES), the `host` parameter is required. Additionally, the `model` parameter may be used to specify a non-default model which should execute the task. Of course, this requires that the FES has the necessary plugins installed. See the [FES documentation](https://github.com/faberf/feature-extraction-server) for more information.

- For [`ASR`] the analyser will perform automatic speech recognition on the audio content.
- For [`OCR`] the analyser will perform optical character recognition on the image content.
- For [`DenseEmbedding`] the analyser will embed text / images as float vectors. Additionally, the `length` parameter is required to specify the length of the embedding.
- For [`ImageCaption`] the analyser will generate a caption for the image content. Optionally, a `prompt` parameter can be used to specify a prompt for the caption generation. For example, the prompt could have the form `"Question: What is in the image? Answer:"`.
- For [`ImageClassification`] the analyser will classify the image content. Additionally, the `classes` parameter is required, which should contain the classes to classify the image into, separated by commas. Optionally, the `top_k` and `threshold` parameters can be used to specify the number of top classes to return and the threshold for the classification.
- For [`ASR`](/vitrivr-engine-module-fes/src/main/kotlin/org/vitrivr/engine/base/features/external/implementations/ASR.kt) the analyser will perform automatic speech recognition on the audio content.
- For [`OCR`](/vitrivr-engine-module-fes/src/main/kotlin/org/vitrivr/engine/base/features/external/implementations/OCR.kt) the analyser will perform optical character recognition on the image content.
- For [`DenseEmbedding`](/vitrivr-engine-module-fes/src/main/kotlin/org/vitrivr/engine/base/features/external/implementations/DenseEmbedding.kt) the analyser will embed text / images as float vectors. Additionally, the `length` parameter is required to specify the length of the embedding.
- For [`ImageCaption`](/vitrivr-engine-module-fes/src/main/kotlin/org/vitrivr/engine/base/features/external/implementations/ImageCaption.kt) the analyser will generate a caption for the image content. Optionally, a `prompt` parameter can be used to specify a prompt for the caption generation. For example, the prompt could have the form `"Question: What is in the image? Answer:"`.
- For [`ImageClassification`](/vitrivr-engine-module-fes/src/main/kotlin/org/vitrivr/engine/base/features/external/implementations/ImageClassification.kt) the analyser will classify the image content. Additionally, the `classes` parameter is required, which should contain the classes to classify the image into, separated by commas. Optionally, the `top_k` and `threshold` parameters can be used to specify the number of top classes to return and the threshold for the classification.


Other fields are for (technical) metadata such as the [`FileSourceMetadata`](/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/features/metadata/source/file/FileSourceMetadata.kt),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,33 @@ internal data class JobResult<S>(
internal class JobWrapper<T, S>(
private val startJobFunc: (T) -> JobStatus,
private val getJobResultFunc: (String) -> JobResult<S>,
private val pollingIntervalMs: Long
private val pollingIntervalMs: Long,
private val hostName: String
){

fun executeJob(inp: T): S {
val jobStatus: JobStatus
try{
jobStatus = startJobFunc(inp)
} catch (e: SocketTimeoutException) {
logger.error { "Failed to start Job: API call timed out." }
logger.error { "Failed to start Job on Host $hostName: API call timed out." }
throw e
}
var jobResult = getJobResultFunc(jobStatus.id)

while (jobResult.status != JobState.complete) {
if (jobResult.status == JobState.failed) {
logger.error{"Job with ID: ${jobStatus.id} failed."}
logger.error{"Job on Host $hostName with ID: ${jobStatus.id} failed."}
throw Exception("Job failed.")
}
logger.debug{"Waiting for job completion. Current status: ${jobResult.status}"}
logger.debug{"Waiting for job completion on Host $hostName. Current status: ${jobResult.status}"}
Thread.sleep(this.pollingIntervalMs)
jobResult = getJobResultFunc(jobStatus.id)
}

return jobResult.result ?: run {
logger.error{"Job with ID: ${jobStatus.id} returned no result."}
throw Exception("Job returned no result.")
logger.error{"Job on Host $hostName with ID: ${jobStatus.id} returned no result."}
throw Exception("Job on Host $hostName returned no result.")
}
}
}
Expand Down Expand Up @@ -93,7 +94,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName,
)

return job.executeJob(input).embedding.map{it.toFloat()}.also{
Expand All @@ -118,7 +120,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).map { it.embedding.map{it.toFloat()} }.also {
logger.info{ "Batched text embedding result: $it" }
Expand All @@ -142,7 +145,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).embedding.map{it.toFloat()}.also {
logger.info{ "Image embedding result: $it" }
Expand All @@ -166,7 +170,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).map { it.embedding.map{it.toFloat()}}.also {
logger.info{ "Batched image embedding result: $it" }
Expand All @@ -190,7 +195,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).caption.also {
logger.info{ "Image captioning result: $it" }
Expand All @@ -214,7 +220,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).map { it.caption }.also {
logger.info{ "Batched image captioning result: $it" }
Expand All @@ -239,7 +246,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).probabilities.map{it.toFloat()}.also {
logger.info{ "Zero shot image classification result: $it" }
Expand All @@ -264,7 +272,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).map { it.probabilities.map{it.toFloat()}}.also {
logger.info{ "Batched zero shot image classification result: $it" }
Expand All @@ -289,7 +298,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).caption.also {
logger.info{ "Conditional image captioning result: $it" }
Expand All @@ -314,7 +324,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).map { it.caption }.also {
logger.info{ "Batched conditional image captioning result: $it" }
Expand All @@ -338,7 +349,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).embedding.map{it.toFloat()}.also {
logger.info{ "Face embedding result: $it" }
Expand All @@ -362,7 +374,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).map { it.embedding.map{it.toFloat()}}.also {
logger.info{ "Batched face embedding result: $it" }
Expand All @@ -386,7 +399,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).also {
logger.info{ "Object detection result: $it" }
Expand All @@ -410,7 +424,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).also {
logger.info{ "Batched object detection result: $it" }
Expand All @@ -434,7 +449,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).transcript.also {
logger.info{ "Automated speech recognition result: $it" }
Expand All @@ -458,7 +474,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).map { it.transcript }.also {
logger.info{ "Batched automated speech recognition result: $it" }
Expand All @@ -484,7 +501,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).text.also {
logger.info{ "Optical character recognition result: $it" }
Expand All @@ -508,7 +526,8 @@ class ApiWrapper(private val hostName:String, private val model: String, private
JobResult(it.status, it.result)
}
},
pollingIntervalMs = pollingIntervalMs
pollingIntervalMs = pollingIntervalMs,
hostName = hostName
)
return job.executeJob(input).map { it.text }.also {
logger.info{ "Batched optical character recognition result: $it" }
Expand Down

0 comments on commit 635eb9c

Please sign in to comment.