Obtain the NSFWQI model: You'll need to start with the NSFWQI model since it is pre-trained (can acquire this from the Yahoo Open NSFW project).
Prepare your dataset: The dataset should contain a collection of the images that you want to evaluate for NSFW content. One thing to make sure of is that your images are in a format that can be processed by the NSFWQI model. I'd also recommend using some form of image compression tool that reduces the image size so the model doesn't become too large.
Predict probability: Use the NSFWQI model to predict the NSFW probability of each image in your dataset individually. This can be accomplished by passing each image through the NSFWQI model and obtaining the predicted NSFW probability. You'll need to determine which NSFW probability is necessary for your purposes.
Calculate the Q value: Once you have obtained the NSFW probability for each image in your dataset, you can calculate the Q value by:
a. Sorting the NSFW probabilities in descending order
b. Plotting the sorted probabilities on a graph
c. Calculate the area under the curve (AUC) of the plot using a numerical integration method (i.e., the trapezoidal rule)
d. The Q value is given by Q = 1 - AUC (which is why it is critical to correctly calculate the AUC)
Note: Calculating the Q value is going to be much easier to do computationally than "by hand".
If needed, you can also plot the Q graph which can be accomplished by plotting the NSFW probabilities on the x-axis and the cumulative percentage of images on the y-axis. The Q graph is obtained by plotting the Q value as a function of the percentage of images included in the dataset (direct relationship).