Machine learning certification project

Tell us what’s happening:

the test directory seems to have no images

Your code so far

    train_image_generator =tf.keras.preprocessing.image.ImageDataGenerator(rescale= 1. / 255)
validation_image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale= 1. / 255)
test_image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale= 1. / 255)

train_data_gen = train_image_generator.flow_from_directory(train_dir,batch_size=128,target_size=(150,150),class_mode= "binary")
val_data_gen = validation_image_generator.flow_from_directory(validation_dir,batch_size=128,target_size=(150,150),class_mode= "binary")
test_data_gen = test_image_generator.flow_from_directory('.',classes=['test'],batch_size=128,target_size=(150,150), shuffle= False)
![Screenshot from 2020-08-09 20-28-44|690x387, 100%](upload://97L2WLs6ROl11lK6JdriG8QC8Zr.png) )

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.

Challenge: Cat and Dog Image Classifier

Link to the challenge:

test_data_gen = test_image_generator.flow_from_directory(
        PATH,
        classes=['test'],
        target_size=(IMG_HEIGHT, IMG_WIDTH),
        batch_size=1,
        class_mode=None,
        shuffle=False)

Welcome, harshadkoli.

Adding to SupremeSadat’s solution: Remember to use the variables given:

PATH = os.path.join(os.path.dirname(path_to_zip), 'cats_and_dogs')

train_dir = os.path.join(PATH, 'train')
validation_dir = os.path.join(PATH, 'validation')
test_dir = os.path.join(PATH, 'test')

# Get number of files in each directory. The train and validation directories
# each have the subdirecories "dogs" and "cats".
total_train = sum([len(files) for r, d, files in os.walk(train_dir)])
total_val = sum([len(files) for r, d, files in os.walk(validation_dir)])
total_test = len(os.listdir(test_dir))

# Variables for pre-processing and training.
batch_size = 128
epochs = 15
IMG_HEIGHT = 150
IMG_WIDTH = 150

Also, when you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

hey guys, you were super helpful. Thank you so much for your help.

Please check my colab notebook and give me a green if I am good to go.

https://colab.research.google.com/drive/13x1kKK3YJdRb7_66IDAUbkBNCD547vsX?usp=sharing

also i was doing the rock, papers and scissors project, I was able to beat kris, mrugesh and quincy with above 60% win while I am not able to manage a win for more than 50.20% with abbey. Please suggest if there’s a better way to beat him.

Here is his code.


def abbey(prev_opponent_play,
          opponent_history=[],
          play_order=[{
              "RR": 0,
              "RP": 0,
              "RS": 0,
              "PR": 0,
              "PP": 0,
              "PS": 0,
              "SR": 0,
              "SP": 0,
              "SS": 0,
           
          }]):

    if not prev_opponent_play:
        prev_opponent_play = 'R'
    opponent_history.append(prev_opponent_play)

    last_two = "".join(opponent_history[-2:])
    if len(last_two) == 2:
        play_order[0][last_two] += 1

    potential_plays = [
        prev_opponent_play + "R",
        prev_opponent_play + "P",
        prev_opponent_play + "S",
    ]

    sub_order = {
        k: play_order[0][k]
        for k in potential_plays if k in play_order[0]
    }

    prediction = max(sub_order, key=sub_order.get)[-1:]

    ideal_response = {'P': 'S', 'R': 'P', 'S': 'R'}
    return ideal_response[prediction]

Use the same strategy as Abby, but look further into the past… :wink:

haha yes I did the same thing
‘’’
def me2(prev_opponent_play,
opponent_history=,
play_order=[{
“PPP”: 0,
“PPS”: 0,
“PPR”: 0,
“PSP”: 0,
“PSS”: 0,
“PSR”: 0,
“PRP”: 0,
“PRS”: 0,
“PRR”: 0,
“SPP”: 0,
“SPS”: 0,
“SPR”: 0,
“SSP”: 0,
“SSS”: 0,
“SSR”: 0,
“SRP”: 0,
“SRS”: 0,
“SRR”: 0,
“RPP”: 0,
“RPS”: 0,
“RPR”: 0,
“RSP”: 0,
“RSS”: 0,
“RSR”: 0,
“RRP”: 0,
“RRS”: 0,
“RRR”: 0,
}]):

if not prev_opponent_play:
    prev_opponent_play = 'P'
opponent_history.append(prev_opponent_play)

last_two = "".join(opponent_history[-1:])
if len(last_two) == 3:
    play_order[0][last_two] += 1

potential_plays = [
    "PS" + prev_opponent_play,
    "PR" + prev_opponent_play,
    "PP" + prev_opponent_play,
    "SS" + prev_opponent_play,
    "SR" + prev_opponent_play,
    "SP" + prev_opponent_play,
    "RS" + prev_opponent_play,
    "RR" + prev_opponent_play,
    "RP" + prev_opponent_play,
]

sub_order = {
    k: play_order[0][k]
    for k in potential_plays if k in play_order[0]
}

prediction = max(sub_order, key=sub_order.get)[-1:]

ideal_response = {'P': 'S', 'R': 'P', 'S': 'R'}
return ideal_response[prediction]

‘’’

but still its not working . I am only able to win by 50.15%

Trust me, it works, but you need to go back even further :wink: I actually made a version, that lets you pass as a parameter how many steps to look back, so I was able to choose the optimum :slight_smile:

is there a function to apply combinations for various inputs and then we can pass r,p,s and steps to look back as parameters to get the o/p. As if I’ll go four steps back(manually), I’ll have to write 3 raised combinations 4 combinations(81) combinations.
I am a beginner so I may not be able to do what you did.

You can use a set of nested for loops to fill up an empty dictionary:

rps = 'RPS'
dict_4step = {}

for letter1 in rps:
    for letter2 in rps:
        for letter3 in rps:
            for letter4 in rps:
                dict_4step.update({letter1+letter2+letter3+letter4: 0})

This will give you

dict_4step = {'RRRR': 0, 'RRRP': 0, 'RRRS': 0, 'RRPR': 0,...}

Now, when a given key appears in your opponent’s sequence, you can increase the corresponding value in the dictionary by 1.