Attentional semantic attack for enhancing adversarial samples transferability.
The 3 matches
- [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] § 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] § 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
- import os
- import cv2
- import time
- import keras
- import argparse
- import PIL.Image
- import numpy as np
- import tensorflow as tf
- import prettytable as pt
- """
- Environment
- ! python==3.7.3
- ! tensorflow==1.13.1
- ! keras==2.2.4
- innvestigate==1.0.8
- scipy==1.2.1
- numpy==1.16.5
- pillow==6.2.1
- opencv-python==4.1.2
- prettytable==0.7.2
- argparse==1.4.0
- Usage
- Command
- python test.py [dataset_path] [net_list] [gpu_id]
- Test in DAmageNet for VGG19,ResNet50,DenseNet121 in GPU 0:
- python test.py ./DAmageNet VGG19,ResNet50,DenseNet121 0
- Test in ImageNet validation set for VGG19 in GPU 1:
- python test.py ./ILSVRC2012_img_val VGG19 1
- Valid networks:
- ResNet50, ResNet101, ResNet152, InceptionResNet, InceptionV3, Xception, VGG16, VGG19
- DenseNet121, DenseNet169, DenseNet201, NASNetMobile, NASNetLarge
- """
- def process_sample(sample_path:str, return_size:int):
- """
- Load the image in np.float32 of [0, 255] as [return_size, return_size, 3]
- Image is centrally cropped and resized
- """
- sample = PIL.Image.open(sample_path).convert('RGB')
- size, large_size, index = np.min(sample.size), np.max(sample.size), np.argmin(sample.size)
- if index: # long
- sample = sample.resize((int(return_size/size*large_size), return_size))
- cut_up, cut_down = int((np.max(sample.size) + return_size) / 2), int((np.max(sample.size) - return_size) / 2)
- sample = np.array(sample)[:, cut_down:cut_up, :] #sample.size = (a, b) -> np.array(sample).shape = (b, a, 3)
- else: # wide
- sample = sample.resize((return_size, int(return_size/size*large_size)))
- cut_up, cut_down = int((np.max(sample.size) + return_size) / 2), int((np.max(sample.size) - return_size) / 2)
- sample = np.array(sample)[cut_down:cut_up, :, :]
- sample = cv2.resize(sample, (return_size, return_size))
- return np.clip(sample.astype(np.float32), 0, 255)
- def crop_or_pad(sample:np.ndarray, size:int):
- """
- Crop or pad the sample into [size, size, 3] without resizing
- The adversarial sample should be processed with this function because resizing decreases their aggression
- """
- img = PIL.Image.fromarray(sample.astype(np.uint8))
- if img.size[0] > size:
- img = img.crop(((img.size[0] - size) / 2, (img.size[1] - size) / 2, (img.size[0] + size) / 2, (img.size[1] + size) / 2))
- img = img.resize((size, size))
- else:
- black = PIL.Image.fromarray(np.zeros((size, size, 3), dtype=np.uint8))
- black.paste(img, (int((size - img.size[0]) / 2), int((size - img.size[1]) / 2)))
- img = black
- return np.array(img)
- def convert_second_to_time(sec:float):
- """
- Convert seconds into hour:minute:second
- """
- m, s = divmod(sec, 60)
- h, m = divmod(m, 60)
- return "%02d:%02d:%02d" % (h, m, s)
- def load_net_info(net_name:str, inp=None):
- """
- if inp is not None: load the network input size and preprocessing function
- else: load the network model and preprocessing function
- """
- size = {'InceptionV3': 299, 'Xception': 299, 'NASNetLarge': 331}.get(net_name, 224)
- if net_name == 'ResNet50': from keras.applications.resnet50 import ResNet50, preprocess_input; net = ResNet50(input_tensor=inp) if inp is not None else size
- 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
- 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
- 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
- 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
- elif net_name == 'Xception': from keras.applications.xception import Xception, preprocess_input; net = Xception(input_tensor=inp) if inp is not None else size
- elif net_name == 'VGG16': from keras.applications.vgg16 import VGG16, preprocess_input; net = VGG16(input_tensor=inp) if inp is not None else size
- elif net_name == 'VGG19': from keras.applications.vgg19 import VGG19, preprocess_input; net = VGG19(input_tensor=inp) if inp is not None else size
- elif net_name == 'DenseNet121': from keras.applications.densenet import DenseNet121, preprocess_input; net = DenseNet121(input_tensor=inp) if inp is not None else size
- elif net_name == 'DenseNet169': from keras.applications.densenet import DenseNet169, preprocess_input; net = DenseNet169(input_tensor=inp) if inp is not None else size
- elif net_name == 'DenseNet201': from keras.applications.densenet import DenseNet201, preprocess_input; net = DenseNet201(input_tensor=inp) if inp is not None else size
- elif net_name == 'NASNetMobile': from keras.applications.nasnet import NASNetMobile, preprocess_input; net = NASNetMobile(input_tensor=inp)if inp is not None else size
- elif net_name == 'NASNetLarge': from keras.applications.nasnet import NASNetLarge, preprocess_input; net = NASNetLarge(input_tensor=inp) if inp is not None else size
- else: raise ValueError('Invalid Network Name')
- return net, preprocess_input
- def build(net_list:list):
- """
- Build all networks in net_list, return sess and dicts
- feed inputs[net_name] with image of size[net_name], run sess, get output[net_name] (None, 1000)
- """
- sess = tf.InteractiveSession()
- inputs, outputs, size = {}, {}, {} # record variables in dict
- for n in net_list:
- print('Loading', n)
- size[n], pre_pro = load_net_info(n) # load size and preprocessing function
- inputs[n] = tf.placeholder(tf.float32, [1, size[n], size[n], 3], name=n)
- net, _ = load_net_info(n, pre_pro(inputs[n], backend=keras.backend, layers=keras.layers, models=keras.models, utils=keras.utils))
- outputs[n] = net.output
- return sess, inputs, outputs, size
- def get_label(form:str):
- """
- Load the labels for 50000 samples
- """
- labels = {}
- with open('val.txt', 'r') as f: label_list = f.read().replace('.JPEG', form).split('\n')
- for item in label_list:
- if item == '': continue
- item = item.split(' ')
- labels[item[0]] = int(item[1])
- return labels
- def judge_pred(image_path, net_name, label, sess, inputs, outputs, size):
- """
- Judge whether the network is wrong
- """
- image = process_sample(image_path, 224)
- prd = np.argmax(sess.run(outputs[net_name], {inputs[net_name]: [crop_or_pad(image, size[net_name])]})[0])
- return prd != label
- def print_result(log):
- """
- Print the final results in a table
- """
- print('\n')
- tb = pt.PrettyTable()
- tb.field_names = ["Network", "Top-1 Error"]
- for net in net_list: tb.add_row([net, '%.2f' % (sum(log[net]) / len(log[net]) * 100) + '%'])
- print(tb)
- def test(dataset, net_list, **kwargs):
- """
- Test the error rate of networks in net_list on the samples in dataset
- """
- labels = get_label(form=os.path.splitext(os.listdir(dataset)[0])[1])
- log = {}
- for net in net_list: log[net] = []
- num_samples = len(os.listdir(dataset))
- start = time.time()
- print('\nTest', net_list, 'on', dataset, 'for', num_samples, 'samples')
- # test each sample
- for i, file in enumerate(os.listdir(dataset)):
- err_str = ''
- for net_name in net_list:
- do_error = judge_pred(dataset + '/' + file, net_name, labels[file], **kwargs)
- log[net_name].append(do_error)
- err_str += '%.2f' % (sum(log[net_name]) / len(log[net_name]) * 100) + '% '
- print('[ Sample %d/%d ] [ Error %s ] [ TimeRemain %s ]' %
- (i+1, num_samples, err_str, convert_second_to_time((time.time() - start) / (i+1) * (num_samples - i))), end='\r')
- print_result(log)
- if __name__ == '__main__':
- parser = argparse.ArgumentParser(description='Test DAmageNet or ImageNet validation set', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
- parser.add_argument('dataset', help='Dataset directory, DAmageNet or ILSVRC2012_img_val')
- parser.add_argument('net_list', help='all networks to be tested, split with comma but without space')
- parser.add_argument('gpu_id', help='GPU(s) used')
- args, _ = parser.parse_known_args()
- assert os.path.exists(args.dataset) and os.path.exists('val.txt')
- os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu_id
- net_list = args.net_list.split(',')
- net_list.sort() # DenseNets should be loaded first
- sess, inputs, outputs, size = build(net_list)
- test(args.dataset, net_list, sess=sess, inputs=inputs, outputs=outputs, size=size)
test.py, under CC-BY-4.0 · at the source
Overview
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
cd2c6cb4d365521233edc0dab87b8341a7c60ced, 23 October 2025Availability: 1 check, the latest on 30 September 2026: the link answers
- 30 September 2026: the link answers
1 file
- README.md, Text, 2 lines
Zenodo 18979330
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
- 30 September 2026: the link answers (HTTP 200)
24 files
- ASA/
ASA.py , Python, 113 lines - ASA/
DI.py , Python, 143 lines - ASA/
DI_TI.py , Python, 157 lines - ASA/
FASM.py , Python, 113 lines - ASA/
L.py , Python, 59 lines - ASA/
MI.py , Python, 117 lines - ASA/
MI_DI.py , Python, 143 lines - ASA/
MI_DI_TI.py , Python, 149 lines, 1 match - ASA/
MI_TI.py , Python, 132 lines - ASA/
TI.py , Python, 129 lines - ASA/
base.py , Python, 828 lines - ASA/
cos.py , Python, 49 lines - ASA/
haetmap.py , Python, 136 lines - ASA/
image_reshape.py , Python, 31 lines - ASA/
interpreters.py , Python, 351 lines - ASA/
lrp.py , Python, 119 lines - ASA/
manymodel.py , Python, 199 lines - ASA/
mi_di_ti_manymodel.py , Python, 232 lines - ASA/
rmse.py , Python, 85 lines - ASA/
ssim.py , Python, 77 lines - ASA/
ssim_new.py , Python, 54 lines - ASA/
test.py , Python, 184 lines, 1 match - ASA/
transfers.py , Python, 49 lines - ASA/
utils.py , Python, 171 lines, 1 match
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:
- it points to the authors' code: mercy0216/
asa , Zenodo 18979330
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://
BibTeX
@article{wang2026attenti
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/
url = {https://
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/
VL - 16
IS - 1
SP - 10957
SN - 2045-2322
PB - Nature Publishing Group
DO - 10.1038/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1038/
"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":
"volume": "16",
"issue": "1",
"page": "10957",
"DOI": "10.1038/
"PMID": "41888410",
"PMCID": "PMC13039846",
"ISSN": "2045-2322",
"publisher": "Nature Publishing Group",
"URL": "https://
"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 communicationsIn 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 intelligenceIn 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 medicineIn 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: eNeuroIn 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 reportsIn 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 scienceIn 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 learningIn 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.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 2 repositories of the authors' code, each at its verified commit and with its license, 24 scripts, and 3 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:d8108be8f62038a7…
Add the badge to the code's README
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 -->
[](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:endHTML
<!-- 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.
