# C2W1\_Unable to split data

**URL:** <https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041>\
**Category:** Convolutional Neural Networks in TensorFlow\
**Tags:** week-module-1\
**Created:** [February 17, 2024, 7:59am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041 "2024-02-17T07:59:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![omsundaram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/omsundaram/32/80876_2.png) [@omsundaram](https://community.deeplearning.ai/u/omsundaram)\
**Post date:** [February 17, 2024, 7:59am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/1 "2024-02-17T07:59:06Z")

</div>

Hi all,  
@Deepti_Prasad  
@balaji.ambresh  
@gent.spah

I’m trying to execute C2W1 assignment but I’m unable to split the data, it gives attached error

 ![image](https://global.discourse-cdn.com/dlai/original/3X/0/7/07eb1a9b37e70740ea92f7e7f08f4480dd82f623.png)

I think this could be the reason due to Source file is not copied to the destination file.

Appreciate any assistance pls as I’m trying since yesterday but unable to crack this…

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [February 17, 2024, 8:34am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/2 "2024-02-17T08:34:43Z")

</div>

This error happens when a you call a function inside a function like split\_data(split\_size(split\_size))…

Make sure you read the instructions before the grader cell correctly .

Regards  
DP

---

<div class="post-metadata">

**Author:** ![omsundaram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/omsundaram/32/80876_2.png) [@omsundaram](https://community.deeplearning.ai/u/omsundaram)\
**Post date:** [February 17, 2024, 8:52am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/3 "2024-02-17T08:52:10Z")

</div>

@Deepti_Prasad , Thank you for the response…

I tried couple of things, but now I get below error

 ![image](https://global.discourse-cdn.com/dlai/original/3X/8/c/8c07e6f4a1c5c704561e81cb6b4a84129ee82c19.png)

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [February 17, 2024, 8:58am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/4 "2024-02-17T08:58:53Z")

</div>

This indicates you have recalled the directory path incorrectly. go to back to first grader cell. Use search tool, you can refer the below comment, it will help you understand on how to write the codes for directory cell as well as split data

> [@C2W1\_Assignment\_Cats vs Dogs](https://community.deeplearning.ai/t/c2w1-assignment-cats-vs-dogs/419029/5):
>
> Hello Viktor, Thank you for sharing the screenshot of your error. based on your screenshot your this grader cell has incorrect code As explained in the previous shared link in this post where it explains according to the hint given please follow these step to make the corrections Hints tells you to use os.makedirs to create your intermediate subdirectories not direct directories for your root path. So as I already have mentioned your first line of c…

Let me know if you are unable to understand anything.

Regards  
DP

---

<div class="post-metadata">

**Author:** ![omsundaram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/omsundaram/32/80876_2.png) [@omsundaram](https://community.deeplearning.ai/u/omsundaram)\
**Post date:** [February 17, 2024, 9:05am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/5 "2024-02-17T09:05:31Z")

</div>

@Deepti_Prasad

Thanks for the detailed explanation, I think i’m stuck at this place

" the split data grader cell first wants you to create a source\_directory which is mentioned as SOURCE\_DIR "

i have written as below for SOURCE\_DIR. Is this correct?  
‘/tmp/PetImages’

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [February 17, 2024, 9:08am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/6 "2024-02-17T09:08:53Z")

</div>

No your source directory path is incorrectly recalled. read the instructions in the comments. Use search tool in the discourse community where learners have faced similar issue and a response has been given. that way you will learn more.

there is error in the splitting of data also but the first main error is how you have recalled your directory path, so it is giving source dir error.

Regards  
DP

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [February 17, 2024, 10:29am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/7 "2024-02-17T10:29:05Z")

</div>

2 things to remember:

1. `create_train_val_dirs` is used for setting up the folder structure.
2. `split_data` is responsible ONLY for copying the images in `SOURCE_DIR` into `TRAINING_DIR` and `VALIDATION_DIR`.

`os.remove` will raise `OSError` if you attempt to remove a directory. Consider using `os.rmdir` or `shutil.rmtree` for removing directories (not required in this step of the assignment).

The staff have provided support code to run `split_data` multiple times (see this comment: `# Empty directories in case you run this cell multiple times `). You don’t need to worry about cleaning the destination directories before splitting files.

---

<div class="post-metadata">

**Author:** ![omsundaram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/omsundaram/32/80876_2.png) [@omsundaram](https://community.deeplearning.ai/u/omsundaram)\
**Post date:** [February 18, 2024, 1:36am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/8 "2024-02-18T01:36:34Z")

</div>

Hi all, thanks for the guidance…  
I’m still unable to get the right source path…appreciate if someone can assist with this pls.

 ![image](https://global.discourse-cdn.com/dlai/original/3X/2/5/2525fcf5d24a31d2b57376cc9f4ad3f5d8e484eb.png)

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [February 18, 2024, 3:56am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/9 "2024-02-18T03:56:31Z")

</div>

See the proper variable name below:

> [@balaji.ambresh](#):
>
> SOURCE\_DIR

Please get familiar with python before moving forward. Happy learning.

---

<div class="post-metadata">

**Author:** ![omsundaram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/omsundaram/32/80876_2.png) [@omsundaram](https://community.deeplearning.ai/u/omsundaram)\
**Post date:** [February 18, 2024, 5:13am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/10 "2024-02-18T05:13:57Z")

</div>

Hi @balaji.ambresh  
Thank you for your response.  
Any course you will recommend me to enhance my further python skill?

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [February 18, 2024, 6:30am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/11 "2024-02-18T06:30:53Z")

</div>

There are about a hundred good Python tutorial courses on YouTube.  
Pick one that has a lot of views. That’s a good indicator it is highly useful.

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [February 18, 2024, 8:41am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/12 "2024-02-18T08:41:30Z")

</div>

Om my previous comment has clear instructions on how to write the source \_dir.

If you read that comments point by point, you would be able to do the corrections.

As far as improving python skills, I can tell you I myself I am still learning as I am not from programming background, so doing a course plus working on many self learning project from kaggle or your local jupyter notebook will surely help you improve. You could also take guidance from @rmwkwok who has a shared a journey of learning by himself through research and improving day by day.

Python course will surely help you but the more you practice, more you get better.

You can send your notebook if you are still stuck.

Regards  
DP

---

<div class="post-metadata">

**Author:** ![omsundaram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/omsundaram/32/80876_2.png) [@omsundaram](https://community.deeplearning.ai/u/omsundaram)\
**Post date:** [February 19, 2024, 3:54am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/13 "2024-02-19T03:54:01Z")

</div>

Hi @Deepti_Prasad , thank you for the response dear!

Indeed my background is not from programming and this makes learning bit challenging. I’m trying to learn by practices : )

I’m also stuck at the source part since 3 days, I wanted to share my notebook but as I’m using company laptop I can’t access my google drive and will be unable to share. Sharing screenshot can work but that will be against community guidelines. Please let me know if I can DM you?

As per my current coding I’m getting below output which means data is not copied to subdirectories and folders are empty… this could be due to Source\_dir defined/path is not correct

![image](https://global.discourse-cdn.com/dlai/original/3X/6/4/64f03c6bb8ea9333553255256c1a0aa3ee83f5e1.png)

Kind regrads,  
Om

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [February 19, 2024, 5:08am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/14 "2024-02-19T05:08:06Z")

</div>

Ok send screenshot via DM for the starting two grader cells

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [February 19, 2024, 7:44am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/15 "2024-02-19T07:44:55Z")

</div>

You need to read all the instructions in the grader cell and before the grader cell carefully.

then the comment I have shared

> [@C2W1\_Assignment\_Cats vs Dogs](https://community.deeplearning.ai/t/c2w1-assignment-cats-vs-dogs/419029/5):
>
> Hello Viktor, Thank you for sharing the screenshot of your error. based on your screenshot your this grader cell has incorrect code As explained in the previous shared link in this post where it explains according to the hint given please follow these step to make the corrections Hints tells you to use os.makedirs to create your intermediate subdirectories not direct directories for your root path. So as I already have mentioned your first line of c…

Literally explains each codes line by line.

using only os.makedir for creating your directory is totally incorrect. The instruction in the grader cell clearly indicates you to use root path which you are ignoring in your codes.

So with a totally fresh copy start again. stop referring to the codes you wrote because it is incorrect.

Regards  
DP

---

<div class="post-metadata">

**Author:** ![omsundaram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/omsundaram/32/80876_2.png) [@omsundaram](https://community.deeplearning.ai/u/omsundaram)\
**Post date:** [February 19, 2024, 9:37am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/16 "2024-02-19T09:37:13Z")

</div>

Hi @Deepti_Prasad ,

I’m still unable to understand, if my code was incorrect why my below output is correct

![image](https://global.discourse-cdn.com/dlai/original/3X/1/a/1af93753ea40006e1b90bfa6f366154219be2638.png)

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [February 19, 2024, 9:42am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/17 "2024-02-19T09:42:23Z")

</div>

it is surely creating the directory you are writing codes for but it is not creating the path or images it is looking for

you would get further down the road error even if the grader cell has passed in the previous cell

---

<div class="post-metadata">

**Author:** ![omsundaram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/omsundaram/32/80876_2.png) [@omsundaram](https://community.deeplearning.ai/u/omsundaram)\
**Post date:** [February 20, 2024, 4:57am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/18 "2024-02-20T04:57:29Z")

</div>

Hi @Deepti_Prasad , pls advise how to correct this? I followed your code guidance but still unable to make any progress…

---

<div class="post-metadata">

**Author:** ![omsundaram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/omsundaram/32/80876_2.png) [@omsundaram](https://community.deeplearning.ai/u/omsundaram)\
**Post date:** [February 21, 2024, 3:03am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/19 "2024-02-21T03:03:24Z")

</div>

Hi all, appreciate if someone can guide me further on this as i’m stuck on this since last week…

---

<div class="post-metadata">

**Author:** ![saifkhanengr](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/saifkhanengr/32/152858_2.png) [@saifkhanengr](https://community.deeplearning.ai/u/saifkhanengr)\
**Post date:** [February 21, 2024, 7:21am UTC](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041/20 "2024-02-21T07:21:26Z")

</div>

Tagging @balaji.ambresh

[Next page](https://community.deeplearning.ai/t/c2w1-unable-to-split-data/573041.md?page=2)
