text stringlengths 1 93.6k |
|---|
# Cropping and possible flipping
|
if (np.random.randint(2) > 0):
|
random_cropped[:,:,:] = padded[:,crops[0,0]:(crops[0,0]+self.img_size),crops[0,1]:(crops[0,1]+self.img_size)]
|
else:
|
random_cropped[:,:,:] = padded[:,crops[0,0]:(crops[0,0]+self.img_size),crops[0,1]:(crops[0,1]+self.img_size)][:,:,::-1]
|
image = torch.FloatTensor(random_cropped)
|
target = self.train_labels[index]
|
else:
|
image, target = self.test_data[index], self.test_labels[index]
|
image = torch.FloatTensor(image)
|
return index, image, target
|
def __len__(self):
|
if self.train:
|
return len(self.train_data)
|
else:
|
return len(self.test_data)
|
class cifar100(cifar10):
|
base_folder = 'cifar-100-python'
|
url = "http://www.cs.toronto.edu/~kriz/cifar-100-python.tar.gz"
|
filename = "cifar-100-python.tar.gz"
|
tgz_md5 = 'eb9058c3a382ffc7106e4002c42a8d85'
|
train_list = [
|
['train', '16019d7e3df5f24257cddd939b257f8d'],
|
]
|
test_list = [
|
['test', 'f0ef6b0ae62326f3e7ffdfab6717acfc'],
|
]
|
meta = {
|
'filename': 'meta',
|
'key': 'fine_label_names',
|
'md5': '7973b15100ade9c7d40fb424638fde48',
|
}
|
# <FILESEP>
|
from globals import pygame
|
class Animation:
|
"""
|
The animation class is very useful to handle sprite-animations.
|
It is recommended to create a class that inherits from this one and then
|
change the _custom()-method to add custom behaviour.
|
Most methods who aren't getters return self in order to perform actions like
|
animation.pause().reset().get_surface()
|
"""
|
def __init__(self, sprites, sprite_order):
|
"""
|
sprites: A list of images of the sprite, each image is a frame of the animation.
|
The images all have to have the same size.
|
See utilities.split_tiled_surface() for an easy way to generate such a list.
|
Sprites can't have an alpha-channel, transparent parts must be indicated by the
|
color (225, 0, 225)
|
sprite_order: Can be three of the following things:
|
Amount (int) of frames every sprite is showed. The order of the sprites played will be the order of the
|
sprites in the "sprites"-argument.
|
OR
|
The amount of frames for every sprites (list). The order of the sprites played will be the order of the
|
sprites in the "sprites"-argument, but this time, the amount of frames each sprite is showed can be changed
|
individually. ([frames_for_image_1, frames_for_image_2...])
|
OR
|
The order of the sprites and the amount of frames for every sprite (list of tuples). This list can contain
|
more elements than there are sprites. The syntax for this list is [(sprite_nr, frame_length),
|
(sprite_nr, frame_length)...].
|
An animation with three different sprites can be 5 sprites long,
|
playing sprite |: 1, 2, 1, 3, 2 :| for 100 frames per sprite for instance would be expressed as follows:
|
Animation([surface_1, surface_2, surface_3], [(1, 100), (2, 100), (1, 100), (3, 100), (1, 100)])
|
"""
|
# Save the sprites-list
|
self.sprites = sprites
|
# Save the speed and order of sprites according to the type of the given list:
|
self.sprite_order = sprite_order
|
self.format_sprite_order()
|
# Initialize the frame_counter
|
self.frame_counter = 0
|
# Initialize the var holding the index of the current sprite
|
self.current_sprite = 0
|
# Create the surface the current frame will be blitted on
|
self.surface = pygame.Surface(self.sprites[0].get_size())
|
# Set the colorkey (225, 0, 255)
|
self.surface.set_colorkey((255, 0, 255))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.