OSCR

Attentional semantic attack for enhancing adversarial samples transferability.

Code ↔ Paper

3 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 3 matches
  1. [1] § Experiments and analysis › Experimental setup ↔ ASA/test.py, lines 83 to 103 · score 0.60 · Inception Resnet v2, Inception v3, model · Report a mismatch
  2. [2] § Experiments and analysis › Experimental setup ↔ ASA/utils.py, lines 38 to 56 · score 0.60 · Inception Resnet v2, Inception v3, model · Report a mismatch
  3. [3] § Experiments and analysis › Transferability of ASA in different enhancement techniques ↔ ASA/MI_DI_TI.py, lines 42 to 144 · score 0.51 · MI DI TI, Inception, v3, model · Report a mismatch

Paper

Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Python · 184 lines · 9.2 KB · CC-BY-4.0 · 1 match

  1. import os
  2. import cv2
  3. import time
  4. import keras
  5. import argparse
  6. import PIL.Image
  7. import numpy as np
  8. import tensorflow as tf
  9. import prettytable as pt
  10. """
  11. Environment
  12. ! python==3.7.3
  13. ! tensorflow==1.13.1
  14. ! keras==2.2.4
  15. innvestigate==1.0.8
  16. scipy==1.2.1
  17. numpy==1.16.5
  18. pillow==6.2.1
  19. opencv-python==4.1.2
  20. prettytable==0.7.2
  21. argparse==1.4.0
  22. Usage
  23. Command
  24. python test.py [dataset_path] [net_list] [gpu_id]
  25. Test in DAmageNet for VGG19,ResNet50,DenseNet121 in GPU 0:
  26. python test.py ./DAmageNet VGG19,ResNet50,DenseNet121 0
  27. Test in ImageNet validation set for VGG19 in GPU 1:
  28. python test.py ./ILSVRC2012_img_val VGG19 1
  29. Valid networks:
  30. ResNet50, ResNet101, ResNet152, InceptionResNet, InceptionV3, Xception, VGG16, VGG19
  31. DenseNet121, DenseNet169, DenseNet201, NASNetMobile, NASNetLarge
  32. """
  33. def process_sample(sample_path:str, return_size:int):
  34. """
  35. Load the image in np.float32 of [0, 255] as [return_size, return_size, 3]
  36. Image is centrally cropped and resized
  37. """
  38. sample = PIL.Image.open(sample_path).convert('RGB')
  39. size, large_size, index = np.min(sample.size), np.max(sample.size), np.argmin(sample.size)
  40. if index: # long
  41. sample = sample.resize((int(return_size/size*large_size), return_size))
  42. cut_up, cut_down = int((np.max(sample.size) + return_size) / 2), int((np.max(sample.size) - return_size) / 2)
  43. sample = np.array(sample)[:, cut_down:cut_up, :] #sample.size = (a, b) -> np.array(sample).shape = (b, a, 3)
  44. else: # wide
  45. sample = sample.resize((return_size, int(return_size/size*large_size)))
  46. cut_up, cut_down = int((np.max(sample.size) + return_size) / 2), int((np.max(sample.size) - return_size) / 2)
  47. sample = np.array(sample)[cut_down:cut_up, :, :]
  48. sample = cv2.resize(sample, (return_size, return_size))
  49. return np.clip(sample.astype(np.float32), 0, 255)
  50. def crop_or_pad(sample:np.ndarray, size:int):
  51. """
  52. Crop or pad the sample into [size, size, 3] without resizing
  53. The adversarial sample should be processed with this function because resizing decreases their aggression
  54. """
  55. img = PIL.Image.fromarray(sample.astype(np.uint8))
  56. if img.size[0] > size:
  57. img = img.crop(((img.size[0] - size) / 2, (img.size[1] - size) / 2, (img.size[0] + size) / 2, (img.size[1] + size) / 2))
  58. img = img.resize((size, size))
  59. else:
  60. black = PIL.Image.fromarray(np.zeros((size, size, 3), dtype=np.uint8))
  61. black.paste(img, (int((size - img.size[0]) / 2), int((size - img.size[1]) / 2)))
  62. img = black
  63. return np.array(img)
  64. def convert_second_to_time(sec:float):
  65. """
  66. Convert seconds into hour:minute:second
  67. """
  68. m, s = divmod(sec, 60)
  69. h, m = divmod(m, 60)
  70. return "%02d:%02d:%02d" % (h, m, s)
  71. def load_net_info(net_name:str, inp=None):
  72. """
  73. if inp is not None: load the network input size and preprocessing function
  74. else: load the network model and preprocessing function
  75. """
  76. size = {'InceptionV3': 299, 'Xception': 299, 'NASNetLarge': 331}.get(net_name, 224)
  77. if net_name == 'ResNet50': from keras.applications.resnet50 import ResNet50, preprocess_input; net = ResNet50(input_tensor=inp) if inp is not None else size
  78. elif net_name == 'ResNet101': from keras_applications.resnet_v2 import ResNet101V2, preprocess_input; net = ResNet101V2(input_tensor=inp, backend=keras.backend, layers=keras.layers, models=keras.models, utils=keras.utils) if inp is not None else size
  79. elif net_name == 'ResNet152': from keras_applications.resnet_v2 import ResNet152V2, preprocess_input; net = ResNet152V2(input_tensor=inp, backend=keras.backend, layers=keras.layers, models=keras.models, utils=keras.utils) if inp is not None else size
  80. elif net_name == 'InceptionResNetV2': from keras_applications.inception_resnet_v2 import InceptionResNetV2, preprocess_input; net = InceptionResNetV2(input_tensor=inp, backend=keras.backend, layers=keras.layers, models=keras.models, utils=keras.utils) if inp is not None else size
  81. elif net_name == 'InceptionV3': from keras.applications.inception_v3 import InceptionV3, preprocess_input; net = InceptionV3(input_tensor=inp) if inp is not None else size
  82. elif net_name == 'Xception': from keras.applications.xception import Xception, preprocess_input; net = Xception(input_tensor=inp) if inp is not None else size
  83. elif net_name == 'VGG16': from keras.applications.vgg16 import VGG16, preprocess_input; net = VGG16(input_tensor=inp) if inp is not None else size
  84. elif net_name == 'VGG19': from keras.applications.vgg19 import VGG19, preprocess_input; net = VGG19(input_tensor=inp) if inp is not None else size
  85. elif net_name == 'DenseNet121': from keras.applications.densenet import DenseNet121, preprocess_input; net = DenseNet121(input_tensor=inp) if inp is not None else size
  86. elif net_name == 'DenseNet169': from keras.applications.densenet import DenseNet169, preprocess_input; net = DenseNet169(input_tensor=inp) if inp is not None else size
  87. elif net_name == 'DenseNet201': from keras.applications.densenet import DenseNet201, preprocess_input; net = DenseNet201(input_tensor=inp) if inp is not None else size
  88. elif net_name == 'NASNetMobile': from keras.applications.nasnet import NASNetMobile, preprocess_input; net = NASNetMobile(input_tensor=inp)if inp is not None else size
  89. elif net_name == 'NASNetLarge': from keras.applications.nasnet import NASNetLarge, preprocess_input; net = NASNetLarge(input_tensor=inp) if inp is not None else size
  90. else: raise ValueError('Invalid Network Name')
  91. return net, preprocess_input
  92. def build(net_list:list):
  93. """
  94. Build all networks in net_list, return sess and dicts
  95. feed inputs[net_name] with image of size[net_name], run sess, get output[net_name] (None, 1000)
  96. """
  97. sess = tf.InteractiveSession()
  98. inputs, outputs, size = {}, {}, {} # record variables in dict
  99. for n in net_list:
  100. print('Loading', n)
  101. size[n], pre_pro = load_net_info(n) # load size and preprocessing function
  102. inputs[n] = tf.placeholder(tf.float32, [1, size[n], size[n], 3], name=n)
  103. net, _ = load_net_info(n, pre_pro(inputs[n], backend=keras.backend, layers=keras.layers, models=keras.models, utils=keras.utils))
  104. outputs[n] = net.output
  105. return sess, inputs, outputs, size
  106. def get_label(form:str):
  107. """
  108. Load the labels for 50000 samples
  109. """
  110. labels = {}
  111. with open('val.txt', 'r') as f: label_list = f.read().replace('.JPEG', form).split('\n')
  112. for item in label_list:
  113. if item == '': continue
  114. item = item.split(' ')
  115. labels[item[0]] = int(item[1])
  116. return labels
  117. def judge_pred(image_path, net_name, label, sess, inputs, outputs, size):
  118. """
  119. Judge whether the network is wrong
  120. """
  121. image = process_sample(image_path, 224)
  122. prd = np.argmax(sess.run(outputs[net_name], {inputs[net_name]: [crop_or_pad(image, size[net_name])]})[0])
  123. return prd != label
  124. def print_result(log):
  125. """
  126. Print the final results in a table
  127. """
  128. print('\n')
  129. tb = pt.PrettyTable()
  130. tb.field_names = ["Network", "Top-1 Error"]
  131. for net in net_list: tb.add_row([net, '%.2f' % (sum(log[net]) / len(log[net]) * 100) + '%'])
  132. print(tb)
  133. def test(dataset, net_list, **kwargs):
  134. """
  135. Test the error rate of networks in net_list on the samples in dataset
  136. """
  137. labels = get_label(form=os.path.splitext(os.listdir(dataset)[0])[1])
  138. log = {}
  139. for net in net_list: log[net] = []
  140. num_samples = len(os.listdir(dataset))
  141. start = time.time()
  142. print('\nTest', net_list, 'on', dataset, 'for', num_samples, 'samples')
  143. # test each sample
  144. for i, file in enumerate(os.listdir(dataset)):
  145. err_str = ''
  146. for net_name in net_list:
  147. do_error = judge_pred(dataset + '/' + file, net_name, labels[file], **kwargs)
  148. log[net_name].append(do_error)
  149. err_str += '%.2f' % (sum(log[net_name]) / len(log[net_name]) * 100) + '% '
  150. print('[ Sample %d/%d ] [ Error %s ] [ TimeRemain %s ]' %
  151. (i+1, num_samples, err_str, convert_second_to_time((time.time() - start) / (i+1) * (num_samples - i))), end='\r')
  152. print_result(log)
  153. if __name__ == '__main__':
  154. parser = argparse.ArgumentParser(description='Test DAmageNet or ImageNet validation set', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  155. parser.add_argument('dataset', help='Dataset directory, DAmageNet or ILSVRC2012_img_val')
  156. parser.add_argument('net_list', help='all networks to be tested, split with comma but without space')
  157. parser.add_argument('gpu_id', help='GPU(s) used')
  158. args, _ = parser.parse_known_args()
  159. assert os.path.exists(args.dataset) and os.path.exists('val.txt')
  160. os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu_id
  161. net_list = args.net_list.split(',')
  162. net_list.sort() # DenseNets should be loaded first
  163. sess, inputs, outputs, size = build(net_list)
  164. test(args.dataset, net_list, sess=sess, inputs=inputs, outputs=outputs, size=size)

test.py, under CC-BY-4.0 · at the source

Overview

Authors: Pengju Wang1, Jing Liu1
  1. College of Computer Science, Inner Mongolia University,Hohhot, 010010 China
Institutions: Inner Mongolia University (China)
Journal: Scientific reports, volume 16, issue 1, article 10957
Dates: received 5 November 2025; accepted 17 March 2026; published online 26 March 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41598-026-45207-8 · PMID 41888410 · PMCID PMC13039846 · OpenAlex W7140442821
Open access: gold, a free copy (OpenAlex)
Status: code verified (how the code is found and verified)
Categories: cognitive (subfield)
Methods: Connectivity, Preprocessing, Machine learning
Keywords: Adversarial attack, Transferability, Attentional perturbation, Mathematics and computing, Neuroscience
Topic: Adversarial Robustness in Machine Learning (Artificial Intelligence, Computer Science), according to OpenAlex
Funding: Inner Mongolia Key R&D and Achievement Transformation Project (No.2025YFDZ0029); Natural Science Foundation of China (No.62462047); Natural Science Foundation of Inner Mongolia of China (No.2023ZD18)
Citations: not cited yet (Europe PMC); 50 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repositories

Its files are read in the Code ↔ Paper reader above, with 3 matches between paragraphs and lines of code.

mercy0216/asa

License: none: the authors keep all their rights
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: cd2c6cb4d365521233edc0dab87b8341a7c60ced, 23 October 2025
Size: 1 file, 0 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README
Not found: license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
1 file

Zenodo 18979330

License: CC-BY-4.0
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: “Code availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (22 files), TensorFlow (18 files), Keras (17 files), SciPy (8 files), OpenCV (7 files), Pillow (7 files), Matplotlib (4 files), scikit-image (2 files)
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
  • 30 September 2026: the link answers (HTTP 200)
24 files

Code availability statement

The paper has a code availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41598-026-45207-8.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 24 scripts, each with its path and the digest of its content;
  • 3 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data availability statement

The paper has a data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

  • it says that the data are available on request

Read it in the paper: doi.org/10.1038/s41598-026-45207-8.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 2 authors, 5 keywords, 3 funders, 7 references.

Cite

This paper

Wang, P., & Liu, J. (2026). Attentional semantic attack for enhancing adversarial samples transferability. Scientific reports, 16(1), 10957. https://doi.org/10.1038/s41598-026-45207-8

BibTeX

@article{wang2026attentional,
author = {Wang, Pengju and Liu, Jing},
title = {{Attentional semantic attack for enhancing adversarial samples transferability}},
journal = {Scientific reports},
year = {2026},
month = mar,
volume = {16},
number = {1},
pages = {10957},
publisher = {Nature Publishing Group},
issn = {2045-2322},
doi = {10.1038/s41598-026-45207-8},
url = {https://doi.org/10.1038/s41598-026-45207-8},
pmid = {41888410},
pmcid = {PMC13039846}
}

RIS

TY - JOUR
AU - Wang, Pengju
AU - Liu, Jing
TI - Attentional semantic attack for enhancing adversarial samples transferability
T2 - Scientific reports
J2 - Sci Rep
PY - 2026
DA - 2026/03/26
VL - 16
IS - 1
SP - 10957
SN - 2045-2322
PB - Nature Publishing Group
DO - 10.1038/s41598-026-45207-8
UR - https://doi.org/10.1038/s41598-026-45207-8
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41598-026-45207-8",
"type": "article-journal",
"title": "Attentional semantic attack for enhancing adversarial samples transferability",
"container-title": "Scientific reports",
"author": [
{
"family": "Wang",
"given": "Pengju"
},
{
"family": "Liu",
"given": "Jing"
}
],
"container-title-short": "Sci Rep",
"volume": "16",
"issue": "1",
"page": "10957",
"DOI": "10.1038/s41598-026-45207-8",
"PMID": "41888410",
"PMCID": "PMC13039846",
"ISSN": "2045-2322",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41598-026-45207-8",
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
26
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-024-45679-0 [code]
Improved modeling of human vision by incorporating robustness to blur in convolutional neural networks.
Journal: Nature communications
In common: Keras, OpenCV, TensorFlow, 5 other tools, 1 reference
[2] doi:10.3389/frai.2022.903875 [code]
Benchmarking Perturbation-Based Saliency Maps for Explaining Atari Agents.
Journal: Frontiers in artificial intelligence
In common: Keras, OpenCV, TensorFlow, 5 other tools, 1 reference
[3] doi:10.3390/s24041143 [code]
NeoSLAM: Long-Term SLAM Using Computational Models of the Brain.
Journal: Sensors (Basel, Switzerland)
In common: Keras, OpenCV, TensorFlow, 5 other tools, 1 reference
[4] doi:10.1038/s41746-024-01123-7 [code]
Constructing personalized characterizations of structural brain aberrations in patients with dementia using explainable artificial intelligence.
Journal: NPJ digital medicine
In common: Keras, TensorFlow, scikit-image, 4 other tools, 1 reference
[5] doi:10.1523/eneuro.0352-23.2024 [code]
A Semi-supervised Pipeline for Accurate Neuron Segmentation with Fewer Ground Truth Labels.
Journal: eNeuro
In common: Keras, OpenCV, TensorFlow, 4 other tools, 1 reference
[6] doi:10.1038/s41598-023-42891-8 [code]
Natural scene reconstruction from fMRI signals using generative latent diffusion.
Journal: Scientific reports
In common: OpenCV, TensorFlow, scikit-image, 4 other tools, 1 reference
[7] doi:10.7717/peerj-cs.1667 [code]
Next-Gen brain tumor classification: pioneering with deep learning and fine-tuned conditional generative adversarial networks.
Journal: PeerJ. Computer science
In common: Keras, OpenCV, TensorFlow, 3 other tools, 1 reference
[8] doi:10.1162/imag.a.1164 [code]
Bias and generalizability of brain age prediction models: A multi-cohort evaluation with anatomical and interpretability insights.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: Keras, TensorFlow, Pillow, 3 other tools, 1 reference
[9] doi:10.1007/s10994-024-06574-3 [code]
XAI-TRIS: non-linear image benchmarks to quantify false positive post-hoc attribution of feature importance.
Journal: Machine learning
In common: Keras, TensorFlow, Pillow, 3 other tools, 1 reference
[10] doi:10.3390/diagnostics13243604 [code]
Deep Learning-Based Extraction of Biomarkers for the Prediction of the Functional Outcome of Ischemic Stroke Patients.
Journal: Diagnostics (Basel, Switzerland)
In common: Keras, OpenCV, TensorFlow, 3 other tools, 1 reference

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Add the badge to the code's README

OSCR: the badge of this paper

If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.

Markdown
<!-- oscr-badge:start -->
[![OSCR](https://openscicode.org/badge/doi/10.1038/s41598-026-45207-8.svg)](https://openscicode.org/badge/doi/10.1038/s41598-026-45207-8)
<!-- oscr-badge:end -->
reStructuredText
.. oscr-badge:start

.. image:: https://openscicode.org/badge/doi/10.1038/s41598-026-45207-8.svg
   :target: https://openscicode.org/badge/doi/10.1038/s41598-026-45207-8
   :alt: OSCR

.. oscr-badge:end
HTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1038/s41598-026-45207-8"><img src="https://openscicode.org/badge/doi/10.1038/s41598-026-45207-8.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->

On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".

If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.

Report a mismatch between the code and the paper · Report a code error (signed in)

Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.

Report a reproduction failure (signed in)

Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.