Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Lee Stott 2026-07-06 16:08:36 +01:00 committed by GitHub
parent 63b09830a7
commit 7290b98524
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 18 deletions

View File

@ -497,24 +497,17 @@
}
],
"source": [
"import hashlib, os, warnings\n",
"\n",
"# SHA-256 of VGG16 weights (with top) - verify at https://github.com/keras-team/keras\n",
"VGG16_WEIGHTS_SHA256 = \"64373286793e3c8b2b4e3219cbf3544bce2f55ab4682710a29f5e7af8f5e4f61\"\n",
"\n",
"def _sha256(path):\n",
" h = hashlib.sha256()\n",
" with open(path, \"rb\") as f:\n",
" for chunk in iter(lambda: f.read(65536), b\"\"):\n",
" h.update(chunk)\n",
" return h.hexdigest()\n",
"\n",
"vgg = keras.applications.VGG16()\n",
"_weights_path = os.path.join(os.path.expanduser(\"~\"), \".keras\", \"models\",\n",
" \"vgg16_weights_tf_dim_ordering_tf_kernels.h5\")\n",
if _sha256(_weights_path) != VGG16_WEIGHTS_SHA256:
warnings.warn("VGG16 weights SHA-256 mismatch - verify file integrity before use")
raise ValueError("Aborting because VGG16 weights failed integrity check")
"# SHA-256 of VGG16 weights (with top)\n",
"VGG16_WEIGHTS_SHA256 = '64373286793e3c8b2b4e3219cbf3544bce2f55ab4682710a29f5e7af8f5e4f61'\n",
"\n",
"_weights_path = keras.utils.get_file(\n",
" 'vgg16_weights_tf_dim_ordering_tf_kernels.h5',\n",
" 'https://storage.googleapis.com/tensorflow/keras-applications/vgg16/vgg16_weights_tf_dim_ordering_tf_kernels.h5',\n",
" file_hash=VGG16_WEIGHTS_SHA256,\n",
" hash_algorithm='sha256',\n",
")\n",
"\n",
"vgg = keras.applications.VGG16(weights=_weights_path)\n",
"inp = keras.applications.vgg16.preprocess_input(x_sample[:1])\n",
"\n",
"res = vgg(inp)\n",