《深度学习基础》TensorFlow脚本导入read_data模块报错求助
ModuleNotFoundError: No module named 'read_data' Issue Hey there! Let's tackle this problem you're facing with the TensorFlow script from Fundamentals of Deep Learning by Nikhil Buduma.
First off, the read_data module isn't a built-in part of TensorFlow or standard Python libraries—this is almost certainly a custom helper module the author created for the book's examples, meant to handle tasks like loading datasets or generating minibatches (which ties into the get_minibatch function you already adjusted).
Here are your best options to resolve this:
- Grab the book's official companion code: Most technical books host their example code on a repository (like GitHub). Look for the book's official codebase—you'll find the
read_data.pyfile there. Once you have it, place it in the same directory as your running script, or add its folder path to Python'ssys.pathso your script can locate it. - Implement the functionality yourself: If you can't find the official code, you can recreate the key parts. Since you're working with
get_minibatch, this function likely pulls small batches of data from a dataset. Depending on the dataset you're using (e.g., MNIST), you can use TensorFlow's native tools liketf.data.Datasetto handle batching, or write a simple function to split your data into minibatches manually. - Double-check for typos: It's easy to misspell module names—double-check the book's code example to make sure you're referencing the module exactly as written (e.g., is it
read_dataor something likeread_data_utils?).
Also, quick note: You were right to remove the empty parentheses from get_minibatch! If the script was passing the function as a parameter (common in TensorFlow workflows), adding parentheses would execute the function immediately instead of passing the function itself, which would cause an error. Good catch there.
内容的提问来源于stack exchange,提问作者DarkHark

